OpenCV C ++无法保存捕获的图像

时间:2016-01-20 10:05:38

标签: c++ eclipse opencv

首先,抱歉我的英语不好。 我是OpenCV的新手,我希望保存从我的摄像头捕获的图像。 我从此链接http://www.samundra.com.np/opencv-code-to-save-image/403

获取了代码
#include <iostream>
#include <opencv/cv.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"


int main(int argc,char** argv)
{
     char path[255];

 // For Linux, path to save the captured image
 //strcpy(path,"/home/samundra/sample.jpg");

 // For Windows, path to save the captured image
   strcpy(path,"c:\\home.jpg");

 // Pointer to current frame
  IplImage *frame;

 //Resize image to small size
  IplImage *small;

 // Create capture device ready
 // here 0 indicates that we want to use camera at 0th index
    CvCapture *capture = cvCaptureFromCAM(0);

  // highgui.h is required
   cvNamedWindow("capture",CV_WINDOW_AUTOSIZE);

   frame = cvQueryFrame(capture);

 // Must be initialized before actually cvResize is used
 // we are creating image of size that is half of the original frame    captured
 // 8 = Bits     3 = Channel
 small = cvCreateImage(cvSize(frame->width/2,frame->height/2), 8, 3);

 while(1)
 {
    // Query for Frame From Camera
    frame = cvQueryFrame(capture);

    // Resize the grabbed frame

       cvResize(frame, small);    //cvResize(source, destination)

     // Display the captured image
       cvShowImage("capture", small);

     char ch =  cvWaitKey(25);  // Wait for 25 ms for user to hit any key
       if(ch==27) break;  // If Escape Key was hit just exit the loop

      // Save image if s was keyboard
      if(ch=='s')
      {
         cvSaveImage(path,small);
      }
   }

  // Release All Images and Windows
  cvReleaseImage(&frame);
  cvReleaseImage(&small);
  cvDestroyWindow("capture");
   return 0;
  }

我正在使用OpenCV 2.3.1和Eclipse,在编译完代码后,网络摄像头已成功打开,但我的图像未保存。谢谢你的帮助。

0 个答案:

没有答案