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

Python OpenCV错误:getRectSubPix中不支持的格式或格式组合(不支持的输入和输出格式组合),python,numpy,opencv,Python,Numpy,Opencv,运行cv2.GetRectSubpixemg,5,5,0,0会抛出错误: OpenCV Error: Unsupported format or combination of formats (Unsupported combination of input and output formats) in getRectSubPix. img的数据类型是float64,这是由img.dtype确定的。查看源代码显示,getRectSubPix的输入组合只有: depth == CV_8U &am

运行cv2.GetRectSubpixemg,5,5,0,0会抛出错误:

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

img的数据类型是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)

或者,您可以使用.astype:

np.float32(img)
img.astype('int8')