OpenCV on the Raspberry Pi


31 posts   Page 1 of 2   1, 2
by eduardofv » Tue May 22, 2012 6:28 pm
I've just got OpenCV running on the rpi. Hope this guide helps: http://eduardofv.com/read_post/185-Installing-OpenCV-on-the-Raspberry-Pi
Posts: 29
Joined: Tue May 22, 2012 2:58 pm
by ucola » Tue May 22, 2012 7:59 pm
gooood job! thx!
i wil also use the raspberry pi for using opencv... i wil build a cat door :)
Posts: 16
Joined: Tue May 22, 2012 7:54 pm
by eduardofv » Tue May 22, 2012 9:49 pm
Good to know! Are you planning a cat door that recognizes and opens only to your cat? Sounds great!
Posts: 29
Joined: Tue May 22, 2012 2:58 pm
by ucola » Tue May 22, 2012 10:01 pm
it wil detect if my cat have a mouse in his mouth and block then the door :)
but i need help how they mus be done with the electronic on the raspberry pi platine...
Posts: 16
Joined: Tue May 22, 2012 7:54 pm
by jeem » Thu May 24, 2012 9:05 pm
Thank you for this documentation.

Could you please do some basic benchmark regarding Webcam capture?

Like a loop that captures image, convert it to grayscale, show the image, start again, then average the time it takes to do the loop.

I am definitely going to play with OpenCV on the Pi. I am just waiting for the Pi :lol:
http://www.jeremy-nicola.info
Posts: 11
Joined: Sat Nov 19, 2011 11:40 am
by eduardofv » Thu May 24, 2012 9:36 pm
Jeem, I've found that the webcam is not recognized on Debian. There's some discussion regarding some missing kernel modules. I've gone to Archlinux and got an old webcam (creative pd1170 with gspca-conex driver). If you need to do this, take into account that there seems to be some problem when updating libusb, so don't update the system (pacman -Syu) and always answer No when asked to update pacman.

This said, it's much more easier to install opencv on archlinux. I installed lxde, cheese and opencv and samples now run on the pi, including webcam!

That said, I've tested the webcam with QT V4L2 test utility and found 18fps on a 352x288 resolution. The webcam is pretty old and crappy and the driver isn't that good either, so I would expect better performance with another camera.

I'm trying to install a Logitech c270 but I've got an error that seems looks like to be regarding the include mic. Hope to solve soon.
Posts: 29
Joined: Tue May 22, 2012 2:58 pm
by jeem » Fri May 25, 2012 4:38 pm
eduardofv wrote:Jeem, I've found that the webcam is not recognized on Debian


That's really annoying !

Is the default kernel used by debian built with V4L support enabled?

eduardofv wrote:That said, I've tested the webcam with QT V4L2 test utility and found 18fps on a 352x288 resolution.


That's not awesome too, I realy hope it's just an old driver issue. All the projects I am planning to do on the Pi will be totaly useless without good webcam support :/
http://www.jeremy-nicola.info
Posts: 11
Joined: Sat Nov 19, 2011 11:40 am
by merlz42 » Sat May 26, 2012 2:15 pm
It's likely that the slowdown is due to displaying it on the screen. Try running one of the openCV demo's, or turning the image display off and counting the fps that it can load from the camera at.

My guess is using feature detection will reduce the framerate about the same amount as displaying it, so you should still get about 18fps using haar features or something.

You can also try clocking your rpi to 800mhz, as that'll possibly give you a few fps boost. Increasing the RAM speeds may also help.
Posts: 20
Joined: Sun May 13, 2012 1:19 pm
by eduardofv » Sun May 27, 2012 2:26 am
Thanks! In this case I think the main culprit is the crappy camera. I've got a newer Logitech c270 but is not working, not even on my Ubuntu laptop... I'll keep working on this

merlz42 wrote:It's likely that the slowdown is due to displaying it on the screen. Try running one of the openCV demo's, or turning the image display off and counting the fps that it can load from the camera at.

My guess is using feature detection will reduce the framerate about the same amount as displaying it, so you should still get about 18fps using haar features or something.

You can also try clocking your rpi to 800mhz, as that'll possibly give you a few fps boost. Increasing the RAM speeds may also help.
Posts: 29
Joined: Tue May 22, 2012 2:58 pm
by Feej » Mon May 28, 2012 6:39 am
I'd be very interested to know if anyone does manage to get a C270 working. They appear to be supported well for linux in general.

