Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Python save jpg specifying quality; gives SystemError

I just installed the newest OpenCV 2.4 on windows 7 (32bit)/ Python 2.7.3,
but I still get the same error I got using the beta version:

>>> import cv2 >>> a = cv2.imread(r"DMap.jpg") >>> a.shape (1080, 1920, 3) >>> cv2.imwrite('img_CV2_90.jpg', a, [cv2.IMWRITE_JPEG_QUALITY, 90]) Traceback (most recent call last):   File "<input>", line 1, in <module> SystemError: error return without exception set 

Any ideas ? Using tuple instead of list, or adding a trailing 0 to the sequence does not help - same error.

Thanks - Sebastian Haase

like image 889
sebhaase Avatar asked May 02 '12 08:05

sebhaase


People also ask

How do I save an image in OpenCV Python?

When working with OpenCV Python, images are stored in numpy ndarray. To save an image to the local file system, use cv2. imwrite() function of opencv python library.

How do I find the resolution of an image in OpenCV?

there is no way to do that with opencv. and resolution is a dtp thing, it's irrelevant in computer-vision. As @berak says, the resolution is largely irrelevant until you actually come to lay down the pixels on a piece of paper or a screen.

Which method of OpenCV is used to save images?

cv2. imwrite() method is used to save an image to any storage device. This will save the image according to the specified format in current working directory.

What is Imread in OpenCV?

imread() method loads an image from the specified file. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format) then this method returns an empty matrix. Syntax: cv2.imread(path, flag) Parameters: path: A string representing the path of the image to be read.


1 Answers

It is probably due to some wrong wrapping of the imwrite() parameters from Python to C, cv2.IMWRITE_JPEG_QUALITY (which is of type "long"), and causes some weird problems. You should try to convert this constant to "int" type:

cv2.imwrite('img_CV2_90.jpg', a, [int(cv2.IMWRITE_JPEG_QUALITY), 90]) 

for me it solved the problem (python 2.7.2, opencv 2.4.1)

like image 65
pcampr Avatar answered Sep 22 '22 05:09

pcampr