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
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.
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.
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.
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With