Subscribe:

Ads 468x60px

.

Sunday, March 3, 2013

How to easily install OpenCV on Raspberry Pi

Hi all

      Building opencv source code in Raspberry Pi will take about 6-7 hours.
Here is the link to install opencv from source

Easy method to install opencv

1)Connect to Raspberry Pi using ssh. Fig shows an example of connecting Rpi using ssh




2)Install synaptic package manager from command line of raspberry pi


3)Install tight-vnc server from command line


4)Start a vnc server in Rpi for viewing the screen and detection window from opencv

Enter the command to start a vnc-server on Rpi

vncserver :1 -geometry 1366x600 -depth 16 -pixelformat rgb565

#New ‘X’ desktop is raspberrypi:1


5)Start vnc client from PC

eg: vncviewer 192.168.1.3:5901
eg:vncviewer rpi_ip:5901


6)Start synaptic from root terminal like this 


7)Install opencv from synaptic like this



8)Download the source code from below


9)Copy files from PC to Rpi using scp command

scp -r facedetect.py face.xml pi@192.168.1.3:"/home/pi"


10)Run python file using following command

python facedetect.py --cascade=face.xml 0


Output
--------


Video:


33 comments:

Anonymous said...

Why don't you just apt-get it? Surely that would be way faster then installing VNC for no reason...

sudo apt-get install *opencv*

Done.

Lentin Joseph said...

Yes ,ofcourse. It can be done in both ways. I did it in this way to showcase the desktop and make a feel that it is running in Rpi. :)

It will perform better if you run from ssh terminal

Lentin Joseph said...

I think this post cover most of commands for interacting with Rpi, So this will a good tutorial for beginers.

Arun Gopal said...

which type of camera are u used?

Arun Gopal said...

are you done same process in java and cross compilation of raspberry pi.and please give the source code for raspberry pi face detection .

Lentin Joseph said...

Hi Arun

I am using I ball face2facecam. I am not using java and all. I included the source code in the post itself.

http://www.mediafire.com/?ahd677sxyfpf1m7

Christopher Hills said...

When I used opencv on the Pi I just ran sudo apt-get install opencv-python and did a whole host of things. Check out my blog post http://orictosh.blogspot.co.uk/?m=1

Christopher Hills said...

Correction on that package name should be python-opencv

Arun Gopal said...

Hi,

i saw the opencv with eye and mouth and nose detection.iam download u r given source code and supported file.how to compile that face detection in the raspberry pi.please give me some steps how send this material on raspberry pi and how to compile that?iam send source code through scp command.is this ryt procedure?please clarify me.


Thanks&Regards,
K.Arungopal

Lentin Joseph said...

Hi Arun,

There is no change in the compilation procedure of opencv, its same as the pc, because we are working on OS layer, so command will be same.
What matters is processing power. When i tried the facedetection code, i scaled the image into 320x240. So what you have to do is scale image before processing. If you run face,nose and eye detection, it will take good amount of processing power, just rescale image into 320x240 and try, i have a doubt whether it work or not in RasPi.

Arun Gopal said...

ok thanks joseph.i want to compile opencv in raspberry pi.do u know about this?are u haveing any source code?presently iam working on this board for opencv face and eye and mouth detection.iam compiled u r code in raspi that is face detection only with rectangular.it is working cool.thanks.....when iam run the ./video it show s the error.please help me how to comipile that programe.



Thanks&Regards,
K.Arungopal

Arun Gopal said...

i have one dought.in python face detection is done in ractangular face using same code it is possible to get the mouth and eyes and nose detection.it is possible?if possible what changes iam done?i mean adding of extra xml file sin programe.how to add xml files in programe.



Thanks&Regards,

K.Arungopal

Anonymous said...

Hi, I think that is usefull show the list of packages that you installed on raspbian throught synaptic, while tha packages are installable throught apt, if the list is complete, someone could install opencv with terminal instead that on X or compile the library (lot of time).

Arun Gopal said...

Hi joseph thanks for the reply...what is my question is on the raspberry i want do the face detection?so please help me for giving any idea about that source code and xml files.....

Thanks&Regards,
K.Arungopal

Anonymous said...

