……
median = cv2.medianBlur(img_dif2, 5)
print(type(median),median.shape,median.dtype)
#cv2.imshow(“median-image”, median)
cv2.imwrite(‘img_geo_dif_median2.png’,median)
Grayimg = median
print(Grayimg.shape)
hist = cv2.equalizeHist(Grayimg)
#cv2.imshow(‘hist’,hist)
cv2.imwrite(‘img_geo_dif_hist2.png’,hist)
img3 = cv2.imread(“./img_geo_dif_hist2.png”,3)
print(img3[1,1,0].dtype)
报错:
(1024, 1024)
OpenCV(4.5.5) /io/opencv/modules/imgproc/src/histogram.cpp:3439: error: (-215:Assertion failed) _src.type() == CV_8UC1 in function ‘equalizeHist’
报错原因:直方图输入数据为uint16,而opencv要求数据格式为uint8.
般的图像文件格式使用的是 Unsigned 8bits吧,CvMat矩阵对应的参数类型就是
CV_8UC1,CV_8UC2,CV_8UC3。
(最后的1、2、3表示通道数,譬如RGB3通道就用CV_8UC3)
而float 是32位的,对应CvMat数据结构参数就是:CV_32FC1,CV_32FC2,CV_32FC3…
double是64bits,对应CvMat数据结构参数:CV_64FC1,CV_64FC2,CV_64FC3等。