Draw the original image features through binary image features

#对原图进行二值化特征描绘
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)

Let’s make a brief summary of the issue of feature drawing of original images using binary image features trained by the model. It is mainly a problem of binary image conversion. Some requirements are to perform feature analysis on the original image, which requires understanding or using the feature functions. Only part of the above code is available

Guess you like

Origin blog.csdn.net/Steven_yang_1/article/details/132477047