【发布时间】:2021-08-15 04:04:34
【问题描述】:
我想用找到的 blob 标记原始图像。但是每当我进行斑点检测时,它只会制作一个像这样的新图像:
blob 之后的结果图片:
但是,我想显示带有红色标记的原始图像。原图:
我只是使用常规代码进行斑点检测。还有另一种方法可以在原始图像上做红色圆圈吗?所以很清楚他们在哪里。
im_gray = cv2.imread(img,cv2.IMREAD_GRAYSCALE)
(thresh, im_bw) = cv2.threshold(im_gray, 128, 255,cv2.THRESH_BINARY |
cv2.THRESH_OTSU)
thresh = 50
im_bw = cv2.threshold(im_gray, thresh, 255, cv2.THRESH_BINARY)[1]
#detect blobs based on features
params = cv2.SimpleBlobDetector_Params()
# Filter by Area.
params.filterByArea = True
params.minArea = 70
params.maxArea = 150
# Filter by Color (black=0)
params.filterByColor = False # Set true for cast_iron as we'll be detecting black regions
params.blobColor = 0
# Filter by Circularity
params.filterByCircularity = True
params.minCircularity = 0.5
params.maxCircularity = 1
# Filter by Convexity
params.filterByConvexity = True
params.minConvexity = 0.5
params.maxConvexity = 1
# Filter by InertiaRatio
params.filterByInertia = True
params.minInertiaRatio = 0.3
params.maxInertiaRatio = 0.9
# Distance Between Blobs
params.minDistBetweenBlobs = 0
#thresholded to value 70 detecting blobs:
detector = cv2.SimpleBlobDetector_create(params)
keypoints = detector.detect(im_bw)
print("Number of blobs detected are : ", len(keypoints))
#detect blobs: missing the detection based on features
im_with_keypoints = cv2.drawKeypoints(im_bw, keypoints, numpy.array([]), (0, 0, 255),
cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
【问题讨论】:
-
问题不清楚。是否要在原始 BGR 图像上绘制红色圆圈?
-
欢迎来到 Stack Overflow。请阅读帮助中心 (stackoverflow.com/help) 中的信息指南,特别是“如何提出一个好问题”(stackoverflow.com/help/how-to-ask) 和“如何创建最小的、可重现的示例”( stackoverflow.com/help/minimal-reproducible-example).
-
您是如何创建标签的?请出示代码。
-
我添加了代码。是的,我想在原始 BGR 图像上画红色圆圈
-
您是否在非原始图像上出现红圈问题?
标签: python opencv image-processing opencv-python opencv-contour