如下图,我本来想用cv.threshold来计算,给深色部分涂上别的颜色,但是这个简单划分的效果不好。
import cv2
img_path = "xxxx.jpg"
#读取文件
mat_img = cv2.imread(img_path)
mat_img2 = cv2.imread(img_path,cv2.CV_8UC1)
#自适应分割
dst = cv2.adaptiveThreshold(mat_img2,210,cv2.BORDER_REPLICATE,cv2.THRESH_BINARY_INV,3,10)
#提取轮廓
img,contours,heridency = cv2.findContours(dst,cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
#标记轮廓
cv2.drawContours(mat_img,contours,-1,(255,0,255),3)
#计算轮廓面积
area = 0
for i in contours:
area += cv2.contourArea(i)
print(area)
#图像show
cv2.imshow("window1",mat_img)
cv2.waitKey(0)
题主,这个有实例,你可以直接用https://blog.csdn.net/qq_41427568/article/details/100897746
傅里叶变换区分一下深色和浅色部分