You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

webcam_demo.py 1.3 kB

2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import argparse
  3. import cv2
  4. import torch
  5. from mmdet.apis import inference_detector, init_detector
  6. def parse_args():
  7. parser = argparse.ArgumentParser(description='MMDetection webcam demo')
  8. parser.add_argument('config', help='test config file path')
  9. parser.add_argument('checkpoint', help='checkpoint file')
  10. parser.add_argument(
  11. '--device', type=str, default='cuda:0', help='CPU/CUDA device option')
  12. parser.add_argument(
  13. '--camera-id', type=int, default=0, help='camera device id')
  14. parser.add_argument(
  15. '--score-thr', type=float, default=0.5, help='bbox score threshold')
  16. args = parser.parse_args()
  17. return args
  18. def main():
  19. args = parse_args()
  20. device = torch.device(args.device)
  21. model = init_detector(args.config, args.checkpoint, device=device)
  22. camera = cv2.VideoCapture(args.camera_id)
  23. print('Press "Esc", "q" or "Q" to exit.')
  24. while True:
  25. ret_val, img = camera.read()
  26. result = inference_detector(model, img)
  27. ch = cv2.waitKey(1)
  28. if ch == 27 or ch == ord('q') or ch == ord('Q'):
  29. break
  30. model.show_result(
  31. img, result, score_thr=args.score_thr, wait_time=1, show=True)
  32. if __name__ == '__main__':
  33. main()

No Description

Contributors (3)