Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于OpenCV的原始图像标记斑点检测_Python_Opencv_Image Processing_Opencv Python_Opencv Contour - Fatal编程技术网

Python 基于OpenCV的原始图像标记斑点检测

Python 基于OpenCV的原始图像标记斑点检测,python,opencv,image-processing,opencv-python,opencv-contour,Python,Opencv,Image Processing,Opencv Python,Opencv Contour,我想用找到的斑点标记原始图像。但每当我进行水滴检测时,它只会生成一个新图像,如下所示: blob后的结果图像: 但是,我想显示带有红色标签的原始图像。原始图像: 我只是使用常规代码进行斑点检测。有没有其他方法可以在原始图像上画红色圆圈?所以很清楚他们在哪里 im_gray = cv2.imread(img,cv2.IMREAD_GRAYSCALE) (thresh, im_bw) = cv2.threshold(im_gray, 128, 255,cv2.THRESH_BINARY | c

我想用找到的斑点标记原始图像。但每当我进行水滴检测时,它只会生成一个新图像,如下所示:

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)

您的问题是您的最后一行:

im_with_keypoints = cv2.drawKeypoints(im_bw, keypoints, numpy.array([]), (0, 0, 255),
                                      cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

在这里,您可以在
im_bw
上绘制关键点,这不是原始图像,而是阈值图像。如果您用原始图像替换此处的
im\u bw
(例如,使用您已加载为
im\u gray
)的灰度版本),您应该会得到所需的结果。

问题尚不清楚。是否要在原始BGR图像上绘制红色圆圈?欢迎使用堆栈溢出。请阅读帮助中心()中的信息指南,特别是“如何提出一个好问题”和“如何创建一个最小的、可复制的示例”。您是如何创建标记的?请显示代码。我添加了代码。是的,我想在原始BGR图像上画红色圆圈。你在非原始图像上画红色圆圈有困难吗?谢谢!这解决了我的问题