运行cv2.getRectSubPix(img, (5,5), (0,0))
会抛出错误:
OpenCV Error: Unsupported format or combination of formats (Unsupported combination of input and output formats) in getRectSubPix.
img
的dtype
是float64,这是用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')