我正在嘗試編寫一個程序,該程序使用OPENCV
和CPP將視頻文件的每個幀存儲爲圖像。我用ffmpeg
和mplayer
實現了這個目標。我想用OPENCV
來得到它。誰能幫忙?是否有任何其他功能將圖像存儲到IMWRITE()
以外的文件?訪問每個視頻幀並對其進行處理
OPENCV
是否有任何功能可以實時獲取在設備的特定端口可用的視頻的實況流?即將每個流的幀存儲爲圖像? 任何人都可以幫我嗎?
在此先感謝.. :)
我正在嘗試編寫一個程序,該程序使用OPENCV
和CPP將視頻文件的每個幀存儲爲圖像。我用ffmpeg
和mplayer
實現了這個目標。我想用OPENCV
來得到它。誰能幫忙?是否有任何其他功能將圖像存儲到IMWRITE()
以外的文件?訪問每個視頻幀並對其進行處理
OPENCV
是否有任何功能可以實時獲取在設備的特定端口可用的視頻的實況流?即將每個流的幀存儲爲圖像? 任何人都可以幫我嗎?
在此先感謝.. :)
節省隨着編號的文件名的所有圖像,這對我的作品:
const char* videofilename = "StopMoti2001.mpeg";
cv::VideoCapture cap(videofilename); // open a video file
if(!cap.isOpened()) // check if succeeded
{
std::cout << "file " << videofilename << " not found or could not be opened" << std::endl;
return;
}
cv::namedWindow("output");
unsigned long counter = 0;
cv::Mat frame;
// read frames until end of video:
while(cap.read(frame))
{
// display frame
cv::imshow("output", frame); cv::waitKey(25); // remove this line if you don't need the live output
// adjust the filename by incrementing a counter
std::stringstream filename (std::stringstream::in | std::stringstream::out);
filename << "image" << counter++ << ".jpg";
std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;
// save frame to file: image0.jpg, image1.jpg, and so on...
cv::imwrite(filename.str().c_str(),frame);
}
謝謝..我試過了程序,但我得到了分段錯誤(核心傾倒)錯誤 –
是顯示任何圖像或任何文件寫入? 'for(;;)'不太好,因爲對於視頻文件(不同於現場攝像機),文件的末尾會有某處結束;) – Micka
沒有任何內容顯示或沒有文件寫入。 –
爲什麼'CV :: imwrite'不是你合適嗎? – Micka
它只複製最後一幀。我想保存所有的幀爲image1.jpg,image2.jpg .... –