通过二值图特征对原图像特征绘制

#对原图进行二值化特征描绘
import cv2
import numpy as np
kernel = np.ones((1, 5), np.uint8)
#原图读取
img = cv2.imread(r"C:\Users\Administrator\Desktop\pic\dianta.tif")
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, binary = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
binary = cv2.morphologyEx(binary, cv2.MORPH_CLOSE, kernel, anchor=(2, 0), iterations=5)
#二值图读取
mask = cv2.imread(r"C:\Users\Administrator\Desktop\dianta.tif", cv2.IMREAD_GRAYSCALE)
contours, hierarchy = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
#原图进行特征绘制
cv2.drawContours(img, contours, -1, (0, 0, 255), 2)
output_path = r"./2.tif"  # 替换为你要保存的路径和文件名
cv2.imwrite(output_path, img)

对关于模型训练出来的二值图特征对原始图进行特征绘制问题做一个小总结。主要是二值图转化的问题。有些需求是对原图进行特征分析,则需要对特征的函数进行理解或者使用。上述代码只有一部分可用

猜你喜欢

转载自blog.csdn.net/Steven_yang_1/article/details/132477047
今日推荐