繁体   English   中英

如何避免错误的亮点检测?

[英]how to avoid false bright spot detection?

这是我的代码,通过使用这个代码亮点完美检测,如图所示。但是,问题是即使现场没有输入图像描述在这里它将检测图像中的错误点可以任何帮助我如何摆脱这个???

 # import the necessary packages import numpy as np import argparse import cv2 # construct the argument parse and parse the arguments ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", help = "Desktop") ap.add_argument("-r", "--radius", type = int, help = "radius of Gaussian blur; must be odd") args = vars(ap.parse_args()) # load the image and convert it to grayscale image1 = cv2.imread("h.png") orig = image1.copy() gray = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY) gray = cv2.GaussianBlur(gray, (args["radius"], args["radius"]), 0) (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray) image1 = orig.copy() cv2.circle(image1, maxLoc, args["radius"], (255, 0, 0), 2) # display the results of our newly improved method cv2.imwrite("myImage.png", image1) [1]: https://i.stack.imgur.com/6CDYP.png 

在此输入图像描述

这是因为当你调用cv2.minMaxLoc(gray) ,它会返回给定矩阵中的最大值和最小值,以及它们的位置,现在你必须根据需要小心并确定maxValue的阈值。 上面的方法总是返回一个maxValue,它可以是1,10或255并不重要,所以对于给定的Mat,它将成功找到最亮像素的位置和强度,而不管给定像素实际上是否为亮按照你的期望。 对于所需的行为,您需要将阈值设置为:

BRIGHT_PIX_THRESH = 220
if (maxVal > BRIGHT_PIX_THRESH):
    cv2.circle(image1, maxLoc, 10, (255, 0, 0), 2)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM