Multi page imwrite for Python [closed]
Hi there, I gladly saw that a feature allowing to save multi-page images was introduced about a year ago: https://github.com/opencv/opencv/pull...
However I don't see this working in Python:
>>> import cv2
>>> im = cv2.imread('/tmp/test.tif')
>>> im2 = cv2.imread('/tmp/thumb.tif')
>>> cv2.imwrite([im, im2], '/tmp/opencv_multi.tif')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: bad argument type for built-in operation
>>> help(cv2.imwrite)
imwrite(...)
imwrite(filename, img[, params]) -> retval
[...]
Is a Python port foreseen? Or am I just using the wrong syntax?
Thanks.
Edit: As pointed out in the comment, the above snippet gave me a different error because of the wrong signature. With the "correct" signature I still get a TypeError though:
>>> import cv2
>>> im = cv2.imread('/tmp/test.tif')
>>> im2 = cv2.imread('/tmp/thumb.tif')
>>> cv2.imwrite([im, im2], '/tmp/opencv_multi.tif')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Expected cv::UMat for argument 'img'
please try to read the original images as grayscale, single channel:
im = cv2.imread('/tmp/test.tif', cv2.IMREAD_GRAYSCALE)
, else they're forced into 3channel, bgr mode,then, you got filename and images in reverse ..., please look at the docs, again (you're even printing it out, still !!!)
My bad. I pasted the wrong line. See update, which gives the error I am talking about. The point is that I don't see anything in the help that indicates a list of images to be passed.
I don't understand your point about grayscale... my image is RGB, why do I need it to open it as grayscale?
sorry, ignore the grayscale, i probably misread it.
but a
vector<Mat>
is a 2d numpy array (with a single column) so it likely (i havent's tried !) goes like: