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 2035
灰色年华
灰色年华 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 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); 
    

提交回复
热议问题