項目要求:利用雙攝像頭同時採集兩個視頻,離線拼接,將兩個視頻拼接成一個視頻。
該部分代碼實現功能:
將視頻轉換爲圖像序列(有順序的)
代碼:
//雙目攝像頭 //詢問拍攝多久的視頻,以秒爲單位計算 //獲取相應時間的視頻 //將對應時間的視頻,以每幀存儲圖像 #include<iostream> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main() { VideoCapture cap00("..\\video\\103_fmlaf\\two_test0.avi"); VideoCapture cap11("..\\video\\103_fmlaf\\two_test1.avi"); if(cap00.isOpened() && cap11.isOpened()) cout << "ok ,have a video" << endl; else cout << "no video" << endl; Mat frame00,frame11; string src_image_namea = "..\\pic_a\\105_fmlaf_pica\\"; const int num00 = 500; char num[num00],num1[4] = "1(",num2[6] = ")"; string num3 = ".jpg"; int numbera = 1; for (int i = 1; ;i++) { itoa(i, num, 10); cap00 >> frame00; if(frame00.empty()) break; imwrite(src_image_namea+num1+num+num2+num3,frame00); } cap00.release(); //重複上一步驟 string src_image_nameb = "..\\pic_b\\105_fmlaf_picb\\"; const int num11 = 500; char numb[num11],num1b[4] = "1(",num2b[6] = ")"; string num3b = ".jpg"; for (int i = 1; ;i++) { itoa(i, numb, 10); cap11 >> frame11; if(frame11.empty()) break; cout <<"b"<< endl; imwrite(src_image_nameb+num1b+numb+num2b+num3b,frame11); } cap11.release(); system("pause"); return 0; }