PyImageSearch / imutils

A series of convenience functions to make basic image processing operations such as translation, rotation, resizing, skeletonization, and displaying Matplotlib images easier with OpenCV and Python.
MIT License
4.53k stars 1.02k forks source link

Count Frames Function #261

Open kbvatral opened 2 years ago

kbvatral commented 2 years ago

The count frames function currently will resort to using manual counting instead of the cv2.CAP_PROP_FRAME_COUNT property if you use version 4+ of OpenCV. From imutils/video/count_frames.py:

try:
    # check if we are using OpenCV 3
    if is_cv3():
        total = int(video.get(cv2.CAP_PROP_FRAME_COUNT))

    # otherwise, we are using OpenCV 2.4
    else:
        total = int(video.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))

I believe that if OpenCV 4 using the same property as OpenCV 3, so this should be as simple as changing the if statement to check if cv3 or cv4. Is there already a convenience function for checking version 4 that could be used here?