opencv形状目标检测

1.圆形检测

OpenCV图像处理中“找圆技术”的使用-图像处理-双翌视觉OpenCV图像处理中“找圆技术”的使用,图像处理,双翌视觉icon-default.png?t=N7T8https://www.shuangyi-tech.com/news_224.htmlopencv 找圆心得,模板匹配比霍夫圆心好用 - 知乎1 相比较霍夫找直线算法, 霍夫找圆心算法极其复杂 现在还没弄懂,等弄懂了来补充算法过程 2 记录霍夫找直线的算法过程: 对于图上任意一点, 所有经过这个点的函数可以表示为: x0 cosO + y0sinO = p 其中, p 为…icon-default.png?t=N7T8https://zhuanlan.zhihu.com/p/370227157python Blob检测圆点_blob分析 python_天人合一peng的博客-CSDN博客opencvhttps://blog.csdn.net/moonlightpeng/article/details/125561035https://www.cnblogs.com/bjxqmy/p/12333022.htmlicon-default.png?t=N7T8https://www.cnblogs.com/bjxqmy/p/12333022.html教你用OpenCV 和 Python实现圆物检测_opencv检测物体半径的代码_码农的后花园的博客-CSDN博客点击上方“码农的后花园”,选择“星标”公众号精选文章,第一时间送达基于python使用OpenCV实现在一张图片中检测出圆形,并且根据圆检测结果信息,绘制 标记出圆的边界和圆心。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

二值化方法

1. 拿到边框之后没法处理

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.二值化

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.检测图像块

利用OpenCV检测图像块_卓晴的博客-CSDN博客本文摘录自 Blob Detection Using OpenCV ( Python, C++ ) 关于图像块的检测方法的总结,用于之后的学习和工程应用。#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

你可能感兴趣的:(函数用法,计算机视觉,python,人工智能)