I spent some time (mine, and that of a very helpful IRC member :-D ) last night recompiling and sticking the uvcvideo module in to my Debian kernel.

When attempting to run Cheese it definitely tries to do something (shows a "working" animation), but then segfaults. Haven't had a chance to look more closely just yet.
Posts: 8
Joined: Sun May 27, 2012 11:10 am
by eduardofv » Mon May 28, 2012 1:13 pm
I've got the Logitech c270 working on the Raspberry Pi. It runs on Archlinux, but don't know if it was a module that I added to the original image what that make it work.

But the main issue seems to be power. I built a "powered usb cable" to connect the camera and now it works quite reliable (at 3 o 4 fps, though). I measured the current consumption and when connected it uses about 40 or 50mA but capturing video it goes up to some 250mA which is too much for the Pi, thus the need for the external power. I guess that if you can get a powered hub it should work. I'm preparing a blog post on the DIY powered usb cable, yet I guess that using it may be somewhat risky.

Also cheese doesn't work all the time for me. QT V4L2 Test Utility and wxCam are working better for me.

Feej wrote:I'd be very interested to know if anyone does manage to get a C270 working. They appear to be supported well for linux in general.

I spent some time (mine, and that of a very helpful IRC member :-D ) last night recompiling and sticking the uvcvideo module in to my Debian kernel.

When attempting to run Cheese it definitely tries to do something (shows a "working" animation), but then segfaults. Haven't had a chance to look more closely just yet.
Posts: 29
Joined: Tue May 22, 2012 2:58 pm
by Feej » Mon May 28, 2012 4:12 pm
Thanks for the update. I'd like to try getting it to work on Debian if I can (given the effort that's gone into getting this far :-) ) but I'd be willing to try Arch. I see from your previous comments that it can't be updated easily though due to libusb issues?

Payday this week, so I'll look into powered USB hubs and go from there! I would very much like to get it working though. If you have any new insights into what got the C270 working, please share, it would be very useful.

I'll update with any progress.
Posts: 8
Joined: Sun May 27, 2012 11:10 am
by eduardofv » Mon May 28, 2012 5:46 pm
Posts: 29
Joined: Tue May 22, 2012 2:58 pm
by Bluemerlin » Mon May 28, 2012 6:47 pm
I've been preparing an OpenCV python program ready for the pi.

The pi arrived and I compiled the uvc video module for my webcam drivers, and the camera is now recognised.

