【问题标题】:how to avoid false bright spot detection?如何避免错误的亮点检测?
【发布时间】:2017-05-25 17:59:37
【问题描述】:

这是我拥有的代码,通过使用此代码,可以完美检测到亮点,如图所示。但是,问题是即使该点不存在enter image description here,它也会检测到图像中的错误点可以提供帮助我怎么摆脱这个???

# 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

【问题讨论】:

    标签: python-3.x opencv


    【解决方案1】:

    这是因为当您调用 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)
    

    【讨论】:

    • 即使我使用阈值假点检测到@ZdaR..我能做什么??
    • 这时你需要调整阈值,对于给定的灰度像素,最大值可以是255,你需要根据你的需要调整这个值,试着逐渐增加它,看看你得到的你真正想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 2019-12-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-29
    相关资源
    最近更新 更多