• Benvenuti su RaspberryItaly!
Benvenuto ospite! Login Login con Facebook Registrati Login with Facebook


Valutazione discussione:
  • 0 voto(i) - 0 media
  • 1
  • 2
  • 3
  • 4
  • 5

[-]
Tags
con opencv problema

Problema con openCV
#1
Ciao, 
per il mio progetto di robotica ho caricato openCV versione 3.2.0.
Dopo aver seguito tutta la procedura tramite tutorial ho constatato con soddisfazione che lanciando facedetect.py,, raspberry rilevava il mio viso ed i miei occhi tramite picamera.
E fin qui tutto ok.
Allora ho cercato di andare avanti per il quello che mi ero prefissato di fare, ovvero effettuare il face tracker tramite pan/tilt.
Per fare questo ho seguito la seguente procedura: https://learn.pimoroni.com/tutorial/elec...ce-tracker
Purtroppo però, arrivato alla 'resa dei conti', lancando il sample 'facetracker_haar.py', viene rilevato il seguente errore:
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pi/PanTiltFacetracker/facetracker_haar.py", line 7, in <module>
    import cv2.cv as cv
ImportError: No module named 'cv2.cv'; 'cv2' is not a package

Non solo, se ora provo a rilanciare facedetect.py che prima funzionava, non rileva più la picamera anche se l'ho abilitata usando raspi config, dandomi il seguente messaggio:

Warning: unable to open video source:  0

Ho gia effettuato degli update, ma niente....eppure utilizzando raspivid -d, la picamera funziona.


Mi potete aiutare?
Risposta
#2
Dev'essere un problema di virtualenv. Che tutorial hai seguito per l'installazione di opencv?
Il mio software non ha mai bugs. Include soltanto funzionalità casuali.


Risposta
#3
Il tutorial è questo: http://www.pyimagesearch.com/2015/07/27/...erry-pi-2/

Tra l'altro ho provato a rifare i seguenti passaggi:

Section 2: Compiling OpenCV 3.0 with Python 2.7+ support

Install the Python 2.7 header files so we can compile the OpenCV 3.0 bindings:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ sudo apt-get install python2.7-dev
1

$ sudo apt-get install python2.7-dev

Timings: 1m 20s

Install pip , a Python package manager that is compatible with Python 2.7:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py
1
2

$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python get-pip.py

Timings: 33s

Just as we did in the original tutorial on installing OpenCV 2.4.X on your Raspberry Pi, we are going to utilize virtualenv and virtualenvwrapper which allow us to create separate Python environments for each of our Python projects. Installing virtualenv and virtualenvwrapper is certainly not a requirement when installing OpenCV and Python bindings; however, it’s a standard Python development practice, one that I highly recommend, and the rest of this tutorial will assume you are using them!

Installing virtualenv and virtualenvwrapper is as simple as using the pip command:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/.cache/pip
1
2

$ sudo pip install virtualenv virtualenvwrapper
$ sudo rm -rf ~/.cache/pip

Timings: 17s

Next up, we need to update our ~/.profile file by opening it up in your favorite editor and adding the following lines to the bottom of the file.
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
# virtualenv and virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
1
2
3
4

# virtualenv and virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python2.7
export WORKON_HOME=$HOME/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh

And if your ~/.profile file does not exist, create it.

Now that your ~/.profile file has been updated, you need to reload it so the changes take affect. To force a reload of the . profile , you can: logout and log back in; close your terminal and open up a new one; or the most simple solution is to use the source command:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ source ~/.profile
1

$ source ~/.profile

Time to create the cv3 virtual environment where we’ll do our computer vision work:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ mkvirtualenv cv3
1

$ mkvirtualenv cv3

Timings: 19s

If you ever need to access the cv3 virtual environment (such as after you logout or reboot your Pi), just source your ~/.profile file (to ensure it has been loaded) and use the workon command:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ workon cv3
1

$ workon cv3

And your shell will be updated to only use packages in the cv3 virtual environment.

Moving on, the only Python dependency we need is NumPy, so ensure that you are in the cv3 virtual environment and install NumPy:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ pip install numpy
1

$ pip install numpy

Timings 13m 47s

While unlikely, I have seen instances where the .cache directory gives a “Permission denied” error since we used the sudo command to install pip . If that happens to you, just remove the .cache/pip directory and re-install NumPy:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ sudo rm -rf ~/.cache/pip/
$ pip install numpy
1
2

$ sudo rm -rf ~/.cache/pip/
$ pip install numpy

Awesome, we’re making progress! You should now have NumPy installed on your Raspberry Pi in the cv3 virtual environment, as shown below:
Figure 1: NumPy has been successfully installed into our virtual environment for Python 2.7+.

Figure 1: NumPy has been successfully installed into our virtual environment for Python 2.7+.

Note: Performing all these steps can be time consuming, so it’s perfectly normal to logout/reboot and come back later to finish the install. However, if you have logged out or rebooted your Pi then you will need to drop back into your cv3 virtual environment prior to moving on with this guide. If you do not, OpenCV 3.0 will not compile and install correctly and you’ll likely run into import errors.

So I’ll say this again, before you run any other command, you’ll want to ensure that you are in the cv3 virtual environment:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ workon cv3
1

