Ask Your Question
0

Assertion Failed Opencv Python unlock

asked 2017-11-09 10:37:42 -0600

updated 2017-11-09 11:02:49 -0600

I am trying to run opencv-python==3.3.0.10 on a macOS 10.12.6 to read from a file and show the video in a window. I have exactly copied the code from here http://opencv-python-tutroals.readthe..., section 'Playing' video from file.

The code runs correctly and shows the video, however after termination of the video it breaks the program, giving the following error:

Assertion failed: (ec == 0), function unlock, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/libcxx/libcxx-307.5/src/mutex.cpp, line 48.

Does anyone have any idea of what might have cause


Code snippet for your convenience

cap = cv2.VideoCapture('vtest.avi')

while(cap.isOpened()):
    ret, frame = cap.read()
    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-11-09 21:06:18 -0600

supra56 gravatar image

The vtest.avi is not available on doc. You have to add your filename such as avi, mp4, etc.

edit flag offensive delete link more
0

answered 2017-11-09 10:51:21 -0600

berak gravatar image

updated 2017-11-09 10:53:05 -0600

there's a difference between webcams and movie files - webcams have an endless stream, while with files you eventually reach the end of it. please make it a HABIT to check return values, and for empty frames, whenever you read images from videos, disk, etc..

cap = cv2.VideoCapture('vtest.avi')

while(cap.isOpened()):
    ret, frame = cap.read()
    if not ret: break # movie's over !

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    cv2.imshow('frame',gray)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

ps: please do not use the outdated tutroals, opencv's python tutorials are here

edit flag offensive delete link more

Comments

Thank you for your answer, but it did not solve the issue. Putting the if statement does break the loop but it crashes right after (anything after the loop is not executed) . I also trying commenting out cap.release()...

Same error.

Campello gravatar imageCampello ( 2017-11-09 10:58:57 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-11-09 10:37:42 -0600

Seen: 3,877 times

Last updated: Nov 09 '17