0


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:
enter image description here

Thank you for any help.

2
  • Do you really have to use opencv_world300.dll in your project? I ran your code and I did not use that DLL at all. Also, try adding opencv_imgcodecs300.dll to the same directory as your CPP file. Commented Mar 28, 2016 at 10:58
  • It works when opencv_ffmpeg300.dll is added to the folder where .exe is present as stated by @Humam Helfawi. Yes, @Rowen I removed opencv_world300.dll and works fine. But I didn't find opencv_imgcodecs300.dll. Commented Mar 28, 2016 at 12:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.