简体   繁体   中英

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. 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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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