這是我從視頻獲取幀的代碼。我想在循環和條件下在視頻中顯示2幀。使用opencv獲取幀視頻
int main(int argc, char** argv)
{
string fileName = "E:\\Tugas Akhir\\Video Master\\city_1.avi";
Mat image1;
Mat image2;
Mat frame;
cv::Mat result;
VideoCapture cap(fileName);
if(!cap.isOpened())
return -1;
Mat edges;
for(int loop=0;;loop++)
{
//std::cout<<loop<<endl;
cap >> frame; // get a new frame from camera
if(loop>0 && (loop%20)==0){
//std::cout<<"frame 2"<<endl;
image2=frame;
**imshow("image2",image2);**
break;
}else if(loop==0){
image1=frame;
**imshow("image1",image1);**
//std::cout<<"frame 1"<<endl;
}
//loop++;
if(waitKey(30) >= 0) break;
}
waitKey(0);
return 0;
}
而這裏的結果,2個窗口有2個不同的圖像
,但是當我改變imshow( 「圖像1」,此搜索)方式的位置...
if(loop>0 && (loop%20)==0){
//std::cout<<"frame 2"<<endl;
image2=frame;
**imshow("image1",image1);**
**imshow("image2",image2);**
break;
}else if(loop==0){
image1=frame;
//std::cout<<"frame 1"<<endl;
}
image1窗口顯示與圖片2相同的圖片,
我不知道爲什麼它顯示奇怪的結果,請告訴我如何解決它,謝謝
目前尚不清楚你將要做什麼。 – rmi