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

2024-05-13 19:34:08 发布

您现在位置:Python中文网/ 问答频道 /正文

运行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的数据类型是float64,它是通过运行

print(img.dtype).

Tags: orandofformatimginputoutput错误
2条回答

或者可以使用.astype()

img.astype('int8')

通过查看源代码可以看出,getrectsubix的输入组合只有:

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)

相关问题 更多 >