0

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

I just want something that works, thanks. Do I need to try to delete the previous installation, or can I just count on apt to fix things?
Looking at your link, I would suggest dpkg --remove packagename. If you don't know the package name, try dpkg -l | grep opencv. I see that a link was created, so maybe do rm /usr/local/lib/python3.5/dist-packages/cv2.so too.
I'll give it a whirl. Thanks for your advice.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.