usb webcam runs slowly on raspberry pi with opencv - opencv

I have some code that I have adapted to run on a headless Rpi using a usb webcam, it is running a bit slow, so my questions are:
If I were to use the GPI pins with a dedicated webcam would that be faster?
Is there any way to speed up my code for Rpi?
Where can I get a Rpi webcam?
My code is here, I struggle to paste inline so its a link

For your question about where to get a Pi camera, a new camera has recently been release. I don't know about speeding up you code, but you might want to overclock your Pi. Good luck,

Like Quentin suggested, a dedicated Camera (in our case, Rpi camera link : http://www.raspberrypi.org/camera) should work much faster than USB webcams as it is known to use GPU for encoding / decoding process instead of using CPU.
(Source : http://www.raspberrypi.org/phpBB3/viewtopic.php?t=55798)
You can try reducing width and height of the frame for better performance in terms of speed.
Also you're using Iplimage* which is no longer supported in new OpenCV versions and replaced by cvMat.
(source: Difference between cvMat, Mat and IpImage)
Hope it helps.

Related

OpenCV HOG Algorithm in Real Time on Raspberry Pi

I would like to know if it is possible to run the OpenCV HOG Detector using a Raspberry Pi in real time using the Raspberry Pi camera.
Unfortunately not, even overclocked to 1000MHz and with 64MB for video it's not enough.
On my old mac with a 2.1 GHz Dual Core Intel CPU and 2GB of ram I could barely get between 8-12 FPS for a 640x480 stream.
I haven't tried OpenCV 3.0 (just 2.4.8) on Raspberry PI so don't have any softcascades test results to share, but it sounds promising.
Another idea I can think of is using LBP cascades. You could start with a HAAR since there's one already for detecting bodies so it would be easy to test, but LBP should be a bit faster. Perhaps you could train a cascade that works really well for a set environment.
Also, if it helps, you can use my little OpenCV wrapper for the PiCamera for tests. It basically returns frames from the Pi Camera module as cv::Mat.
I've had openCV running on a PI, using a USB video grabber, as I am using a CCTV camera. I use Python.
It runs fine (for what I want to do), but you need to limit the resolution.
It's slower than a PC (2ghz dual core) but still works.

openCV compatible webcams

I have read that openCV does not recognise some webcams.
Can you suggest some webcams for a basic stereo-vision project using the following?:
openCV 2.2.0
Visual Studio 2010 (C++)
Windows 7 32 bits
Thanks.
I posted a similar question back then.
Good and compatible webcam to do image processing/computer vision?
What kind of camera you are looking for? Any model? State the model and I let you know if it's good enough.
Also, you can find a list of compatible webcams with openCV. It's an old list though. They stopped updating it since 2013, I think. Compatible webcam with openCV
You find that most common brands like Hp, Logitech, etc should work just fine. If you are worried, just state the model you are looking at in the comments. I see if I know if it's compatible with openCV.
EDIT:
To answer your question in the comment, nope, that shouldn't be the case. All cameras can run simultaneously at the same time. Reasons that cameras can't run simultaneously at the same time is usually due to the USB bandwidth. In fact, most cameras pose the same problem.
Some methods to overcome that problem:
1)put a Sleep(ms) in between the lines of your capture line.
2)Use lower resolution which would reduce the bandwidth used by each camera.
3)Use MJPEG format(compressed frames)

Image Processing - Beaglebone vs Raspberry Pi

