pyOpenCv not working on raspberry pi - python

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.

Related

install opencv from source windows

I am trying to install OpenCV following this link https://docs.opencv.org/master/d5/de5/tutorial_py_setup_in_windows.html
opencv-4.5.1 is the version I am building from source. I have no errors in my entire process( up to Step 16)
Step 17 which INSTALL also has no errors, but Step 18 'import cv2 as cv' will not import this module.
I have python 3.9.1. I followed all the steps with CMAKE and was able to generate with no errors.
Is there something that I am missing here?
I would recommend to use another IDE like Pycharm to create your projects. It is extremely easy to setup an OpenCV work environment :).
IDLE is great for smaller projects but I`ve seen a lot of people having issues with it.

Re-installing OpenCV on Jetson Nano

I am currently working on a Nvidia Jetson Nano. When I installed JetPack 4.4, OpenCV 4.1.1 was included inside and when I was running on my Nano's Python shell, I was able to at least run import cv2 and a few other functions without errors. However, when I was running one of my scripts, I kept encountering this certain error and I thought it was an issue with my OpenCV. This is because the tutorial that I was following, they mentioned that if ran cv2.getBuildInformation() it should include details of CUDA. At the time, my output did not contain CUDA so I thought something was wrong.
Then, I've decided to reinstall OpenCV not thinking too much about it by following several tutorials, mainly the one by blogger Piggybank here. I did not uninstall anything as I thought that it would just simply overwrite it. However, the installation did not go through because it mentioned that my disk was running low on memory. I though that the entire operation would be aborted but apparently not. When I try to run import cv2 it gives me:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'
I tried to 'completely uninstall' OpenCV via pip and apt-get after but the commands returned saying that OpenCV does not exist. Not too sure what went wrong here and I don't understand I was able to run OpenCV smoothly before but now, I don't have enough memory for it. When I try to reinstall with the blog link above, it only reaches to about 50% of the entire installation process. Please help.

Python 2.7.14--- importing vlc module on mac OS

in the last couple of days I was developing an APP on python IDLE.
I tried to import the vlc module, when I run it I get this error:
OSError: dlopen(libvlccore.dylib, 6): image not found
I installed the module with this command: pip install python-vlc.
I hope you can help me getting it work!
Thanks in advance!
Zaid Zaim
python-vlc is just Python bindings for libVLC.
Without that library, it won't do you any good, because all it does is try to load that library (a .dylib, .so, or .dll, depending on your platform) and call functions out of it.
There should be installation instructions at the wiki page linked above, but on a Mac, the easiest way is to just install the VLC player. I know that if you install it with Homebrew, you get the library, in a location that python-vlc can find. But I think even the binary installer from the front page of the main VideoLAN website will work as well.
If you're using Homebrew, you'll want to read the docs for when to search brew vs. brew cask vs. other taps,1 or search somewhere like Mac App Store for the current status. But at present, the appropriate command appears to be:
brew cask install vlc
1. Generally, anything that you'd expect to find as a double-clickable app in /Applications, as opposed to a Unix command-line tool or a support library, is going to be a cask, and therefore in the tap cask, which has special shortcuts to access it. But that's a relatively new thing, and not every recipe has been converted yet.
brew install --cask vlc
Is the latest command, and it works for me!

How do I install OpenCV 3 on Centos 6.8?

I'm working on a CentOS cluster right now and have Python2.7 installed. I've managed to get OpenCV 2.4 installed (using these helpful instructions) but it does not have all of the functionality of 3 (I need the connectedComponents function and a couple others not available). Omitting the "checkout tags" step results in errors during "cmake". Something else to note is when I attempt to install the ffmpeg package it tells me no such package is available. Error:
CMake Error at 3rdparty/ippicv/downloader.cmake:77 (message):
ICV: Failed to download ICV package: ippicv_linux_20151201.tgz.
Status=6;"Couldn't resolve host name"
Call Stack (most recent call first):
3rdparty/ippicv/downloader.cmake:110 (_icv_downloader)
cmake/OpenCVFindIPP.cmake:237 (include)
...
I've managed to get OpenCV 2.4 installed (using these helpful instructions) but it does not have all of the functionality of 3 (I need the connectedComponents function and a couple others not available).
Why don't you just download OpenCV 3 then?
Something else to note is when I attempt to install the ffmpeg package it tells me no such package is available.
You can download the file yourself from here (the package that is not available for you).
Then place it in the folder where it initially would have been downloaded to:
<your opencv build>/3rdparty/ippicv/
It seems like OpenCV 3 would be better suited for what you are doing, you even said yourself that you are needing features that aren't available in 2.7.
The OpenCV 3.0 documentation actually has a full guide on installing the latest version of the library using the Yum feature in your terminal. It walks you through every step and explains them all in detail, including the Cmake steps which seem to be giving you trouble. I would recommend taking a look at the guide which is linked here.

extract single frame from video

I am trying to write a script that will extract a single frame from a user uploaded video clip in order to create a thumbnail. It sounds like either OpenCV or ffmpeg will do what I need, but I am having trouble installing them.
I tried installing OpenCV using apt-get install libopencv-dev, and it looks like everything worked, but when running import cv2 in Python, it says there is no such module. Also tried installing using these instructions, but when I run the import, it hangs for a second or two and then says Failed to initialize libdc1394.
I then tried to install ffmpeg with pyffmpeg, but the most recent version of pyffmpeg I could find was released 3 years ago and built for Python2.6 on Ubuntu 10.10, while I am using 2.7 on Ubuntu 12.04.
Does anyone have experience installing either of these, or would recommend something else for this purpose?
If you are trying to install ffmpeg, you can do this more easily if you have homebrew and then use brew to install it. It's a lot more complicated otherwise.
If you just want to be able to complete this task, and it doesn't have to be the tool you're listing, you could try ffmpeg-python. After you have it installed, you can use the get_video_thumbnail example to get a single image. You could also probably tweak the read_frame_as_jpeg example to get a single image from a frame if you want.

Categories

Resources