hoehermann
Posts: 24
Joined: Thu Jul 26, 2012 10:23 am

Re: OpenCV + webcam

Fri Aug 17, 2012 10:31 pm

uvccapture should decode YUYV correctly. But in many cases the uvcvideo module assumes totally wrong default values for various camera parameters. My pictures looked similar to what you describe until I settled for manually setting brightness, contrast, saturation and gain. uvccapture offers the undocumented parameters -B, -C, -S and -G for this purpose (if I remember correctly).
I made some additional experiments with my Raspberry Pi. It looks like the USB has severe issues that depend on what seems like attached peripherals, overall system load, day of time, quality of power suppy, mood of hardware, feng-shui flow of qi and presumably current weather conditions. All I can say is that somedays I even have to unplug my keyboard in order to make the camera work. While the camera is active, hot plugged devices are not recognized. I have less problems when I disable sound and ethernet by unloading the respective modules.

HVA
Posts: 11
Joined: Fri Aug 03, 2012 2:28 pm

Re: OpenCV + webcam

Sat Aug 18, 2012 1:36 pm

hoehermann wrote:GCC should find the header files itself. When you install a package, the header files are automatically put in the appropriate folders. On Debian it is /usr/include/. Therefore you should include <cv.h> rather than "cv.h", but it should work anyway. Sometimes a packager thinks it is useful to have the headers in a subdirectory. You can examine the examples C source file or the Makefile (compiler option -I) to find out the directory. I give you the advice never to compile something from source and install it yourself unless you really really have to. OpenCV is in the repository and installable via apt-get. Keep in mind that there often are two packages, for example opencv and opencv-dev. For development, you need both, as the latter includes the header files.
Hi hoehermann,

Apparently the situation of OpenCv in linux is not as what I have expected.

Are you kind to give us a few clues on how to install (and from where to get) Opencv-dev???
I have tried apt-get install... no luck

Please help

hoehermann
Posts: 24
Joined: Thu Jul 26, 2012 10:23 am

Re: OpenCV + webcam

Sat Aug 18, 2012 2:39 pm

The filename search for "cv.h" at http://packages.debian.org/ told me that the package name is actually libcv-dev. My bad. The header file's location then is /usr/include/opencv/cv.h, so you might have to write #include <opencv/cv.h>. For the more recent projects I use python-opencv, so my hints for the C world on linux are not 100% accurate.

HVA
Posts: 11
Joined: Fri Aug 03, 2012 2:28 pm

Re: OpenCV + webcam

Sat Aug 18, 2012 2:41 pm

hoehermann wrote:The filename search for "cv.h" at http://packages.debian.org/ told me that the package name is actually libcv-dev. My bad. The header file's location then is /usr/include/opencv/cv.h, so you might have to write #include <opencv/cv.h>. For the more recent projects I use python-opencv, so my hints for the C world on linux are not 100% accurate.
Hi hoehermann

It worked in the end but I had to do:
..
apt-get update
sudo apt-get install libopencv-dev
...
Now everything is fine.

Thank you very much

HVA
Posts: 11
Joined: Fri Aug 03, 2012 2:28 pm

Re: OpenCV + webcam

Sat Aug 18, 2012 4:08 pm

Hi,

I come again with some little questions regarding OpenCV.

1. when running the "facedetect" example on "lena.jpg" (512x512) it takes 25.5sec to do it. Is this right? Is not a bit too long?

2. On my applications and even on "facedetect" example some annoying message comes out:
Xlib extension "RANDR" missing on display ":1.0"

how can I get rid of it? and what does it mean?

Thank you

hoehermann
Posts: 24
Joined: Thu Jul 26, 2012 10:23 am

Re: OpenCV + webcam

Sat Aug 18, 2012 7:43 pm