I've been researching for a while and found tons of helpful resources on this subject, but I figured I would lay down my specifications here so I can get some recommendations from people experienced in this area. It seems like Beaglebone and Raspberry Pi with a Logitech or Microsoft camera are my best options at this point.
My target speed is 50 fps (20 ms per image) with the processing involved. From what I've looked at, this doesn't seem feasible considering most webcams don't go much past 30 fps. More specifically, I need to take the endpoints of an object (like a sheet of paper) and calculate where the midpoint is. Nothing incredibly fancy. 1080p isn't a requirement, I can most likely go much lower. Python is preferable over C and C++ since I've already done a lot of image processing with Python.
It looks like a lot of the code I'll be needing is mostly open-source already, so I really just need to figure out what controller/camera combo I should be using.
It's still a bit of a toss up between the two however here are my views.
The BBB will use a USB web cam and that will take a certain amount of processing power just to get the image. After that you can then manipulate it with SimpleCV
The RPi has a camera board that they say will only use < 3% of the cpu and the rest can be used for processing your image. Plus you can over-clock the RPi to 1Ghz.
Using the RPi with a basic webcam does not give a very good result, whereas the RPi camera works directly on the CSI bus and is set to do 1080 dpi natively. Plus they now have drivers for the camera that work with SimpleCV too.
IMHO I would say that the RPi B and Camera board would be technically faster that the BBB, but it also depends on what manipulation you plan to do :
Marc

2 usb cameras not working with opencv

I'm working on a project of computer vision and I need to use two cameras using opencv library. I tried this code but with two webcams from USB port it doesn't work while it works if I use one usb camera and the camera of my pc.
CvCapture* capture[2];
capture[0] = cvCreateCameraCapture(0);
capture[1] = cvCreateCameraCapture(1);
if(!capture[0] && !capture[1])
printf("Webcam error\n");
I'm working on windows 7 on an acer aspire 5742g. Is it a problem of the bus of my computer? The cameras are 2 Philips SPZ2000.
I tried also to work on the pictures taken by the one of them and from the camera on my pc and when I use the code for calibration and rectification found on the book "Learning opencv" of Bradsky I get a bad result. Can somebody help me?
Thank you in advance,
Sara
The typical reason for 2+ USB cameras to not work together (still they might be working fine separately) is that USB bandwidth is insufficient for them both to run simultaneously. There is a bandwidth limit, which is rather low: The maximum throughput of an isochronous pipe (which is usually used for video) is 24MB/s.
More on this issue:
Implications of using many USB web cameras
How many USB cameras can be accessed by one PC
Not able to capture video using 2 webcamera simulteneously
Two webcams on one usb hub - bandwidth issues

OpenCV + Webcam compatibility

For the people that have experience with OpenCV, are there any webcams that don't work with OpenCV.
I am looking into the feasibility of a project and I know I am going to need a high quality feed (1080p), so I am going to need a webcam that is capable of that. So does OpenCV have problems with certain cameras?
To be analysing a video feed of that resolution on the fly I am going to need a fast processor, I know this, but will I need a machine that is not consumer available...ie, will an i7 do?
Thanks.
On Linux, if it's supported by v4l2, it is probably going to work (e.g., my home webcam isn't listed, but it's v4l2 compatible and works out of the box). You can always use the camera manufacturer's driver to acquire frames, and feed them to your OpenCV code. You can even sub-class the VideoCapture class, and implement your camera driver to make it work seamlessly with OpenCV.
I would think the latest i7 series should work just fine. You may want to also check out Intel's IPP library for more optimized routines. IPP also easily integrates into OpenCV code since OpenCV was an Intel project at its inception.
If you need really fast image processing, you might want to consider adding a high performance GPU to the box, so that you have that option available to you.
Unfortunately, the page that I'm about to reference doesn't exist anymore. OpenCV evolved a lot since I first wrote this answer in 2011 and it's difficult for them to keep track of which cameras in the market are supported by OpenCV.
Anyway, here is the old list of supported cameras organized by Operating System (this list was available until the beginning of 2013).
It depends if your camera is supported by OpenCV, mainly by the driver model that your camera is using.
Quote from Getting Started with OpenCV capturing,
Currently two camera interfaces can be used on Windows: Video for Windows (VFW) and Matrox Imaging Library (MIL) and two on Linux: Video for Linux(V4L) and IEEE1394. For the latter there exists two implemented interfaces (CvCaptureCAM_DC1394_CPP and CvCapture_DC1394V2).
So if your camera is VFW or MIL compliant under Windows or suits into standard V4L or IEEE1394 driver model, then probably it will work.
But if not, like mevatron says, you can even sub-class the VideoCapture class, and implement your camera driver to make it work seamlessly with OpenCV.

Resources