Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to save an image with JPEG output in opencv 3.2.0?

Hello, I am using opencv 3.2.0 and I simply want to read an image and simple save the same image to JPEG output with compression ratio of 75%. There is an example for PNG format: http://docs.opencv.org/trunk/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce . I use the following instructions:

include <opencv2 core.hpp="">

include <opencv2 opencv.hpp="">

include <opencv2 imgcodecs.hpp="">

include <opencv2 highgui.hpp="">

pragma comment(lib, "opencv_world320.lib")

pragma comment(lib, "opencv_world320d.lib")

using namespace std; using namespace cv;

int main() { /******************* Declaring Variables ******************/ int x, y; Mat my_img; vector<int> compression_params; /****************** load and dispaly an image ******************/ my_img = imread("E:/Standard_Images/goldhill.jpg", CV_LOAD_IMAGE_COLOR); cout << "The image dimensions:" << my_img.rows << "" << my_img.cols << endl; cout << "The number of the channels:" << my_img.channels() << endl; cout << "The image depth: " << my_img.depth() << endl; namedWindow("Lena", WINDOW_AUTOSIZE); imshow("Lena", my_img); waitKey(0); destroyWindow("Lena"); /******************* Compress the image with JPEG and write into a new file *******************/ compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params.push_back(75); bool bSuccess = imwrite("E:/Standard_Images/My_Image.jpg", my_img, compression_params); if (!bSuccess) { cout << "Couldn't save the file" << endl; } else { namedWindow("The Saved file", CV_WINDOW_AUTOSIZE); Mat openImage = imread("example.jpg", CV_LOAD_IMAGE_UNCHANGED); imshow("The Saved file", openImage); } getchar(); return 1; } But it fails to save the output image and the following error is issued: "Exception thrown at 0x00007FFF08DC86C2 (opencv_world320.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000020F4BADF000." Do you have any idea about how to save an image with JPEG format? Thanks a lot for your help

How to save an image with JPEG output in opencv 3.2.0?

Hello, I am using opencv 3.2.0 and I simply want to read an image and simple save the same image to JPEG output with compression ratio of 75%. There is an example for PNG format: http://docs.opencv.org/trunk/d4/da8/group__imgcodecs.html#gabbc7ef1aa2edfaa87772f1202d67e0ce . I use the following instructions:

include <opencv2 core.hpp="">

include <opencv2 opencv.hpp="">

include <opencv2 imgcodecs.hpp="">

include <opencv2 highgui.hpp="">

pragma
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>

#pragma comment(lib, "opencv_world320.lib")

pragma "opencv_world320.lib") #pragma comment(lib, "opencv_world320d.lib")

"opencv_world320d.lib") using namespace std; using namespace cv;

cv; int main() { /******************* /************************************************************ Declaring Variables ******************/ ************************************************************/ int x, y; Mat my_img; vector<int> compression_params; /****************** /************************************************************ load and dispaly an image ******************/ ************************************************************/ my_img = imread("E:/Standard_Images/goldhill.jpg", CV_LOAD_IMAGE_COLOR); cout << "The image dimensions:" << my_img.rows << "" "*" << my_img.cols << endl; cout << "The number of the channels:" << my_img.channels() << endl; cout << "The image depth: " << my_img.depth() << endl; namedWindow("Lena", WINDOW_AUTOSIZE); imshow("Lena", my_img); waitKey(0); destroyWindow("Lena"); /******************* /************************************************************ Compress the image with JPEG and write into a new file *******************/ ************************************************************/ compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); compression_params.push_back(75); bool bSuccess = imwrite("E:/Standard_Images/My_Image.jpg", my_img, compression_params); if (!bSuccess) { cout << "Couldn't save the file" << endl; } else { namedWindow("The Saved file", CV_WINDOW_AUTOSIZE); Mat openImage = imread("example.jpg", CV_LOAD_IMAGE_UNCHANGED); imshow("The Saved file", openImage); } getchar(); return 1; }

But it fails to save the output image and the following error is issued: "Exception thrown at 0x00007FFF08DC86C2 (opencv_world320.dll) in ConsoleApplication1.exe: 0xC0000005: Access violation reading location 0x0000020F4BADF000." Do you have any idea about how to save an image with JPEG format? Thanks a lot for your help