我試圖從視頻文件保存圖像,但它無法保存我的硬盤驅動器中的任何圖像。我編譯了以下程序,沒有錯誤。使用OpenCV無法保存圖像
#include <stdio.h>
#include <stdlib.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int main(int argc, char* argv[]) {
int c=1;
IplImage* img=0;
IplImage* small;
IplImage* small=new IplImage(inputArray);
char buffer[1000];
CvCapture* cv_cap=cvCaptureFromFile("test.avi");
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);
while(1) {
img=cvQueryFrame(cv_cap);
cvShowImage("Video",img);
small = cvCreateImage(cvSize(img->width/2,img->height/2), 8, 3);
sprintf(buffer,"C:/image%u.jpg",c);
c++;
if (cvWaitKey(100)== 27) break;
}
cvDestroyWindow("Video");
return 0;
}
我使用的是2.3.1 OpenCV庫和Visual Studio 2010 我如何保存圖像從一個視頻文件?
我自己也嘗試這個代碼,上面的程序代碼是什麼wrong.please看到下面的程序code.After我添加以下代碼,也出現了同樣的問題。
cvSaveImage(buffer,img);
修正程序下顯示。請到看到這一點,告訴我,我所做的wrong.but沒有編譯error.after我運行程序它不保存任何圖像。
#include"stdafx.h"
#include<cv.h>
#include<highgui.h>
#include<cxcore.h>
int main(int argc, char* argv[]) {
int c=1;
IplImage* img=0;
char buffer[1000];
CvCapture* cv_cap=cvCaptureFromCAM(-1);
cvNamedWindow("Video",CV_WINDOW_AUTOSIZE);
while(1) {
img=cvQueryFrame(cv_cap);
cvShowImage("Video",img);
sprintf(buffer,"D:/image%u.jpg",c);
cvSaveImage(buffer,img);
c++;
if (cvWaitKey(100)== 27) break;
}
cvDestroyWindow("Video");
return 0;
}
你能告訴我如何保存圖像。上面的程序不保存任何圖像。請給我你的建議。謝謝。
在這段代碼是你想救它?看起來你沒有對包含文件名的'buffer'做任何事情。 – WeaselFox 2012-04-01 08:04:49
另外,如果您使用C++,爲什麼要使用舊的C接口? – etarion 2012-04-01 09:39:42
可能重複的[不保存任何圖像..當保存視頻幀](http://stackoverflow.com/questions/9966600/doesnt-save-any-image-when-saving-frames-of-a -video) – karlphillip 2012-04-01 20:12:40