hello joseph,i ran your face detection code on raspberrypi,but i am getting detection time in between 600 and 900 ms,your is 200 ms.i am using intex webcam.
Thanks&Regards,
Abhilash

Lentin Joseph said...

Hi

Did you try it without vnc_server?? And what about your webcam resolution, Is it 640x480?

Anonymous said...

hi,if i only use ssh,then its giving gtk error.should i modify the program?my webcam resolution is 640x480.
-abhilash

Arun Gopal said...

Hi joseph and anonymous....

first in raspberry pi install vncserver...for that open a terminal and type sudo apt-get install toghtvncserver....and open a host terminal and type sudo apt-get install xvnc4viewer....after installation in host type open a terminal and type in host vncviewer...type u r ip address and enter and it asks password and enter it shows the raspberry pi gui screen.....



Thanks&Regards,
K.Arungopal

Anonymous said...

I get an error message when I put this in the terminal ...

4)Start a vnc server in Rpi for viewing the screen and detection window from opencv

Enter the command to start a vnc-server on Rpi

vncserver :1 -geometry 1366x600 -depth 16 -pixelformat rgb565

#New ‘X’ desktop is raspberrypi:1

Lentin Joseph said...

Did you install tightvnc package in Raspberry Pi ? You need to install it first.

Anonymous said...

OK I installed it now. And got the vncserver running.

Now I cant get further at step 5).

I have a mac. How can I start the vncviewer there?

Anonymous said...

I got it already I installed VNC Viewer for Mac in the end and I hat to put the IP Adress like this in there 192.168.178:1.

Also OpenVC is working now. I had to kill motion first.

Thanks for the great tutorial!

Varun hebbar said...

how to transfer facedetect.py file from windows xp to raspberry pi vis ssh?

scp is not working..

Lentin Joseph said...

Try this

http://winscp.net/eng/index.php

Varun hebbar said...

thanx....

now i got another problem...
installed opencv from synaptic...and installed packages....
and i saved facedetect.py and face.xml in my gmail draft...then i saved both from raspberry pi platform(using midori browser)...
when i type this

python facedetect.py --cascade=face.xml 0

it gives the error

no module named cv2.cv in line 10....

please help...

Arun Gopal said...

Hi varun..iam using this blog..its absolutely work on raspberry pi..First u have to install simplecv in raspberry pi..http://www.internetdelascosas.cl/2012/12/06/instalando-bibliotecas-en-python/...Just follow this link..install python on raspberry pi bacause code in python..and for installing opencv in raspberry pi

sudo apt-get install libcv-dev
sudo apt-get install python-opencv
sudo apt-get install libopencv-dev
sudo apt-get install libcv2.3
sudo apt-get install libopencv-doc

Thats it u r opencv is installing on raspberry pi..its is very simple to use..try this sure u get output..xml and code files is send through only scp command only..otherwise it can not works.


Thanks&Regards,
K.Arungopal

Varun hebbar said...

after installing the above packages....there is no space left in pi....

what to do now?

showin no space left error....
please help

im using type B rpi....comes with 512MB RAM..

Lentin Joseph said...

@Varun ,I am using 32GB SD card, may be you need to expand the SD Card size,

"no space left error" is only due to SD card not due to RAM !!

Varun hebbar said...

ok im using 4gb card...

but i have a doubt...after plugin out the card from rpi and connecting to pc using card reader it shows
only 58MB used...

hazyy said...

Hi, thank you for this tutorial. I'm following the steps from terminal in my macbook. i reached this point and got:

pi@raspberrypi ~ $ vncviewer 102.168.2.2:5901
-bash: vncviewer: command not found

:( i don't know what to do here. can you please help me?

Lentin Joseph said...

Hi ,You need to run vncviewer from client system ,ie ubuntu. For getting vncviewer command in client system, you have to install xvnc4viewer from synaptic.

hazyy said...
This comment has been removed by the author.
Anonymous said...

Hi, after running the command
root@PIWEB:/OpenCV# python facedetect.py --cascade=face.xml 0

i got the following error:

(result:10414): Gtk-WARNING **: cannot open display: localhost:10.0

what is wrong there???

Thx

Post a Comment