1

I'm trying to run a program that has been running before. After a while I switched the OS and came back to Ubuntu 14.10 (before it was 14.04). I'm not quite shure if the problem is within openCV or more of a basic thing. I can't find the problem. Maybe someone of you has an idea.

import cv2

cap = cv2.VideoCapture(0)

while(True):
    # Capture frame-by-frame
    ret, frame = cap.read()

# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

It is running to the point that i can see a video capture. But typing "q" to quit the program. The window that was opened freez, is turning black after a while and nothing else happens. Then I'l have to close the window and force it to exit. Any idea what the problem is and how to solve?

Siddharth Thevaril
  • 3,722
  • 3
  • 35
  • 71
TheEnclave
  • 25
  • 5
  • I think you should check all your python environment first. Maybe some dependencies have been changed – Neo Ko Jul 08 '15 at 11:01
  • Did you try ti figure out on which line application stops? You can add some prints before `cap.release` and `cv2.destroyAllWindows`. It should helps to localize problem. – Jimilian Jul 08 '15 at 11:14
  • Installed ubuntu 14.04 and everything else (hopefully correct). Same problem. Tried what Jimilian said. Created some outputs before, inbetween and after cap.release and destroyAllWindow. All is printed and the window is not destoryed. – TheEnclave Jul 09 '15 at 11:56

2 Answers2

0

Some buffers are perhaps used for drawing and so releasing their memory is a bad idea.

So could you try to call destroyAllWindows, before calling cap.release ?

Alexandre Mazel
  • 2,462
  • 20
  • 26
0

Okay, found a workaround here on stackoverflow. Don't know why I didn't found it earlier. Well it seems to be a problem within Linux.

DestroyWindow does not close window on Mac using Python and OpenCV

after

cv2.destroyAllWindow()

add

for i in range (1,5):
    cv2.waitKey(1)

Don't ask me why but it works. If someone has an answere to this. Please let me know ;o) Thanks to all who tried to help.

Community
  • 1
  • 1
TheEnclave
  • 25
  • 5