opencv shape object detection

1. Circle detection

The use of "circle-finding technology" in OpenCV image processing - Image processing - Shuangyi Vision The use of "circle-finding technology" in OpenCV image processing, image processing, Shuangyi Vision icon-default.png?t=N7T8https://www.shuangyi-tech.com/news_224. html opencv circle finding experience, template matching is easier to use than Hough circle center - Zhihu 1 Compared with Hough's straight line finding algorithm, Hough's circle center finding algorithm is extremely complicated and I haven't understood it yet. I will supplement the algorithm process when I understand it 2 Record Huo The algorithm process of finding a straight line: For any point on the graph, all functions passing through this point can be expressed as: x0 cosO + y0sinO = p where, p is... https://zhuanlan.zhihu.com/p/370227157 python icon-default.png?t=N7T8Blob detection Dot_blob analysis python_heaven and man peng's blog-CSDN blog opencv https://blog.csdn.net/moonlightpeng/article/details/125561035 https://www.cnblogs.com/bjxqmy/p/12333022 .html icon-default.png?t=N7T8https://www.cnblogs.com/bjxqmy/p/12333022.html Teach you to use OpenCV and Python to implement round object detection_opencv code to detect the radius of an object_The coder's back garden blog-CSDN blog click above " "Coder's Back Garden", select the "Star" public account to select articles, and have them delivered as soon as possible. Based on Python, OpenCV is used to detect circles in a picture, and based on the circle detection result information, draw the marked circle. Boundary and center of circle. 1 Ho...https://blog.csdn.net/weixin_45192980/article/details/119814390?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-3-119814390-blog-103874538.235%5Ev27%5Epc_relevant_3mothn_strategy_recovery&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-3-119814390-blog-103874538.235%5Ev27%5Epc_relevant_3mothn_strategy_recovery&utm_relevant_index=4

Binarization method

1. There is no way to deal with the border after getting it

from imutils import auto_canny, contours

# 【1】读入图片+预处理
image = cv2.imread('./data/ac1_bar_rotated.png')# 加载图片

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 转灰度
blurred = cv2.GaussianBlur(gray, (5, 5), 0)# 高斯模糊
edged = auto_canny(blurred) # 边缘检测

fig = plt.figure(figsize=(20, 30))
plt.imshow(edged, cmap ='gray')
plt.title(u"边缘检测后的图片")
plt.axis('off')

# 检测图片中的最外围轮廓
cnts,_ = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
print("原始图片检测的轮廓总数:", len(cnts))

# 定义黑色背景幕布
black_background = np.ones(image.shape, np.uint8)*0
# 将检测到的轮廓添加幕布上进行展示
cv2.drawContours(black_background, cnts, -1, (3,240,240), 2)

fig = plt.figure(figsize=(20, 30))
plt.imshow(black_background)
plt.title(u"原始图片检测到的所有最外围轮廓")
plt.axis('off')

2. Binarization

from imutils import auto_canny, contours

# 【1】读入图片+预处理
image = cv2.imread('./data/ac1_bar_circle_rotated.png')# 加载图片
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)# 转灰度
# OTSU二值化
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]

fig = plt.figure(figsize=(15, 20))
plt.imshow(thresh, cmap ='gray')
plt.axis('off')
numpy_img = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 15)   # 自动阈值二值化

fig = plt.figure(figsize=(15, 20))
plt.imshow(thresh, cmap ='gray')
plt.axis('off')
img = cv2.imread('./data/ac1_bar_circle_rotated.png')# 加载图片
gray_src= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
minThreshValue = 35
_, gray = cv2.threshold(gray_src, minThreshValue, 255, cv2.THRESH_BINARY)
gray = cv2.resize(gray, dsize=None, fx=1, fy=1, interpolation=cv2.INTER_LINEAR)

fig = plt.figure(figsize=(15, 20))
plt.imshow(gray, cmap ='gray')
plt.axis('off')

kernel = np.ones((3, 3), dtype=np.uint8)
gray = cv2.dilate(gray, kernel, 1)  # 1:迭代次数,也就是执行几次膨胀操作
gray = cv2.erode(gray, kernel, 1)

fig = plt.figure(figsize=(15, 20))
plt.imshow(gray, cmap ='gray')
plt.axis('off')

2. Detect image blocks

Using OpenCV to detect image blocks_Zhuo Qing's blog-CSDN blog This article is excerpted from Blob Detection Using OpenCV (Python, C++), a summary of the detection method of image blocks, for subsequent learning and engineering applications. #mermaid-svg-rdgqMuicdO2HmUtV .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid- svg-rdgqMuicdO2HmUtV .labe.. https://blog.csdn.net/zhuoqingjoking97298/article/details/122761250

Guess you like

Origin blog.csdn.net/u012193416/article/details/129817542