Raquel
Raquel

Reputation: 165

Why does cv2.medianBlur returns a format error?

I am trying to use the cv2.medianBlur on an image but it does not work unless I import the image using the cv2.read. As I don't want to change the rest of my code can anyone explain to me why this happens or any other method to accomplish the same result?

def medianFilterData(data, w):
    fdata = []
    for i in range(0, len(data)):
        img = data[i].astype('d')
        median = cv2.medianBlur(img, w)
        fdata.append(median)
    return fdata

The error:

cv2.error: OpenCV(4.5.1) C:/Users/appveyor/AppData/Local/Temp/1/pip-req-build-kh7iq4w7/opencv/modules/imgproc/src/median_blur.simd.hpp:975: error: (-210:Unsupported format or combination of formats)  in function 'cv::opt_AVX2::medianBlur'

The first image is: enter image description here

Upvotes: 4

Views: 4402

Answers (1)

imdevskp
imdevskp

Reputation: 2233

try .astype('int8') or .astype('float32')

def medianFilterData(data, w):
    fdata = []
    for i in range(0, len(data)):
        img = data[i].astype('int8')
        median = cv2.medianBlur(img, w)
        fdata.append(median)
    return fdata

Upvotes: 4

Related Questions