OpenCV recognizes my camera but cant read - c++

I've been working on a computer vision project for a while now using the webcam of my laptop (it shows up as "HD WebCam" with 640x480 res) but want to use this program with the camera of my DJI-Inspire1 drone. The camera is recognized and opened but it fails to read images from it.
In more detail:
in my player class load camera function:
capture.open(-1); // this opens a window with a combobox showing all
//the cameras i have. Selecting the DJI camera fails
//the read while selecting the webcam fails and crashes.
// capture.open(0); opens the webcam succesfully
// capture.open(1);
open(1) seems to try to open DJI-Camera but gives different values than
open(-1) and crashes after reading a frame (the frames are entirely
black 720x480 CV_8UC3) In debug mode it crashes whie reading the frame with a Segmentation fault and points to a dissassembly of "DriverProc" (i guess?) and a line with a movdqa command.
// capture.open(2); oddly also seems to try and open DJI-camera now with
// 720x486 resolution resulting in a black 720x486 CV_8UC3 image (no crashes).
// anything above open(2) fails and crashes
if(capture.isOpened()){
// in here i check the values of different properties, they are:
// open(-1) open(1) open(2) HD WEBCAM
// CV_CAP_PROP_FORMAT = 0 -1 -1 -1
// CV_CAP_PROP_FRAME_WIDTH = 720 720 720 640
// CV_CAP_PROP_FRAME_HEIGHT = 486 480 486 480
// CV_CAP_PROP_FOURCC = 1.49883e+09 -4.66163e+08 -4.66163e08 8.44715e+08
// CV_CAP_PROP_FPS = 30 0 0 0
}
next up is in the main loop of the player class (its on its own thread)
while(!stop){
// this is the command that tries to read the next frame
if(!capture.read(frame)){
// this happens for the open(-1) version
}
}
So basically the resolution is either 720x486 or 720x480 which is very strange, there seems to be three cameras connected yet the list with capture.open(-1) shows only 2. open(2) will succefully load a black image :P. Im certain that the camera is working since i can view it in other applications such as "Livestream Studio". The Video goes from the camera to a controller (which reduces the resolution to 720 i think) wirelessly and from there to a Blackmagic design HDMI->USB3.0 converter and from there to the PC. After Intense googling i found out that the fourcc code 1.49883e+09 for the open(-1) version is indeed "2VUY" which is used by Blackmagic so that makes sense. could find what the -4.66163e08 ones mean though.
I'm using openCV 3.0.0 , minGW4.92 32bit , Qt 5.5.0
So does anyone have any ideas as to what the problem might be? I'm all out of ideas.

Related

