OpenCV imwrite 2.2 causes exception with message “OpenCV Error: Unspecified error (could not find a writer for the specified extension)” on Windows 7

前端 未结 3 2017
灰色年华
灰色年华 2021-01-02 06:25

I\'m porting an OpenCV 2.2 app from Unix (that works) onto Windows 7 64-bit and I receive the following exception when cv::imwrite is called

\"OpenCV Error: Unspecif

相关标签:
3条回答
  • 2021-01-02 06:38

    Try

    cvSaveImage("test.jpg", &(IplImage(image)));
    

    instead of

    imwrite("test.jpg", image);
    

    This is a known bug in the version you are using.

    0 讨论(0)
  • 2021-01-02 06:43

    From the OpenCV 2.2 API:

    The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension, see imread for the list of extensions. Only 8-bit (or 16-bit in the case of PNG, JPEG 2000 and TIFF) single-channel or 3-channel (with ‘BGR’ channel order) images can be saved using this function. If the format, depth or channel order is different, use Mat::convertTo , and cvtColor to convert it before saving, or use the universal XML I/O functions to save the image to XML or YAML format.

    You might have more luck converting your file to 8 or 16 bits before saving.

    However, even with single channel 8 bit files I have had unknown extension errors trying to save jpg or png files but found that bmp works.

    0 讨论(0)
  • 2021-01-02 07:02

    Your current installation of OpenCV doesn't support the file format you are trying to create on disk.

    Check if the extension of the file is right. If it is, you'll have to recompile OpenCV and add support to this format and possibly install the libraries you are missing.

    That's all that can be said without more information.

    EDIT:

    As I have also failed building an application that uses the C++ interface of OpenCV (v2.3 on VS2005) I ended up using the following workaround: convert the C++ types to the C types when necessary.

    To convert from IplImage* to cv::Mat is pretty straight forward:

    IplImage* ipl_img = cvLoadImage("test.jpg", CV_LOAD_IMAGE_UNCHANGED);
    Mat mat_img(ipl_img);
    
    imshow("window", mat_img);
    

    The conversion cv::Mat to IplImage* is not so obvious, but it's also simple, and the trick is to use a IplImage instead of a IplImage*:

    IplImage ipl_from_mat((IplImage)mat_img);
    
    cvNamedWindow("window", CV_WINDOW_AUTOSIZE);
    // and then pass the memory address of the variable when you need it as IplImage*
    cvShowImage("window", &ipl_from_mat); 
    
    0 讨论(0)
提交回复
热议问题