error: (-5:Bad argument) image is empty or has incorrect depth (!=CV_8U) in function ‘cv::SIFT_Impl:

运行OpenCV的SIFT算法,在运行代码keypoints, describe = sift.detectAndCompute(image, None)后出现以下错误信息:

cv2.error: OpenCV(4.7.0) D:\a\opencv-python\opencv-python\opencv\modules\features2d\src\sift.dispatch.cpp:495: error: (-5:Bad argument) image is empty or has incorrect depth (!=CV_8U) in function 'cv::SIFT_Impl::detectAndCompute'

错误原因:

sift的函数sift.detectAndCompute()函数要求输入图像必须由值为0-255的8位整数定义,这意味着它必须是CV_8U深度。

所以在对图像使用sift之前,请使用以下内容将其转换为8位
image = cv2.normalize(generate_img,None,0,255,cv2.NORM_MINMAX).astype(‘uint8’)

猜你喜欢

转载自blog.csdn.net/qq_45100200/article/details/131233064