0
#include <iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace std;
using namespace cv;
int main(int argc, const char* argv[]) {
VideoCapture cap(0);
if(!cap.isOpened())
{
cout<<"can't open video file"<<endl;
return -1;
}
namedWindow("Myvideo",CV_WINDOW_AUTOSIZE);
while(1)
{
Mat frame;
bool bsuccess=cap.read(frame);
if(!bsuccess)
{
cout<<"can't read a frame"<<endl;
break;
}
imshow("Myvideo",frame);
if(waitKey(30)==27)
{
cout<<"Esc key is pressed by the user"<<endl;
break;
}
}
return 0;
}
上述代碼僅用於從攝像頭捕獲視頻。 但我想從這個視頻中獲得一張圖片(即只有一幀)。有人可以告訴我如何做到這一點。我實際上試圖刪除while循環,這樣我就可以得到一個循環,而不是一個接一個地循環(即視頻)。並且還刪除了「break」聲明。如何從視頻剪輯使用opencv和eclipse獲取單幀
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>`
using namespace std;
using namespace cv;
int main(int argc, const char* argv[]) {
VideoCapture cap(0);
if(!cap.isOpened())
{
cout<<"can't open video file"<<endl;
return -1;
}
namedWindow("Myvideo",CV_WINDOW_AUTOSIZE);
Mat frame;
cap.read(frame);
imshow("Myvideo",frame);
if(waitKey(30)==27)
{
cout<<"Esc key is pressed by the user"<<endl;
}
return 0;
}
但不幸的是,它只是顯示一個空白窗口。 誰能幫我...在此先感謝
@cyriel ...這真的是一個聰明的信息...它的工作......非常感謝。 – venus