my problem is a bit complicate to explain but I am gonna do my best ( it's gonna be long) . I am trying to develop a python program to count vehicules in a traffic. For that I have a canvas on which I can draw lines to define the entry and exit of a road ( so the program counts every vehicules crossing the lines). At first it was counting from uploaded videos and it worked well on Windows but I had to use it with Jetson Nano and a webcam to have a live streaming video. s
So I installed everything it needed to run and here's what happened:
I have both python2.7 and python3.7 in my Jetson. But the program was built with python3.7. I tried using gstreamer to open my CSI Camera but it didn't work.
I decided to see if my opencv was compatible with Gstreamer and i saw "GStreamer: no" and" Python(for build): bin/python2.7
After running a script( that should open the camera) with python2.7, the camera worked well, so I decided to make my program work with python2.7. And INDEED the program could open the camera BUT there were no canvas anymore, so I couldn't draw the lines .
I tried installing a virtual environment ( archiconda ) , nothing works, the cv2 in my conda env is still not working with Gstreamer. I thought about building it with Cmake but there's no CMakeList.txt in the cv2 folder in my archiconda folder.
Now when I run my script (which shows my openCV build info ) with python2.7 , it shows GStreamer:Yes and Python(for build): home/archiconda/bin/python3 . But when i run it with python3.7 I get GStreamer:No and Python(for build): bin/python2.7
I must admit am so lost i don't understand what's happening.
So my main problem is : How can I make my OpenCV work with GStreamer and Python3.7 on my Jetson Nano
Versions:
OpenCV 4.5.4
Python 3.7
GStreamer 1.14.5
Thank you if you had the patience to read me.
Related
I am running the latest version of Raspbian on the Raspberry Pi with Python 2.7 and 3.7 installed. For a project, I need to implement some spatial/binaural audio file playback capabilities in Python, and Pyglet (version 1.5.6) (https://pypi.org/project/pyglet/, https://github.com/pyglet/pyglet) seems to be the simplest option with least dependencies. However, I am not being able to hear audio output through the headphones. Here's what I did:
Installed pyglet dependencies: sudo apt-get install ffmpeg libopenal1 libopenal-dev python3-pil.imagetk python3-pil python3-matplotlib python3-scipy gstreamer1.0-alsa gstreamer1.0-python3-plugin-loader (From previous programs, the system also had cmake, python3-opencv libopencv-dev libusb-1.0-0-dev, libboost-program-options-dev and python3-numpy installed)
I then installed pyglet as per given in the guide: sudo pip3 install --upgrade pyglet. The installation proceeded without any errors.
I know that by default often, Raspberry Pi spits audio out through the HDMI port instead of A/V port. So I went to raspi-config using sudo raspi-config, went to Advanced Options -> Audio. Selected the proper option (in my case 1 Headphones). I checked if audio was playing fine through my headphones by playing couple of youtube videos and audio files on the Raspberry Pi itself.
I then checked if pyglet was working by importing pyglet with import pyglet in a python shell, it worked fine without any warnings or errors.
I launched the example program provided here: https://github.com/pyglet/pyglet/tree/master/examples/soundspace. To do so, I downloaded the repo https://github.com/pyglet/pyglet and moved to the proper directory (via cd command) and wrote: sudo python3 soundspace.py. For a brief overview, the program contains 4 instruments that can be dragged across the room with a mouse. In doing so, the audio that you hear from each instrument changes depending on position and orientation of those instruments as well as your virtual position inside the mini game. The program executes without any error being shown in the terminal, but I don't hear any sound. When I try to move the objects, the program freezes but no error is shown in the terminal.
Since I was least bothered about the complex program, I went ahead to create my own simple program that will play a wav file (sourced from the Pyglet's developer repo itself before anyone says the wav file is incompatible https://github.com/pyglet/pyglet/tree/master/examples/soundspace), reference from: https://pyglet.readthedocs.io/en/latest/programming_guide/media.html . Here's the code snippet:
import pyglet
pyglet.options['search_local_libs'] = True
pyglet.options['audio'] = ('openal')
source = pyglet.media.load('Bass.wav', streaming=False)
source.play()
According to the documentation, if I am not wrong, this is supposed to play the wav file being fed to the source. The program seems to run without any errors shown in the terminal. But I do not hear any audio output from the program.
I also messed around a bit with pyglet.media.Player() but same observation persits: no error in terminal but no audio as well.
Any suggestions on how to fix the issue? Note that I would prefer to use Pyglet as this is the only spatial/binaural/positional audio Python package that has managed to work almost well without breaking my OS, so it would be best if alternative suggestions be a bit inline with this package and not entirely something different.
https://github.com/NicklasTegner/PyAL Since I was out of time. I tried experimenting with other OpenAL Python libraries and this one works fine.
Edit: The actual problem was not with Pyglet but with PulseAudio, which clashes with ALSA. I solved the problem by connecting an external USB audio card and audio was working properly (with HRTFs and all).
i try to identify the forehead in my cropped image to identify the thermal image, Here are things i did
found a python code which uses "dlib" library
Dlib works only if i have cmake and cmake works only if i have visual studio
for installing dlib 19.19.0 and cmake 3.17.3 (They are obsolete compared with my python 3.8.2 ) i found errors during installation in
my windows 10 . error "c compiler identification unknown" (during dlib
installation) even though i had added cmake path to my env variable
i also tried pip install for dlib(not installed) and cmake (installed)
So are there any alternative solutions to fetch my " forehead only " python task ?
You can try anaconda to install python dlib. Then use face detection and eyebrow landmarks to crop forehead.
If you want to skip dlib then look into opencv facemark api but its in C++. In my last test with opencv 4.2.0 facemark LBF trained model was better then Kazemi for opencv. Further detail on LBF implementation,
https://gist.github.com/kurnianggoro/74de9121e122ad0bd825176751d47ecc
There is a python bindings repo for opencv facemark,
https://github.com/saiteja-talluri/GSoC-OpenCV
You can also look into python https://github.com/1adrianb/face-alignment, as it shows dlib was removed as requirement in commit log.
I am using a chromebook with linux beta turned on to use a terminal to run python3 scripts. they worked fine until recently when any pop out window (pygame, pyplot) look corrupted. the windows have black bars covering them for pyplot or are completely covered in black for pygame. the code in the python scripts are unchanged and worked just fine a couple of weeks ago.
I have already turned off linux beta, then returned it back on, reinstalling packages which didn't alleviate the issue. Any help is IMMENSELY appreciated!!
I installed Qt5 bindings via pip install PyQt5 and changed the backend to Qt5Agg per How to change backends in matplotlib / Python and that fixed the black bars for me.
I'm having an error running simple code using cv2 module.
It's just:
import cv2
img = cv2.imread('sudoku.png',0)
cv2.imshow('image',img)
And it fails with the following error:
QObject::moveToThread: Current thread (0x1b74720) is not the object's thread (0x1e57d70).
Cannot move to target thread (0x1b74720)
I googled this error and tried a lot of things but it doesn't help. I tried installing without pip, I tried using step-by-step installation (from official OpenCV) but nothing helps.
When I run:
cv2.__version__
It returns 3.4.3
As noted already, the basis for this problem is discussed in opencv-python issue 46, and results from the duplication of the following libraries both on the host and the opencv-python distro libQtDBus libQtCore and libQtGui.
It has been lately addressed in the newest release of opencv-python. It is not a fix to the source code, rather the fix is to force pip to compile the newly available source via
pip install --no-binary opencv-python opencv-python
This will cause opencv-python to use the same libraries as the host, so the conflict no longer exists.
According to this issue posted on the OpenCV GitHub, this is a known issue that the developer states is damn near impossible to fix. It is apparently caused by a conflict in any Qt installations on the system with the Qt that is shipped with OpenCV. There are some suggestions floating around to remove the libqt5x11extras5 package from the system. This may fix it for some but anyone running these libraries on a Linux distribution that uses a window manager based on Qt will render their desktop environment unusable by removing this package (having tried it myself).
You can try building OpenCV from source using the WITH_GTK=ON option when running cmake which will use GTK instead of Qt, circumventing the conflict. However, this is hard to make use of in Python when using virtual environments.
I haven't spent the time to fully appreciate this problem, but as I understand this is caused by multiple conflicting versions of some plugin in the environment. I tried installing building opencv-python but there were errors with that approach. Another suggestion is to change your import order, but I've had mixed success with that, and I couldn't get it to work on a project today.
But I found a workaround that worked for me. Install opencv-python-headless instead of opencv-python. This will avoid installing the conflicting plugins. It may not work for you depending on what features of opencv you need.
$ pip uninstall opencv-python
$ pip install opencv-python-headless
The error was fixed on my system, by simply updating one library.
To find out where it is coming from, assuming Linux, try the following,
LD_DEBUG=files python -c "import cv2"
or,
LD_DEBUG=files python -c "import cv2 ; img = cv2.imread('myimage.png',0) ; cv2.imshow('image',img) ; cv2.waitKey(0)"
On my machine, it failed in one of the blas libraries. I updated that library and the code now runs without error.
This is an old bug you can find it discussed in a number of online communities.
My test code is as follows. Notably the error has not reoccurred, and apparently has nothing to do with Qt.
import cv2
img = cv2.imread('sudoku.png',0)
cv2.imshow('image',img)
cv2.waitKey(0)
To me, the solution to this problem was removing Anaconda, then installing pip followed by installing OpenCV with a simple pip install command.
I'm having trouble instantiating and opening an OpenCV VideoWriter for recording video on a Raspberry Pi (Raspbian Weezy).
My project is written in C++, but I've written a minimal Python program that demonstrates the problem.
https://gist.github.com/chriscollins/11ff2f43852e1c93dae8
Both my C++ code and the Python code above run without problem on my Windows machine. Sometimes the writer does not open, but that's to be expected - I don't have all of the listed codecs installed (the list of codecs comes from the Open CV source), but a good number of them work correctly. However, on a Raspberry Pi, both the C++ code and the Python code fail with the VideoWriter never being opened. In the above Python code, writer.isOpened() returns false for every single codec, when run on a Raspberry Pi.
I've chowned the destination directory to the user I'm running the Python script as, and chmodded it to 777 so I don't believe that it is a permissions problem. I think it may be connected with how I've installed OpenCV or some of its dependencies, but I'm not sure how to rectify it.
The install process I've used is as follows:
Update firmware/packages via rpi-update, apt-get update and apt-get upgrade.
Install the following dependencies via apt-get:
libjpeg8
libjpeg8-dev
libjpeg8-dbg
libjpeg-progs
ffmpeg
libavcodec-dev
libavcodec53
libavformat53
libavformat-dev
libgstreamer0.10-0-dbg
libgstreamer0.10-0
libgstreamer0.10-dev
libxine1-ffmpeg
libxine-dev
libxine1-bin
libunicap2
libunicap2-dev
swig
libv4l-0
libv4l-dev
python-numpy
libpython2.6
python-dev
python2.6-dev
libgtk2.0-dev
Download and unzip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip to /root/opencv-2.4.9.
cd /root/opencv-2.4.9 and run cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_PERF_TESTS=OFF -DBUILD_opencv_gpu=OFF -DBUILD_opencv_ocl=OFF. Output of cmake is available at https://gist.github.com/chriscollins/d8060e03a6acd6d4336c
make and make install from the same directory.
Various other OpenCV functionality works correctly on the Raspberry Pi (in C++ or in Python) - e.g. viewing a webcam via VideoCapture, but I can't get the VideoWriter to work. I'm tempted to try installing FFMPEG from source instead of via apt-get, but as make takes 5+ hours to run on a Raspberry Pi, I was hoping I'd find the answer here, rather than proceeding with a trial and error approach!
Any advice on how to solve (or debug) this is appreciated.
EDIT: Added output of cmake command (https://gist.github.com/chriscollins/d8060e03a6acd6d4336c)
Looking at the output of make, I've found that it says NO to installation of gstreamer, which is a must for multimedia handling. This is the missing link.
Try
sudo apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev .
This should solve your problem.
I've had similar issue on Mac OS 10.9 (Mavericks). I've solved it be reinstalling Opencv with ffmpeg support (i'm not sure whether i've reinstalled it after manually installing ffmpeg or whether brew handled it). On mac installing OpenCV with ffmpeg support was just one command - brew install opencv --with-ffmpeg (description of this option -> "Build with ffmpeg support"). I'm sure apt-get should have similar option.
You may also try this solution - http://www.ozbotz.org/opencv-installation-2-3-1/ It's quite old, but after small changes should work with current OpenCV version.