Opencv doesn't detect firewire webcam on linux - c++

I have connected a cam through firewire and tried to access it using opencv. The camera is detected in coriander and able to get a video stream. Below is the code I used
#include "/home/iiith/opencv-2.4.9/include/opencv/cv.h"
#include "/home/iiith/opencv-2.4.9/include/opencv/highgui.h"
#include "cxcore.h"
#include <iostream>
using namespace cv;
using namespace std;
int main(int,char**)
{
VideoCapture cap(0);
if(!cap.isOpened())
cout<<"Camera not detected"<<endl;
while(1)
{
Mat frame;
namedWindow("display",1);
cap >> frame;
imshow("display",frame);
waitKey(0);
}
}
When I run this code, the video is streamed from the webcam instead of my firewire cam. I tried the same code in my friend's system and there the firewire cam was detected. I tested the settings using different commands such as testlibraw , lsmod and they are all the same. Even the Opencv version, 2.4.9, Ubuntu 12.04 are all the same. This is really bizarre and am at this for 2 days. Can anyone please tell me what the difference could be? How can I get the external cam detected in opencv? Thanks in advance.
Note : Does this have something to have with setting the default cam? Thanks.
Update 1 : VideoCapture cap(1) gives the following error
HIGHGUI ERROR: V4L: index 1 is not correct!
Does this mean the camera is not recognized?

First, you should be sure that camera is recognized from your s.o.
unplug camera and wait few seconds;
open terminal and digit:
watch dmesg
lspci | grep -E -i "(1394|firewire)" #this could give you something
plug your device and read new entry on terminal
if your device is recognized you can launch a command like this:
mplayer tv:// -tv driver=v4l2:width=352:height=288

The Possible problem could be that the camera connected through firewire is not recognized by the system.
First try to see the camera output using AMcap or some other webcam software and check if you are able to see this.
If you not able to see the video in amcap then it means that drivers of that particular camera is missing.

Related

How can set exposure time for DMM 27UJ003-ML camera using opencv

I'm using a camera which is called DMM 27UJ003-MLand the documents are available via this link. This camera has some features such as Brightness which can be set in OpenCV, see the following code for instance
//Header
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
VideoCapture cap(0); //Access to camera with ID = 0
double brightness = cap.get(CV_CAP_PROP_BRIGHTNESS); // get value of brightness
cout<<brightness<<endl; //print brightness value in console
}
result is 0.5 and it's OK,I can set Brightness as well, but if i want to change Exposure time the problem will be appear!!(Exposure time is another camera property that can be variable)
int main()
{
VideoCapture cap(0);
cap.set(CV_CAP_PROP_EXPOSURE,0.1);
}
ButExposure time can't be set in appropriate way and if want to use get method to knowing what set as Exposure time value,result is strange
VideoCapture cap(0);
double Exposure = cap.get(CV_CAP_PROP_EXPOSURE);
cout<<Exposure<<endl;
result of Exposure is inf and camera doesn't response to outside environment(it seems that Exposure time is inf actually) so the only way to reset Exposure timeis software that company gave to me and i don't know how i can set this feature in opencv
thanks for your help.
Add the following code at the beginning:
cap.set(CV_CAP_PROP_AUTO_EXPOSURE,0.25);
0.25 means 'manual mode'.
If you use Linux based machine you can install a package that will help you about that, which it's name is v4l2ucp,this package can be install by below command in ubuntu
sudo apt install v4l2ucp
this is a package that give you graphical control on camera with using great v4l2 package (by installing v4l2ucp there is no need to install v4l2 again). if you can change exposure time in the v4l2ucp then you can use v4l2 inside of your program.
you can get whole information about your camera by below command in ubuntu terminal.
v4l2-ctl --all
after knowing which parameters are available for you by using above command you can change value of that parameter. for example of my output is like below
brightness (int) : min=-10 max=10 step=1 default=0 value=0
you can see there is a variable of camera,which it's name is brightness and defalut value of that is 0 and there is boundary for value (min=-10, and max =10) so how can I set this value to 10 for instance? I can do this by below command(please test it by open camera)
v4l2-ctl --set-ctrl brightness=10
after doing that in terminal you can see brightness changes in camera.
So how we could use v4l2 command inside Qt programming? by using QProcess class, this command let you to run terminal commands inside of Qt program. I write a simple example
#include <QProcess>
int main()
{
QProcess process;
process.start("v4l2-ctl --set-ctrl brightness=10");
pro.waitForFinished(-1);
}

How to capture video from an external camera using opencv on ubuntu

I am a beginner to ubuntu. I am trying to drive a external camera on ubuntu 15.04. I want to know how to combine opencv library with camera driver. So I can capture video use sentences like
VideoCapture cap;
cap.open(0);//0,1,2...
Does anyone have some idea? Looking forward to your reply!
It depends on the camera you use, some cameras you need do nothing, and some cameras give API,you can use the API to get the video then use opencv to do something.

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.

Firewire camera with OpenCv 2.4. not working

I am using OpenCV 2.4 with C++ for image processing and video streaming . I would like to know how we can use fire-wire camera like pixilink to capture frames? I tried the VideoCapture class but it seems to work with only usb cameras unlike firewire one. If some one has done same thing with firewire camera then kindly give some guidance how to do that?
You can capture images using firewire SDK or you can also libdc1394 API. I found libdc1394 to more reliable and easy to use and there are couple of examples available to get start.

OpenCV not initializing USB camera

I am trying to capture video from a USB camera using OpenCV.
#include <highgui.h>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
VideoCapture cap (-1);
if (!cap.isOpened())
cout << "Cam initialize failed";
else cout << "Cam initialized";
return 0;
}
It is failing to initialize the camera. cap.isOpened() is returning zero.
The same program, with same version of OpenCV and the same USB camera, is correctly running in my friend's machine. I am running Fedora 16. The camera is properly working in another application (for example, Cheese).
I did some searching in Google and Stack Overflow. But no useful help.
Any idea?
Try running your program as root. You may not have permission, and opencv doesn't tell you if thats the reason cap.isOpened() failed.
The manual here says that the VideoCapture::VideoCapture(int device) accepts
device: id of the opened video capturing device (i.e. a camera index). If there is a single camera connected, just pass 0.
I think you should change the -1 to 0 if you have 1 camera in your system.