'OpenCV(4.2.0) (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'

i am trying to inpaint on a 8000x4000 image, and a 8000x4000 binary mask but getting the following error.

error Traceback (most recent call last) in 1 img = cv.imread('input/200130_033344133.jpg') 2 mask = cv.imread('resources/maskX.png',0) ----> 3 dst = cv.inpaint(img,mask,3,cv.INPAINT_TELEA) 4 cv.imshow('dst',dst) 5 cv.waitKey(0)

error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\core\src\array.cpp:2492: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'

here is my code. what i tried was to convert the image and the mask to numpy array or cv2.UMat. but all in vain

img = cv.imread('input/200130_033344133.jpg')
mask = cv.imread('resources/maskX.png',0)
dst = cv.inpaint(img,mask,3,cv.INPAINT_TELEA)
cv.imshow('dst',dst)
cv.waitKey(0)
cv.destroyAllWindows()

any reason why its not working? the images are loading properly i checked.



Solution 1:[1]

I do not know what is wrong, because it works fine for me on Python 3.7 and OpenCV 3.4 on Mac OSX.

Did you import cv? Is your mask more than 1 channel after making grayscale? Perhaps it is an issue with OpenCV 4?

Here is what works for me.

Image with scratch:

enter image description here

Scratch Mask:

enter image description here

import cv2

img = cv2.imread('zelda1_scratch.jpg')
mask = cv2.imread('zelda1_scratch_mask.png',0)
dst = cv2.inpaint(img,mask,3,cv2.INPAINT_TELEA)
cv2.imwrite('zelda1_scratch_inpainted.jpg', dst)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

Result:

enter image description here

Solution 2:[2]

I had the same error while trying to inpaint.

error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'

Then I realised I typed the mask format incorrectly instead of .jpg I wrote .png. So cv2.imread() was loading an empty matrix. When I fixed typo, error was gone.

So please check again your input image and mask name and formats.

I think this error is the sign of that image cannot loaded correctly.

Sincerely, Enes

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fmw42
Solution 2 enesdemirag