OpenCV 错误:getRectSubPix 中不支持的格式或格式组合(不支持的输入和输出格式组合)



运行cv2.getRectSubPix(img, (5,5), (0,0))会抛出错误:

OpenCV Error: Unsupported format or combination of formats (Unsupported combination of input and output formats) in getRectSubPix.

imgdtypefloat64,这是用img.dtype确定的。

查看源代码显示,getRectSubPix 的输入组合只有:

depth == CV_8U && ddepth == CV_8U
depth == CV_8U && ddepth == CV_32F
depth == CV_32F && ddepth == CV_32F

这意味着输入数组需要转换为 int8 或 float32 才能传入,这可以通过以下方法完成:

np.int8(img)

np.float32(img)

或者您可以使用.astype()

img.astype('int8')

最新更新