ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
The following code works for me. two usb cameras, opencv2.3.1, MSVS2008, windows7 32 bit
#include "highgui.h"
#include "stdio.h"
int main()
{
CvCapture * capture1=cvCaptureFromCAM(0);
CvCapture * capture2=cvCaptureFromCAM(1);
if(!capture1)
{
printf("Cannot find device1!\n");
exit(0);
}
if(!capture2)
{
printf("Cannot find device2!\n");
exit(0);
}
IplImage * image1=0;
IplImage * image2=0;
cvNamedWindow("Grab1");
cvNamedWindow("Grab2");
while(1)
{
image1=cvQueryFrame(capture1);
image2=cvQueryFrame(capture2);
if(!image1||!image2)
break;
cvShowImage("Grab1",image1);
cvShowImage("Grab2",image2);
int key=cvWaitKey(10);
if(27==key)
break;
}
cvReleaseCapture(&capture1);
cvReleaseCapture(&capture2);
cvDestroyWindow("Grab1");
cvDestroyWindow("Grab2");
return 0;
}
2 | No.2 Revision |
The following code works for me. two usb cameras, opencv2.3.1, opencv2.1, MSVS2008, windows7 32 bit
#include "highgui.h"
#include "stdio.h"
int main()
{
CvCapture * capture1=cvCaptureFromCAM(0);
CvCapture * capture2=cvCaptureFromCAM(1);
if(!capture1)
{
printf("Cannot find device1!\n");
exit(0);
}
if(!capture2)
{
printf("Cannot find device2!\n");
exit(0);
}
IplImage * image1=0;
IplImage * image2=0;
cvNamedWindow("Grab1");
cvNamedWindow("Grab2");
while(1)
{
image1=cvQueryFrame(capture1);
image2=cvQueryFrame(capture2);
if(!image1||!image2)
break;
cvShowImage("Grab1",image1);
cvShowImage("Grab2",image2);
int key=cvWaitKey(10);
if(27==key)
break;
}
cvReleaseCapture(&capture1);
cvReleaseCapture(&capture2);
cvDestroyWindow("Grab1");
cvDestroyWindow("Grab2");
return 0;
}
3 | No.3 Revision |
The following code works for me. two usb cameras, opencv2.1, MSVS2008, windows7 32 bit
#include "highgui.h"
#include "stdio.h"
int main()
{
CvCapture * capture1=cvCaptureFromCAM(0);
CvCapture * capture2=cvCaptureFromCAM(1);
if(!capture1)
{
printf("Cannot find device1!\n");
exit(0);
}
if(!capture2)
{
printf("Cannot find device2!\n");
exit(0);
}
IplImage * image1=0;
IplImage * image2=0;
cvNamedWindow("Grab1");
cvNamedWindow("Grab2");
while(1)
{
image1=cvQueryFrame(capture1);
image2=cvQueryFrame(capture2);
if(!image1||!image2)
break;
cvShowImage("Grab1",image1);
cvShowImage("Grab2",image2);
int key=cvWaitKey(10);
if(27==key)
break;
}
cvReleaseCapture(&capture1);
cvReleaseCapture(&capture2);
cvDestroyWindow("Grab1");
cvDestroyWindow("Grab2");
return 0;
}
the following code is with opencv2.3.1. also succeed.
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
int main()
{
cv::VideoCapture cap1, cap2;
cv::Mat frame1, image1, frame2, image2;
cap1.open(0);
cap2.open(1);
if( !cap1.isOpened() )
{
std::cout << "Could not initialize cap1"<<std::endl;
return -1;
}
if( !cap2.isOpened() )
{
std::cout << "Could not initialize cap2"<<std::endl;
return -1;
}
for(;;)
{
cap1 >> frame1;
if( frame1.empty() )
break;
frame1.copyTo(image1);
cap2 >> frame2;
if( frame2.empty() )
break;
frame2.copyTo(image2);
cv::imshow( "Img1", image1 );
cv::imshow( "Img2", image2 );
char c = (char)cv::waitKey(10);
if( c == 27 )
break;
}
return 1;
}