1. 25s is quite a long time. However I do not know how complex the facedetect example is or how it actually works, so I can only compare apples and oranges. The Raspberry Pi does not include a very performant CPU. Its real number crunching abilities reside in the GPU. I do not expect someone modified the OpenCV libraries to utilize this very GPU for the floating point operations. So you may be out of luck and stuck with the poor performance. For my project the simple binarisation and edge detection is adequately fast. However I can not do much image filtering for preprocessing, everything that needs floating point operations (such as blur) is painfully slow. You simply cannot expect more performance from a low power consuming, low cost ultra small system.
2. RandR is a extension for the X server (which gives you the graphical desktop). See http://en.wikipedia.org/wiki/RandR . There can be many reasons for this problem to occur, some people say installing a GTK engine is necessary, e.g. the package gtk2-engines-pixbuf, others say they need to edit their /etc/X11/xorg.conf to include

Code: Select all

Section "Extensions"
 Option "Composite" "Enable"
 Option "RANDR" "Enable"
EndSection
I assume you don't need these features, so you can save yourself a lot of time by simply ignoring the message. For me, the debian "rasbian" wheezy from the official site is behaving just fine.

CrystalCowboy
Posts: 9
Joined: Mon Aug 27, 2012 8:44 pm

Re: OpenCV + webcam

Sun Sep 02, 2012 8:48 pm

kuroOluffy wrote:For my project, I only need to capture one frame from the camera and process the image. I do not require any streaming features.
I can recommend fswebcam, which does exactly that. It is available as a package with both Arch and Raspbian.

murali
Posts: 19
Joined: Sat Feb 09, 2013 11:50 am

OpenCV 2.3.1 +webcam+ python/C

Fri Feb 15, 2013 5:43 pm

Hi all,
I have installed openCV as per the instructions provided at http://mitchtech.net/raspberry-pi-opencv/
version number is 2.3.1.
I have used the C code provided in the previous posts of this very thread to capture the webcam image but when I compiled ...I got a big list of errors of nature undefined reference to the functions used.

My program and OpenCV library resides in the same directory /home/pi

I have also used a python program for the same job . when I tried to execute the program an error was reported

Traceback (most recent call last):
File "basic2.py", line 4, in <module>
cv.NamedWindow("camera",1);
AttributeError: 'module' object has no attribute 'NamedWindow'

Python program I used from net:

#! /usr/bin/python
open cv2 as cv;
cv.NamedWindow("camera", 1);
capture=cv.CaptureFromCAM(0);

while True :
img = cv.QueryFrame(capture)
cv.ShowImage("camera",img)
if cv.WaitKey(10)==27:
break
cv.DestroyWindow("camera")



my python program and OpenCV library reside in /usr/bin
please let me know where did I go wrong. I am in a great need of this job.

hoehermann
Posts: 24
Joined: Thu Jul 26, 2012 10:23 am

Re: OpenCV 2.3.1 +webcam+ python/C

Fri Feb 15, 2013 6:11 pm

murali wrote:please let me know where did I go wrong

Code: Select all

open cv2 as cv;
Here.
Your code is a messed combination of the old openCV bindings for phython, the new ones and a little bit of C syntax. Have a look at my code, which is using the new openCV bindings only. http://www.youtube.com/watch?v=Urm2kdGX8WQ

murali
Posts: 19
Joined: Sat Feb 09, 2013 11:50 am

Re: OpenCV + webcam

Sat Feb 16, 2013 4:56 am

hi hoehermann,
Thanks.

You mentioned that open cv2 as cv; is the place where I went wrong. Is it the only one and if so , what it should be?.
PS:I am very new to python.

hoehermann
Posts: 24
Joined: Thu Jul 26, 2012 10:23 am

Re: OpenCV + webcam

Sat Feb 16, 2013 10:39 am

