學opencv時間不長,但又比較喜歡玩,看以前電視上會有那種一個屏幕上顯示多幅圖像的玩意,感覺很好玩,比較好奇,自己利用opencv做了一個簡單的分屏顯示的小程序
其實很簡單,就是對數據結構進行的操作,說到底就是對指針的操作,利用cvGetCols函數分別將兩幅圖像的數據分別放到自己創建的一個CvMat數據矩陣中,這樣就可以在一個窗口中將兩幅圖像le
下面是具體的程序實現,程序很簡單,對於高手來說可能比較幼稚,千萬別噴我啊
CvCapture *capture1 = 0;
CvCapture *capture2 = 0;
IplImage *image1 = 0;
IplImage *image2 = 0;
CvMat *M_image1;
CvMat *M_image2;
CvMat part;
cvNamedWindow("woaini,haiyingyang" , 1);
for(; ;)
{
capture1 = cvCaptureFromCAM(0);
if(!capture1)
printf("capture1 failed/n");
capture2 = cvCaptureFromCAM(1);
if(!capture2)
printf("capture2 failed/n");
image1 = cvQueryFrame(capture1);
if(!image1)
printf("query image1 failed/n");
image2 = cvQueryFrame(capture2);
if(!image2)
printf("query image2 failed/n");
M_image1 = cvCreateMat(image1->height , image1->width , CV_8UC3);
M_image2 = cvCreateMat(image1->height , image1->width , CV_8UC3);
cvConvert(image1 , M_image1);
cvConvert(image2 , M_image2);
CvMat *pair = cvCreateMat(image1->height , image1->width*2 , CV_8UC3);
cvGetCols(pair , &part , 0 , image1->width);
cvCopy(M_image1 , &part);
cvGetCols(pair , &part , image1->width , image1->width*2);
cvCopy(M_image2 , &part);
cvShowImage("woaini,haiyingyang" , pair);
if(cvWaitKey(10) >= 0)
break;
}
cvDestroyWindow("woaini,haiyingyang");
cvReleaseCapture(&capture1);
cvReleaseCapture(&capture2);
cvReleaseImage(&image1);
cvReleaseImage(&image2);
return 0;
效果圖: