作为我正在研究的项目的一部分,我需要使用OpenCV和Python在图像中找到一些"blob"的中心点.我遇到了一些麻烦,真的很感激任何帮助或见解:)
我目前的方法是:获取图像的轮廓,在那些上叠加椭圆,使用斑点检测器找到每个图像的中心.这种效果相当不错,但偶尔我还需要忽略无关的斑点,有时斑点会相互碰触.
以下是一个很好的例子:
良好的源图像:
提取轮廓后:
检测到斑点:

当它变得很糟糕时(你可以看到它错误地将椭圆覆盖在三个blob上,并检测到一个我不想要的):
错误的源图像:
提取轮廓后:
检测到斑点:

这是我目前使用的代码.我不确定任何其他选择.
def process_and_detect(img_path):
img = cv2.imread(path)
imgray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 50, 150, 0)
im2, contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
drawn_img = np.zeros(img.shape, np.uint8)
min_area = 50
min_ellipses = []
for cnt in contours:
if cv2.contourArea(cnt) >= min_area:
ellipse = cv2.fitEllipse(cnt)
cv2.ellipse(drawn_img,ellipse,(0,255,0),-1)
plot_img(drawn_img, size=12)
# Change thresholds
params = cv2.SimpleBlobDetector_Params()
params.filterByColor = True
params.blobColor = 255
params.filterByCircularity = True
params.minCircularity = 0.75
params.filterByArea = True
params.minArea …Run Code Online (Sandbox Code Playgroud) 我建立摘要操作并将其添加到集合中,然后sess.run在培训/验证期间始终将摘要集合作为调用的一部分进行评估。
但是,在某些情况下,值是nan,这会使Tensorboard图变坏。(用三角形代替数据点,并且平滑度不适用于介于两者之间的nan值)。
有没有一种方法可以根据值的有效性从集合中省略特定的摘要?我可以将nan值替换为零或类似值,但是任何人为选择的值都会污染报告的真实统计信息。
我添加如下摘要:
tf.summary.scalar('scc_precision_test', precision_test, [Constants.TEST_SUMMARIES])
谢谢!