Why does a full screen window resolution in OpenCV (# Banana Pi, Raspbian) slow down the camera footage and let it lag?

Currently I’m working on a project to mirror a camera for a blind spot.
The camera got 640 x 480 NTSC signal.
The output screen is 854 x 480 NTSC.
I grab the camera with an EasyCAP video grabber.
On the Banana Pi I installed open cv 2.4.9.
The critical point of this project is that the video on the display needs to be real time.
Whenever I comment the line that puts the window into fullscreen, there pop ups a small window and the footage runs without delay and lagg.
But when I set the video to full screen, the footage becomes slow, and lags.
Part of the code:
namedWindow("window",0);
setWindowProperty("window",CV_WND_PROP_FULLSCREEN,CV_WINDOW_FULLSCREEN);
while(1){
cap>>image;
flip(image, destination,1);
imshow("window",destination);
waitKey(33); //delay 33 ms
}
How can I fill the screen with the camera footage without losing speed and frames?
Is it possible to output the footage directly to the composite output?
The problem is that upscaling and drawing is done in software here. The Banana Pi processor is not powerful enough to process the needed throughput with 30 frames per second.
This is an educated guess on my side, as even desktop systems can run into lag problems when processing and simultaneously displaying video.
A common solution in the computer vision community for this problem is to use OpenGL for display. Here, the upscaling and display is offloaded to the graphics processor. You can do the same thing on a Banana Pi.
If you compiled OpenCV with OpenGL support, you can try it like this:
namedWindow("window", WINDOW_OPENGL);
imshow("window", destination);
Note that if you use OpenGL, you can also save on the flip operation by using an approprate modelview matrix. For this however you probably need to dive into GL code yourself instead of using imshow.
I fixed the whole problem by using:
namedWindow("window",1);
With FLAG 1 stands for WINDOW_AUTOSIZE.
The footage is more real-time now.
I’m using a small monitor, so the window size is nearly the same as the monitor.

OpenCV displays the image triplicated in a single frame

I am trying to build an application to simply get, save and show some frames from my camera, a DMK 41BU02 (you can consult the specifications of the device in the following link: datasheet)
My code is as simple as that:
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main(int, char**)
{
String path="~/proof.jpg";
VideoCapture cap(1); // /dev/video0 is the integrated webcam of my laptop, while /dev/video1 is the DMK41BU02 camera
cvNamedWindow( "Video", CV_WINDOW_AUTOSIZE );
if(!cap.isOpened()) // check if we succeeded
return -1;
Mat frame;
cap >> frame;
imwrite(path, frame);
imshow("Video", frame);
waitkey(0);
return 0;
}
The code compiles and executes whithout any problem, but the error arrives when the image is shown on the window or saved in the jpg file, because I get something like the following jpg, where the image is triplicated in the frame:
Resulting image of the code shown above
Some aspects to remark:
The code executes normally and returns normal images when working
with the integrated webcam of my laptop.
The DMK41BU02 camera works normally and returns normal images when working with another application, such as fswebcam or VLC.
The camera datasheet says it is compatible with OpenCV.
I have also tried the code with an infinite loop, as I know the first frame grabbed can be blank or with some type of error, but the problem is still there.
I have had some issues installing the camera drivers, but I think they're all resolved.
The laptop is a 32-bit machine with Ubuntu installed on it. Here you can see the output of uname -a: Linux AsusPC 3.11.0-18-generic #32~precise1-Ubuntu SMP Thu Feb 20 17:54:21 UTC 2014 i686 i686 i386 GNU/Linux
I have no idea of how to debug this problem and, of course, I don't know where the error could be. Could you give me any hint, please?
Thank you very much.
UPDATE: I forgot to post the weird outputs that the application writes in the terminal at the very beginning of the program:
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
libv4l2: error set_fmt gave us a different result then try_fmt!
HIGHGUI ERROR: libv4l unable convert to requested pixfmt
libv4l2: error set_fmt gave us a different result then try_fmt!
init done
opengl support available
I've had the exact same problem. The issue is within openCV itself, or more so; how cap_v4l.hpp (in the highgui module) and cap_libv4l.hpp are implemented.
The issue here is that OpenCV appearantly uses a wrong video type or channel type to read the data. Try playing arround with the different types (yuyv variants, etc) inside the opencv lib.
For some magical reason the cap_v4l.hpp is the code thats actually used by opencv and the code in cap_lib4l is not used, but seems to support more vide formats (It could be switched arround, i'm not sure about that).
Switching these files and recompiling opencv did improve stuff for me.
Since after the call to cap>>frame you have three channel (type=16), your capture is unaware that your camera is monochrome. Use grab-retrieve pairs instead since retrieve specifies number of channels.
bool VideoCapture::grab()
bool VideoCapture::retrieve(Mat& image, int channel=0)
Here is example code that also shows how to set camera parameters. You can also try to set some camera parameters that explicitly declare monochrome mode. If everything else fails you can always cut one image out of your triple with
Rect rect(0, 0, frame.cols/3, frame.rows);
Mat true_img = frame(rect).clone();
However, I kind of like what happens in your case. You have a natural frame queue and can analyze motion an possibly structure by looking at what happens in three consecutive frames.

Setting frame size of QuickCam Pro 3000 with OpenCV?

I'm using OpenCV 2.4.6 to grab images with my old Logitech QuickCam Pro 3000 webcam. Using VideoCapture::set( CV_CAP_PROP_FRAME_WIDTH, ... ) I'm not able to set the value of the width (idem for the height). set(...) always returns false.
Is it normal?
P.S. I'm on Linux (kubuntu) and it seems to use V4L.
It seems that your camera was not initialized properly. The following code works for me.
using namespace cv;
[...]
VideoCapture capture(0);
capture.set(CV_CAP_PROP_FRAME_WIDTH, width);
capture.set(CV_CAP_PROP_FRAME_HEIGHT, height);
I experimented with it a bit and found the following issues:
capture.set returns 0 if capture was not initialized.
capture.set returns 0 if camera is busy (another process using it).
It is not guaranteed that calling VideoCapture::set will change camera resolution to your desired resolution. For example, with my Logitech HD Pro Webcam C290, setting resolution to 640x480 and 1920x1080 works. But when I try 1024x768, VideoCapture::set returns true, but actual resolution is set to 960x720. So, check the actual resolution after reading a frame.

cvCaptureFromCAM causes program to hang

I have a multiple camera setup and an OpenCV application that has been working using two cameras. One camera is a Logitech C310, and the other has been my built-in camera on my MacBook Pro. On initialization I call cvCaptureFromCAM(), once for each camera. However, hooking up a second Logitech C310 (total of 3 cameras) causes the call to cvCaptureFromCAM() to hang for my MacBook pro camera.
Both Logitech cameras work together just fine. Once I call cvQueryFrame() for my MacBook camera it hangs, but eventually after maybe 2-3 minutes it returns what appears to be a valid pointer (i.e. not NULL), but that camera is not initialized. I receive no frames from that camera, and the light that is typically green when the camera is in use is not lit.
Here is a snippet of my code:
for( size_t i = 0; i < NUM_CAMERAS; i++ ) // Works fine when NUM_CAMERAS is 2, but hangs when it is 3
{
capture[i] = cvCaptureFromCAM( i );
if( capture[i] != NULL )
{
// Start a thread for each camera
}
}
// Threads manage calling cvQueryFrame() for each camera.
I am certain this is not an issue with multiple threads, because cvQueryFrame() always hangs, even if I do not start any new threads.
Thanks for any help - I'm having trouble finding anyone else with a similar issue.
OpenCV 2.4.5
OSX 10.8.4
gcc 4.2
Qt 5.0.2
Boost version 105300
2.4GHz Intel Core i7, retina Mac, 8BG RAM
2 x Logitech C310, 1 x MacBook Pro Camera
1 x Frustrated Dude
Turns out this is a limitation with my MacBook Pro. Running 2 USB cameras as well as the built-in iSight (which I believe is also USB internally), initialization of the 3rd device hangs. I can't provide a technical reason, but it seems it is a USB bandwidth issue.
I resolved this by using a Thunderbolt dock (http://www.belkin.com/us/p/P-F4U055) which has additional USB ports. Now my application works fine and initializes all cameras as it should. Also verified an Apple Thunderbolt display (which has a built in USB hub) also works.
Cheers!

OpenCV - Webcam does not work

I'm learning OpenCV because I want to build and program a 3D Scanner over the summer.
I bought three webcams for this purpose (two for the actual stereo images and one for texture [or as a backup]).
I tried to get a webcam's video with OpenCV. However, this does not work, as I ended up with a black screen, instead of video.
I then tried the same code with my grandmother's webcam. It worked fine.
However, I already bought 3 webcams of the type that I was planning on using to build my scanner: http://www.amazon.com/Webcam-Camera-Vision-Meeting-compatible/dp/B0015TJNEY/ref=pd_bxgy_e_img_b
I don't want to buy any new webcams.
Does anybody have any idea of why my webcams don't work with OpenCV (they work with other programs)?
How can I get OpenCV to accept my webcams?
Any suggestions would be appreciated!
Thanks
If your program pass this step , you should try a different number for cvCaptureFromCAM(0); 0 is the first web cam but maybe your's is set as 1, 2 or 3. you can also try -1 and see what happens
CvCapture *capture;
capture = cvCaptureFromCAM(0);
if (!capture)
{
printf("Error at capture");
return 1;
}