OpenCV imwrite() not saving image

后端 未结 7 1262
梦毁少年i
梦毁少年i 2020-12-31 13:00

I am trying to save an image from OpenCV on my mac and I am using the following code and so far it has not been working.

cv::imwrite(\"/Users/nickporter/Desk         


        
7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 13:52

    The following function can be dropped into your code to support writing out jpg images for debugging purposes.

    You just need to pass in an image and a filename for it. In the function, specify a path you wish to write to & have permission to do so with.

    void imageWrite(const cv::Mat &image, const std::string filename)
    {
        // Support for writing JPG
        vector compression_params;
        compression_params.push_back( CV_IMWRITE_JPEG_QUALITY );
        compression_params.push_back( 100 );
    
        // This writes to the specified path
        std::string path = "/path/you/provide/" + filename + ".jpg";
    
        cv::imwrite(path, image, compression_params);
    }
    

提交回复
热议问题