问题描述
我尝试从影片档案储存图片,但无法在我的硬碟中储存任何图片。我编译了以下程序没有错误。
I was trying to save images from a video file but It couldn't save any image in my hard drive. I compiled following program without errors.
#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.
如何从视频文件保存图像?
I am using a 2.3.1 openCV library and Visual Studio 2010.How can I save the image from a video file?
我也试过这个代码,上面的程序代码有些错误。请看下面的程序代码。我添加以下代码后,也有同样的问题。
I have also tried this code,above program code are something wrong.please see following program code.After i adding following code ,also there was a same problem.
cvSaveImage(buffer,img);
更正的程序如下所示。看到这个,告诉我我做错了什么。编译错误。运行程序后,它不保存任何图像。
Corrected program is shown below.please see this and tell me what i did wrong.but there is not compile error.after i run the program it doesn't save any image.
#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;
}
你能告诉我如何保存图片。
can you tell me how to save a image .above program doesn't save any images.please give me your suggestions.thank you.
推荐答案
不知道你是否解决了问题。如果不是你可以使用imwrite(test.jpg,img);保存图片
Don't know if you solved the problem or not. if not you can use imwrite("test.jpg",img); to save an image,
这里是一个示例 -
while(1){
here is an example- while(1) {
img=cvQueryFrame(cv_cap);
cvShowImage("Video",img);
imwrite("test.jpg",img);
}
这篇关于不能使用OpenCV保存图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!