The code for displaying the contents of the two cameras simultaneously with OPENCV is as follows:
#include <iostream>#include<stdio.h>#include<tchar.h>#include<cv.h>#include<cvaux.h>#includeusing namespacestd;int_tmain (intARGC, _tchar*argv[]) {Cvcapture* Cam0 = Cvcapturefromcam (Cv_cap_dshow +0); if(!cam0) {fprintf (stderr,"Could not initialize opening of Camera 0..\n"); System ("Pause"); return-1; } printf ("Cam0 initialized\n"); DoubleHeight0 =Cvgetcaptureproperty (Cam0, cv_cap_prop_frame_height); DoubleWidth0 =Cvgetcaptureproperty (Cam0, cv_cap_prop_frame_width); Cvnamedwindow ("Camera 0", cv_window_autosize);//Create a window called "Camera 0"cvcapture* cam1 = Cvcapturefromcam (Cv_cap_dshow +1); if(!cam1) {fprintf (stderr,"Could not initialize opening of Camera 1..\n"); System ("Pause"); return-1; } printf ("cam1 initialized\n"); DoubleHEIGHT1 =Cvgetcaptureproperty (cam1, cv_cap_prop_frame_height); DoubleWidth1 =Cvgetcaptureproperty (cam1, cv_cap_prop_frame_width); Cvnamedwindow ("Camera 1", cv_window_autosize);//Create a window called "Camera 1" while(1) {Iplimage*cam0frame =Cvqueryframe (CAM0); if(cam0frame) {cvshowimage ("Camera 0", Cam0frame); } iplimage*cam1frame =Cvqueryframe (CAM1); if(cam1frame) {cvshowimage ("Camera 1", Cam1frame); } if(Cvwaitkey ( -) == -)//wait for the ' ESC ' key press for 30ms. If ' ESC ' key is pressed, break loop{cout<<"ESC key is pressed by user"<<Endl; Break; }} cvreleasecapture (&cam0); Cvreleasecapture (&cam1); Cvdestroywindow ("Camera 0"); Cvdestroywindow ("Camera 1"); return 0;}
OpenCV show two cameras display two cameras simultaneously