However during the program I do a cvqueryframe I just get a seg fault (even with display output turned off. :( Will be seeing if others get the same problem.
Posts: 57
Joined: Tue Dec 20, 2011 3:41 pm
by Psycho Squid » Mon May 28, 2012 6:56 pm
Face recognition will be awesome if possible.
Rasberry Pi model B
GNU\Linux
Andreas Eriksson
Karlstad, Sweden
User avatar
Posts: 5
Joined: Mon May 28, 2012 6:23 pm
Location: Karlstad, Sweden
by eduardofv » Mon May 28, 2012 6:56 pm
I'm pretty sure it must be a power issue. Try a powered hub
Posts: 29
Joined: Tue May 22, 2012 2:58 pm
by Fanjita » Thu Jun 07, 2012 10:00 am
Bluemerlin wrote:I've been preparing an OpenCV python program ready for the pi.

The pi arrived and I compiled the uvc video module for my webcam drivers, and the camera is now recognised.

However during the program I do a cvqueryframe I just get a seg fault (even with display output turned off. :( Will be seeing if others get the same problem.


I found Arch Linux to be so much more stable and easy to get going with than Debian for OpenCV / webcam work. Also, one of my main breakthroughs was to go with smaller capture resolutions - my Pi just couldn't cope with full resolution from my (crappy) cam.

More details of my adventures at http://fanjita.org/serendipity/archives/57-Capturing-webcam-video-with-OpenCV-on-Raspberry-Pi-Arch-Linux.html
Posts: 17
Joined: Thu Jun 07, 2012 9:31 am
Location: Edinburgh, UK
by ucola » Thu Jun 07, 2012 10:10 am
Can you try the facedetection sample script (on OpenCV sample folder) and tell us about the performance?

thx
Posts: 16
Joined: Tue May 22, 2012 7:54 pm
by Fanjita » Thu Jun 07, 2012 11:36 pm
ucola wrote:Can you try the facedetection sample script (on OpenCV sample folder) and tell us about the performance?


It's not fast... I'm still using the python bindings, so ported an equivalent version of that sample grabbed from http://blog.jozilla.net/2008/06/27/fun-with-python-opencv-and-face-detection/ (although that needed some tweaking for efficiency, and for the latest python bindings).

I currently get about 0.3 FPS - but it does seem very accurate. I've experimented with not drawing the images (I'm currently remoting the output of OpenCV to XWindows on my iMac over wired LAN, so there shouldn't be much load), and it didn't make a significant difference - 0.32 FPS.

Possibly I'm being hampered by a kernel without good floating point optimization for the Pi - I haven't looked into that. And I'm not overclocking at all.
Posts: 17
Joined: Thu Jun 07, 2012 9:31 am
Location: Edinburgh, UK
by eduardofv » Fri Jun 08, 2012 11:04 pm
Here are my notes on how I got OpenCV running on Arch Linux on the Pi. Hope this helps! http://eduardofv.com/read_post/192-OpencCV-on-the-Raspberry-Pi-with-Arch-Linux-ARM
Posts: 29
Joined: Tue May 22, 2012 2:58 pm
by Feej » Sun Jun 10, 2012 6:02 pm
Eduardo and Fanjita, thanks so much for your blogs, they're really helpful! I had to spend some time learning how to compile the UVC module for Debian, so I've done a slightly more basic tutorial on this and posted it here. Hopefully this will be helpful to less experienced users.

A powered USB hub is definitely required (I'm using a Belkin one listed on the verified peripherals page), and one more thing which I think has been mentioned elsewhere on the forum is that your user has to be added to the video group. Before I did this I was getting segfaults.

I can now use SSH with X-forwarding to login to the Pi, and use Cheese to view the capture. It seems to work at a steady 3 FPS @ 640x480. I have yet to install and test OpenCV for face detection; hopefully that will be done in the next week.

Thank you all for your help and blog posts, and especially to the person who walked me through compilation via IRC... can't remember your name, sorry!
Posts: 8
Joined: Sun May 27, 2012 11:10 am
by ucola » Sun Jun 10, 2012 6:33 pm
im sure, if you use a slower resolution, you became more fps...

regards
Posts: 16
Joined: Tue May 22, 2012 7:54 pm
by Feej » Mon Jun 11, 2012 8:28 pm
Upon attempting to compile on the Pi, I get the following error:

[ 37%] Building CXX object modules/core/CMakeFiles/opencv_test_core.dir/test/test_operations.o c++: Internal error: Killed (program cc1plus) Please submit a full bug report. See <file:///usr/share/doc/gcc-4.4/README.Bugs> for instructions.
make[2]: *** [modules/core/CMakeFiles/opencv_test_core.dir/test/test_operations.o] Error 1 make[1]: *** [modules/core/CMakeFiles/opencv_test_core.dir/all] Error 2 make: *** [all] Error 2

I'm presently attempting this compile again after rebooting with arm224.elf for some more available memory.

If anyone has any ideas as to what might be causing this issue, please let me know!
Posts: 8
Joined: Sun May 27, 2012 11:10 am
by Fanjita » Mon Jun 11, 2012 11:19 pm
Here's a little glimpse of the sort of thing I'm trying to achieve with this project : http://www.fanjita.org/serendipity/archives/59-The-Raspberry-Rover.html.

I made a simple roving robot that uses Hue-Saturation-Value analysis to spot different-coloured objects in the environment, and navigate towards them.

Eventually I'd like to add some more sophisticated detection and analysis, but the results are quite satisfying so far. When I have a little more time I'll post the code, circuit schematics etc.
Posts: 17
Joined: Thu Jun 07, 2012 9:31 am
Location: Edinburgh, UK
by eduardofv » Mon Jun 11, 2012 11:33 pm
Fanjita, the rover looks great! I'm pretty sure that when the CSI camera is available it will work great. Congrats!
Posts: 29
Joined: Tue May 22, 2012 2:58 pm