0

I have an image opened with Image.open(). I make some changes, reassigning pixel RGV values,and try to save.

When I try to save, I get:

Trace back (most recent call last):
  File "./shimmer", line 97, in <module>
    cv2.imwrite('/home/christos/portrait-out.jpg', result)
TypeError: Expected Pre<cv::UMat> for argument 'img'

This happens when the image has been created, baseline = Image.open('/home/christos/portrait-new-mini.jpg').

In searching I have found similar reported errors but no clear articulation of "Here’s what works and how’s why."

I have also seen pages in which similar work is done without similar recorded difficulties.

I can post my code if that is requested, but I am guessing that the problem is narrowly defined by the cv2.imwrite() call and something I want to be feeding the invocation.

Christos Hayward
  • 5,777
  • 17
  • 58
  • 113
  • cv2 has own method to read image - `cv2.imread()` - and it creates `numpy` array. `Pillow` keeps it in different format and you may have to convert it to `numpy` array before save it - as I remeber `cv2_img = numpy.array(pillow_image)` BTW: why to use `cv2` to save it if `pillow` can save it? – furas Mar 31 '20 at 17:52
  • BTW: `cv2` as default use `BGR` instead of `RGB` and you may have to convert it before save it. `img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)` – furas Mar 31 '20 at 17:57

1 Answers1

1

Seems that you open the Image in Pillow and try to save the Pillow Image with OpenCV. OpenCV expect a numpy array. You should first convert your image before write in file with opencv.

Check this post : https://stackoverflow.com/a/14140796/13103631

I think, it will solve your issue

Kylo_Entro
  • 46
  • 5