简体   繁体   English

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

[英]how to avoid false bright spot detection?

This is the code i have and by using this code bright spots are perfectly detected as shown in image.But,the problem is even though the spot is not there enter image description here it will detect false spot in the image can any help me how to get rid of this??? 这是我的代码,通过使用这个代码亮点完美检测,如图所示。但是,问题是即使现场没有输入图像描述在这里它将检测图像中的错误点可以任何帮助我如何摆脱这个???

 # 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 

enter image description here 在此输入图像描述

This is because when you call cv2.minMaxLoc(gray) , it would return the maximum and minimum value in the given matrix, along with their location, now you have to take care and threshold that maxValue as per your needs. 这是因为当你调用cv2.minMaxLoc(gray) ,它会返回给定矩阵中的最大值和最小值,以及它们的位置,现在你必须根据需要小心并确定maxValue的阈值。 The above method would always return a maxValue, it can be 1, 10, or 255 doesn't matters, so for a given Mat it would successfully find the location and intensity of brightest pixels irrespective of the fact that given pixel is actually bright as per your expectations. 上面的方法总是返回一个maxValue,它可以是1,10或255并不重要,所以对于给定的Mat,它将成功找到最亮像素的位置和强度,而不管给定像素实际上是否为亮按照你的期望。 For the desired behaviour you need to set a threshold as: 对于所需的行为,您需要将阈值设置为:

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