我收到错误,OpenCV2将图像转换为灰度&找到边缘但得到这个错误
导入cv2导入numpy为np
img = cv2.imread(r“F:\ Python_Folder \ lena.jpg”)
您必须将图像转换回uint8。检查以下编辑的代码段:
import cv2 import numpy as np img = cv2.imread("F:\Python_Folder\lena.jpg") # img = cv2.imread(r"F:\Python_Folder\lena.jpg",0) also tried this grey_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) laplacian = cv2.Laplacian(grey_img, cv2.CV_64F) # convert back to uint8 laplacian = cv2.convertScaleAbs(laplacian) cv2.imshow("Laplacian image",laplacian) cv2.waitKey(0) cv2.destroyAllWindows()