- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试检测图像中的 Blob ,但不知何故它不起作用。基本上我想确定圆圈的数量。
代码:
import cv2
import numpy as np
import sys
# Read image
im = cv2.imread("K.jpg", cv2.IMREAD_GRAYSCALE)
# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()
# Change thresholds
params.minThreshold = 10
params.maxThreshold = 200
# Filter by Area.
params.filterByArea = True
params.minArea = 50
# Filter by Circularity
params.filterByCircularity = True
params.minCircularity = 0.75
# Filter by Convexity
params.filterByConvexity = True
params.minConvexity = 0.87
# Filter by Inertia
params.filterByInertia = True
params.minInertiaRatio = 0.7
detector = cv2.SimpleBlobDetector_create(params)
# Detect blobs.
keypoints = detector.detect(im)
print len(keypoints)
# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures
# the size of the circle corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0, 0, 255),
cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
# Show blobs
cv2.imshow("Keypoints", im_with_keypoints)
if cv2.waitKey(0) and 0xff==27:
cv2.destroyAllWindows()
这是输入图像:
最佳答案
我已经找到解决办法了。
当涉及到 Blob 检测时;您正在识别图像中的异常值/不需要的对象。因此,这些所谓的 Blob /异常值被假定为在普通背景上呈黑色/灰色。换句话说, Blob 被认为在白色背景下很容易识别。
当您对原始图像的灰度图像执行 Blob 检测时,出现的背景为黑色,如下所示:
在黑色背景下 Blob 检测什么也没发现:(
这就是我所做的。这只是黑客的一行。我模糊了灰度图像,然后使用 inverted_img = cv2.bitwise_not(blur)
然后我将获得的图像传递给 Blob 检测函数。这就是我得到的:
我还可以获得存在的 Blob 数量:
number = 0
for i in keypoints[0:]:
number = number + 1
print "Number of blobs:",number
这就是我在控制台屏幕上看到的内容:
关于python - Blob 检测不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42410390/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!