I installed pyOpenCV on my raspberry pi using the pre-built binary from here. It doesn't seem to work at all. I wrote this little script to test:
import cv2
webcam = cv2.VideoCapture(0)
if not webcam.isOpened():
print('VideoCapture failed')
exit()
while True:
frame = webcam.read()[1]
cv2.imshow("Test", frame)
key = cv2.waitKey(1) & 0xFF
if key == ord("q"):
break
webcam.stop()
cv2.destroyAllWindows()
and it crashes with the message
OpenCV Error: Unspecified error (The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script) in cvShowImage, file /home/yyoo/src/opencv-3.3.0/modules/highgui/src/window.cpp, line 605 Traceback (most recent call last): File "test.py", line 10, in cv2.imshow("Test", frame) cv2.error: /home/yyoo/src/opencv-3.3.0/modules/highgui/src/window.cpp:605: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvShowImage
Since I didn't build the code from source in the first place, I have no idea what to do. I think I should just start over, building from source. I have two questions related to this. First, do I need to delete anything before undertaking this, and if so, what? Second, where is a good place to get instructions? I'm running stretch, and python 3.5, and I'm planning on using a USB webcam. I tried following the instructions at pyImageSearch but it uses a virtual environment, and that didn't work for me for some reason. I'm planning on using the pi for one app only, so the virtual environment isn't important to me, and I'd just as soon skip it.
On this site it seems to say that all I have to do is to type
sudo apt-get install python-opencv
which makes me wonder why other sites talk about downloading openCV source and running make. I'm really confused and would be grateful for advice.