cv::imwrite could not find a writer for the specified extension

The following command causes an exception.

cv::imwrite("test.jpg", diffImg);

I also tried numerous variations on this, including absolute paths and PNG export. Here's the error:

Exception at 0x75abd36f, code: 0xe06d7363: C++ exception, flags=0x1 (execution cannot be continued) in opencv_core231!cv::error

C:\slave\WinInstallerMegaPack\src\opencv\modules\highgui\src\loadsave.cpp:276: error: (-2) could not find a writer for the specified extension

According to this related thread my current OpenCV installation doesn't support the image formats I tried. But I merely downloaded the precompiled Windows framework like their site suggested.

How can I get JPG export working?


I have also faced this issue and I have observed that this issue will come when I use the image without any extension. like abc.jpg but I rename it abc only.

You must use an image name with extension.


Just mention the format in which you like to save your image like image.jpg, image.jpeg

cv2.imwrite('image.jpg',image)