VideoCapture

class video.VideoCapture(cam_index=0, queue_size=128)[source]

Bases: object

OpenCV VideoCapture wrap in detached thread.

Parameters
  • cam_index (integer or str) – Filename or cam index

  • queue_size (int) – Integer of maximum number of frame to store into the queue

Example

>>> cap = VideoCapture()
>>> time.sleep(.1)
>>>
>>> cv2.namedWindow('Camera', cv2.WINDOW_NORMAL)
>>>
>>> cap.start()
>>>
>>> while cap.running():
>>>
>>>   frame = cap.read()
>>>   frame.show('Camera', ms=1)
>>>   print('FPS: {:.3f}'.format(cap.fps))
>>>
>>> cap.stop()
>>>
>>> cv2.destroyAllWindows()

Notes

The object is inspired to the ImUtils implementation.

References

property elapsed

Get the elapsed time from start to up to now

Returns

elapsed – Elapsed time

Return type

float

property fps

Get the frame per seconds

Returns

fps – Frame per seconds

Return type

float

read()[source]

Get a frame as Image object

Returns

im – The loaded image

Return type

Image obj

running()[source]

Check if new frames are available

Returns

running – True if there are data into the queue, False otherwise

Return type

bool

start()[source]

Start the video capture in thread

stop()[source]

Stop the thread