$ workon cv3

And once you are in cv3 virtual environment, you can use cmake to setup the build:
Installing OpenCV 3.0 for both Python 2.7 and Python 3+ on your Raspberry Pi 2
Shell
$ cd ~/opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..
1
2
3
4
5
6
7
8
9

$ cd ~/opencv
$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=ON \
-D INSTALL_PYTHON_EXAMPLES=ON \
-D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
-D BUILD_EXAMPLES=ON ..

Update (3 January 2016): In order to build OpenCV 3.1.0 , you need to set -D INSTALL_C_EXAMPLES=OFF (rather than ON ) in the cmake command. There is a bug in the OpenCV v3.1.0 CMake build script that can cause errors if you leave this switch on. Once you set this switch to off, CMake should run without a problem.

Ma quando arrivo al cmake inizio ad avere una serie di problemi.....

Uno dei problemi è questo:
pi@raspberrypi:~/opencv/build $ cmake -D CMAKE_BUILD_TYPE=RELEASE \
> -D CMAKE_INSTALL_PREFIX=/usr/local \
> -D INSTALL_C_EXAMPLES=ON \
> -D INSTALL_PYTHON_EXAMPLES=ON \
> -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
> -D BUILD_EXAMPLES=ON ..
CMake Error: The source directory "/home/pi/opencv" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.

Sinceramente però, il mio Raspberry mi sembra un po' troppo incasinato.

Forse mi conviene reinstallare il Raspbian e ripartire da 0.
Che tutorial mi suggerite per installare una versione di opencv che giri al meglio sul mi Raspberry Pi 2 B?
Risposta
#4
Si, c'è la nostra guida.
Il mio software non ha mai bugs. Include soltanto funzionalità casuali.


Risposta
#5
ok, quindi con la versione 2.4.10.

Grazie Gabb!!
Risposta
#6
Ciao Gabb,

ieri sera ho reinstallato il raspbian e sono ripartito da 0.
Ho quindi seguito la procedura da te indicata.
E' andato tutto bene fino a che, dopo aver settato la build ho lanciato il cmake e sono andato a dormire....
Purtroppo stamattina ho constatato che il procedimento è arrivato solo al 13% fermandosi con il seguente errore ripetuto n volte per vari codec :
/home/pi/opencv-2.4.10/modules/highgui/src/ffmpeg_codecs.hpp:104:7: error: 'CODEC_ID_H264' was not declared in this scope CODEC_ID_H264, MKTAG('h', '2', '6', '4')

Ora sono fermo in build.
Cosa posso fare per non buttare tutto quelo sino ad ora fatto?

Per ulteriore informazione, inoltro le ultime righe di errore (dopo quelle dei vari codec):

In file included from /home/pi/opencv-2.4.10/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/pi/opencv-2.4.10/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘double CvCapture_FFMPEG::getProperty(int)’:
/home/pi/opencv-2.4.10/modules/highgui/src/cap_ffmpeg_impl.hpp:774:33: error: ‘AVStream’ has no member named ‘r_frame_rate’
return av_q2d(video_st->r_frame_rate);
^
/home/pi/opencv-2.4.10/modules/highgui/src/cap_ffmpeg_impl.hpp: In member function ‘double CvCapture_FFMPEG::get_fps()’:
/home/pi/opencv-2.4.10/modules/highgui/src/cap_ffmpeg_impl.hpp:821:49: error: ‘AVStream’ has no member named ‘r_frame_rate’
double fps = r2d(ic->streams[video_stream]->r_frame_rate);
^
In file included from /home/pi/opencv-2.4.10/modules/highgui/src/cap_ffmpeg.cpp:45:0:
/home/pi/opencv-2.4.10/modules/highgui/src/cap_ffmpeg_impl.hpp: In function ‘int icv_av_write_frame_FFMPEG(AVFormatContext*, AVStream*, uint8_t*, uint32_t, AVFrame*)’:
/home/pi/opencv-2.4.10/modules/highgui/src/cap_ffmpeg_impl.hpp:1237:72: error: ‘avcodec_encode_video’ was not declared in this scope
out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture);
^
modules/highgui/CMakeFiles/opencv_highgui.dir/build.make:230: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o' failed
make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.cpp.o] Error 1
CMakeFiles/Makefile2:1921: recipe for target 'modules/highgui/CMakeFiles/opencv_highgui.dir/all' failed
make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
Makefile:149: recipe for target 'all' failed
make: *** [all] Error 2
(cv) pi@raspberrypi:~/opencv-2.4.10/build $
Risposta
#7
Ragazzi, un aiuto??
Risposta
#8
Problema risolto!!
Opencv versione 3.2.0 installata con successo e funzionante.
Tutto ciò grazie a questo tutorial: http://pklab.net/?id=392&lang=EN
Anche qui si era presentato il problema che dopo il reboot la picamera non veniva più rilevata da opencv.
Il problema è poi stato superato abilitando il seguente modulo:

Enable the kernel module:

sudo modprobe bcm2835-v4l2
Risposta
  


Vai al forum:


Navigazione: 1 Ospite(i)
Forum con nuovi Post
Forum senza nuovi post
Forum bloccato
Forum Redirect