Python, OpenCV Error, Unsupported combination of source format

Question:

I am trying to run this code:

import cv2
import numpy as np

src = np.array([[10, 20, 40, 50],
                 [50, 20, 50, 20],
                 [10, 10, 30, 60],
                 [20, 40, 60, 70]])

dst1 = cv2.blur(src, ksize=(3, 3), borderType = cv2.BORDER_CONSTANT)
print(dst1)
dst2 = cv2.GaussianBlur(src, ksize=(3, 3), sigmaX=0, borderType = cv2.BORDER_CONSTANT)

And I got an error:

 dst2 = cv2.GaussianBlur(src, ksize=(3, 3), sigmaX=0, borderType = cv2.BORDER_CONSTANT)
    cv2.error: OpenCV(4.5.5) /Users/runner/work/opencv-python/opencv-python/opencv/modules/imgproc/src/filter.simd.hpp:3045:  
    error: (-213:The function/feature is not implemented) 
    Unsupported combination of source format (=4), and buffer format (=5) in function 'getLinearRowFilter'
Asked By: Min

||

Answers:

if you construct an np.array like that, it’s (default) format is np.int32, which is not supported. rather make it:

src = np.array([[10, 20, 40, 50],
                [50, 20, 50, 20],
                [10, 10, 30, 60],
                [20, 40, 60, 70]], np.uint8) # <-- correct type !!!
Answered By: berak
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.