murali wrote:I am very new to python
I noticed. Unfortunately, that import is not the only line which is wrong. I'll try to explain more detailed. In Python OpenCV can be used in two different manners. The first is via the cv module. It uses the old style binding between C and Python. Therefore, the resulting python code is very C-ish and programming is often tedious. The second (recommended) manner is via the cv2 module. It uses a more object oriented like approach and is much more pythonic. With this module, you have all the benefits of python, including dynamic typing, slice access, automatic memory management and many others.
In the description of the linked video is a link to the python code I used. You can extract the lines you need from there (basic initialisation, access to webcam, display of image).

murali
Posts: 19
Joined: Sat Feb 09, 2013 11:50 am

Re: OpenCV + webcam

Sat Feb 16, 2013 10:59 am

hi hoehermann,
The link contains the video of dice. I could not find any code there. Please give me the link to the code which you are refering to. Thanks!

hoehermann
Posts: 24
Joined: Thu Jul 26, 2012 10:23 am

Re: OpenCV + webcam

Sat Feb 16, 2013 2:01 pm

In the description of the linked video is a link to the python code I used.
I did not want to post the direct link as it is subject to change and I only want to update the references in one place. Here it is nevertheless: http://hehoe.de/hd/downloads/diceDetector.py

murali
Posts: 19
Joined: Sat Feb 09, 2013 11:50 am

Re: OpenCV + webcam

Mon Feb 18, 2013 3:35 am

hi hoeherman, thanks!
my webcam atleast started showing green light ...but
VIDIOC_QUERYMENU: Invalid Argument (3 times)
select timeout ... is shown
I have used the following code:
#! usr/bin/python

import cv2
cam=cv2.VideoCapture(0)
s,img=cam.read()
if s:
cv2.namedwindow("camera", cv2.CV_WINDOW_AUTOSIZE)
cv2.imshow("camera",img)
cv2.waitKey(0)
cv2.destroywindow("camera")

unfortunately, I cannot resize the window as the default flag is CV_WINDOW_AUTOSIZE
please suggest me some solution.

murali
Posts: 19
Joined: Sat Feb 09, 2013 11:50 am

Re: OpenCV + webcam

Mon Feb 18, 2013 12:12 pm

hi hoeherman,
please let me know how to change the timeout value in uvcvideo.ko file

User avatar
jasonclark
Posts: 58
Joined: Sun May 13, 2012 3:51 pm
Location: Hertfordshire, UK
Contact: Website

Re: OpenCV + webcam

Mon Feb 18, 2013 12:53 pm

I was using open CV late last year (I lost the code so can't share).
The best performance came from reducing the webcam image to a lower resolution and also converting it to a single channel (grey scale).

Once you get the array of faces, you can scale them back up. For my application pixel perfect alignment wasn't required, and scaling from 320x200 to 160x100 still gave enough information to detect faces, but with far less processing overhead.

Once you've scaled the found co-ordinates back, you can then base any manipulations on the full res image.
In my case, I used pyGAME to blit some objects (PNG with alpha) onto the image.

It was still slow, but certainly faster than 25 seconds.

The other problem I saw was that some examples were loading the XML files (for the open CV face recognition) for every detection. This is not required and I simply loaded it at the program start and retained the information.

hoehermann
Posts: 24
Joined: Thu Jul 26, 2012 10:23 am

Re: OpenCV + webcam

Mon Feb 18, 2013 3:58 pm

murali wrote:VIDIOC_QUERYMENU: Invalid Argument
select timeout
I ran into the same problem (see my previous posts in this topic).
murali wrote:please let me know how to change the timeout value in uvcvideo.ko file
Please refer to post http://www.raspberrypi.org/phpBB3/viewt ... 13#p149313 for detailed instructions on increasing the timeout. Decreasing resolution down to 320x240 should also remove the problem. Unfortunately I do not know how to capture high resolution images without having timeout problems. I am disappointed by my pi in this respect.

murali
Posts: 19
Joined: Sat Feb 09, 2013 11:50 am

Re: OpenCV + webcam

Tue Feb 19, 2013 1:34 am

thanks a lot!

Return to “Automation, sensing and robotics”