简体   繁体   中英

pyOpenCv not working on raspberry pi

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.

Build OpenCV from scratch gives your more control over the choice of modules like CUDA version or which BLAS library to use.

It could be quite troublesome and slow to build OpenCV on a Raspberry Pi, I believe. Therefore I would suggest trying pre-built packages through channels like sudo apt-get install python-opencv or pip . You can test them pretty quickly and they are easy to be removed even if they don't work.

If you really wanted to build from scratch, the site that you have mentioned should work. If you don't want virtual environment, just skip all the steps that involves virtual environment. Installation commands that work inside a virtual environment should work outside it too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM