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.
Related
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.
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 want to run QT-Creator on my Odroid XU3 (ARM Architecture with Lubuntu 14.4) and build an application with it. I've read a lot of on the internet to figure out how to do this but haven't been successful yet. I tried to follow these instructions https://wiki.qt.io/ODROID-XU3 but didn't understand few things.
It states that I need to install some dependencies. I followed the given hyperlink on this site and installed the dependencies using following commands:
sudo apt-get build-dep qt5-default
sudo apt-get install "^libxcb.*" libx11-xcb-dev libglu1-mesa-dev
libxrender-dev libxi-dev
When I searched for my qt5 folder, I could only find qt4 in user/share. What did I do wrong?
It states that I have to setup a toolchain and a sysroot. Do I have to do this only if I want to cross-compile, so compile on a different machine for my Odroid XU3, or also if I just want to compile on Odroid itself?
Let's say I want to setup the toolchain. According to this site I should copy the raspberry pi toolchain (or a different one) into the folder ~/Code/Odroid/toolchain. Problem is I don't see such a folder in my home directory on my Odroid. Should I mkdir one?
Let's also say I want to setup the sysroot, I don't get the part "One is to mount the ODROID-XU3's SD Card or eMMC on your development machine and either make a copy or a link to ~/Code/Odroid/sysroot". Am I right in assuming that I should copy the content of my SD-card to this folder on my developing machine?
Where should I build my QT now - on my development machine or Odroid? (sorry for that stupid question)
What If I want to make it simple and build everything on Adroid XU3 assuming that I have plenty of time and resources. I tried to first install qt and qt creator afterwards but as I started qtcreator, there was no compiler preconfigured and also the QuickView was missing. The terminal was also mentioning that the toolchain is missing. I struggled a lot in order to add these missing components but failed.
Thanks in advance!
to your second point: you can compile it on the Odroid or on your PC. But you should take a look at this: https://wiki.qt.io/Category:QtonPi it should be pretty the same on the Odroid.
I need to run a program which use VTK5 on my Archlinux PC, but I found it really hard to install VTK5, there is only VTK6(not compatible with VTK5) in official repo, and when I try to install it from AUR, it returns "Makepg was unable to build vtk5", then I try to install through source code, the result is that I was unable to install the VTK Python module...
Is there anybody who has any experience or idea about it?
I have not installed on Archlinux specifically, but on different linux machines. If you compile from source and are interested in python, remember to select the option python wrapping when running cmake. Btw, once built, you will have to update both the pythonpath and the ldlibrarypath.
You can also have a try at enthought canopy, which distributes a complete installation with numpy, scipy, vtk http://docs.enthought.com/canopy/quick-start/install_linux.html
I 'm trying to run some precompiled code (source code is not available) on Ubuntu, which requires openCV to be installed. I installed the latest version of openCV (from the SVN) yesterday, and installed it according to the debian install guide on the openCV website (cmake -> make -> sudo make install) and everything seemed to go fine.
I tried to run stipdet program but this gives me following error.
bash: ./stipdet: cannot execute binary file
Please can anyone help me with this error?
What does:
file $(which stipdet)
...say? I'm guessing it was built for a CPU you don't have.
You need to run chmod 755 ./stipdet to make stipdet executable.