opencv、c++、Qt連續擷取雙目攝像頭畫面
阿新 • • 發佈:2018-12-15
雙目標定前,嘗試獲取雙目相機的影象,但是所得影象是兩個攝像頭的畫面相連而成的。
#include <iostream> #include <opencv2/opencv.hpp> #include <fstream> #include <stdio.h> using namespace std; using namespace cv; int main() { VideoCapture capture(0); // 雙目攝像頭index為0 Mat cam; int i = 0; char filename[10]; char c = 0; while (capture.read(cam)) //capture >> cam { imshow("camwindow",cam); //視窗顯示 c = cvWaitKey(10); if (c == 'c') //連續按c鍵擷取攝像頭畫面,預設儲存在工程編譯目錄下 { sprintf(filename, "img%d.jpg",i++); //圖片命名img0.jpg , img1.jpg... imwrite(filename, cam); } c = cvWaitKey(10); if (c == 27) //退出 ,27為Esc鍵 { break; } } return 0; }