I want to save my output image in .jpg format only, because then I use the same image to execute another code, which requires its image in .jpg format. I used imwrite function, which gives me Unhandled exception: Access violation reading location. When I tried to save the same in .bmp format it works fine.
My example code taken from here:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image;
// LOAD image
image = imread("image1.jpg", CV_LOAD_IMAGE_COLOR); // Read the file "image.jpg".
//This file "image.jpg" should be in the project folder.
//Else provide full address : "D:/images/image.jpg"
if (!image.data) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl;
return -1;
}
//DISPLAY image
namedWindow("window", CV_WINDOW_AUTOSIZE); // Create a window for display.
imshow("window", image); // Show our image inside it.
//SAVE image
imwrite("result.jpg", image);// it will store the image in name "result.jpg"
waitKey(0); // Wait for a keystroke in the window
return 0;
}
This code also gives same error. Is there any way I can save image in jpeg format only.
Reference:
1. Example that shows we can save the image in .bmp format.
2. I have downloaded openCV 3.0 and not built it on own. So I think this solution is ruled out.
3. My error is something similar to this code. But the solution here does not work.
I use OpneCV 3.0, Visual studio 2013, Windows 8.1.
Error got:
Thank you for any help.
opencv_world300.dllin your project? I ran your code and I did not use that DLL at all. Also, try addingopencv_imgcodecs300.dllto the same directory as your CPP file.opencv_ffmpeg300.dllis added to the folder where .exe is present as stated by @Humam Helfawi. Yes, @Rowen I removedopencv_world300.dlland works fine. But I didn't findopencv_imgcodecs300.dll.