[OpenCV]How to detect and connect camera automatically
How can i detect and connect camera automatically?
How can i detect and connect camera automatically?
For the instance you can write a function that will try to open video capture devices by enurator started from the 0:
cv::VideoCapture _videocapture;
std::vector<std::pair<int,cv::String>> v_videodevices
int _devid = 0;
while(true) {
if(_videocapture.open(_devid)) {
v_devices.push_back( std::make_pair<int,cv::String>(_devid, "Device " + std::to_string(_devid)) );
_devid++;
} else {
break;
}
}
_videocapture.release();
Alternativelly you can use Qt library and QCamera class to enumerate all available video devices.
VideoCapture capture(0);
if(!capture.isOpened())
{
return (-1);
}
double width= capture.get(CV_CAP_PROP_FRAME_WIDTH);//u can get the width of the frame
double height= capture.get(CV_CAP_PROP_FRAME_HEIGHT);;//u can get the height of the frame
Mat Frame;
for( ; ; )
{
capture>> Frame;
if(!Frame.empty())
{
do what ever u want with the captured frames
}
if(waitKey(30) == 27)//since esc key ASCII Value is 27 and if it is pressed for 30 ms it will stop the camera
{
cout<<"Esc key is pressed"<<endl;
break;
}
By default set the device Id= 0. So that automatically it will detect the camera.
Thank you for your answer. But if I connect the device like this:not device --->connect device---->disconnect device-->connect device Could you give me some advices?
Asked: 2016-12-06 20:24:03 -0600
Seen: 5,526 times
Last updated: Dec 19 '16
Area of a single pixel object in OpenCV
build problems for android_binary_package - Eclipse Indigo, Ubuntu 12.04
OpenCV DescriptorMatcher matches
Can't compile .cu file when including opencv.hpp
Using OpenCV's stitching module, strange error when compositing images
compile error in opencv2/flann/lsh_table.h when compiling bgslibrary