python - Finding the brightest spot in an image -


so trying find brightest spot in image , coordinates. found prewritten code doesn't work propoerly, wondering if can give me solution (i not advanced in programming) . using video of tracked object not photo.

this code trying use:

# import necessary packages import simplecv import numpy np import argparse import cv2   display = simplecv.display() cam = simplecv.camera() img = cv2.imread(args["image"]).fliphorizontal().togray()  # construct argument parse , parse arguments ap = argparse.argumentparser() ap.add_argument("-i", "--image", = "path image file") ap.add_argument("-r", "--radius", type = int,      = "radius of gaussian blur; must odd") args = vars(ap.parse_args())  # perform naive attempt find (x, y) coordinates of # area of image largest intensity value (minval, maxval, minloc, maxloc) = cv2.minmaxloc(gray) cv2.circle(image, maxloc, 5, (255, 0, 0), 2)  # display results of naive attempt cv2.imshow("naive", image)  # apply gaussian blur image find brightest # region gray = cv2.gaussianblur(gray, (args["radius"], args["radius"]), 0) (minval, maxval, minloc, maxloc) = cv2.minmaxloc(gray) image = orig.copy() cv2.circle(image, maxloc, args["radius"], (255, 0, 0), 2)  # display results of our newly improved method cv2.imshow("robust", image) cv2.waitkey(0) 

but error getting if trying run is:

nameerror: name 'args' not defined 

this original code uses photos:

# import necessary packages import numpy np import argparse import cv2   # construct argument parse , parse arguments  ap = argparse.argumentparser()  ap.add_argument("-i", "--image", = "path image file")  ap.add_argument("-r", "--radius", type = int,     = "radius of gaussian blur; must odd")  args = vars(ap.parse_args())   # load image , convert grayscale  image = cv2.imread(args["image"])  orig = image.copy()  gray = cv2.cvtcolor(image, cv2.color_bgr2gray)   # perform naive attempt find (x, y) coordinates of  # area of image largest intensity value  (minval, maxval, minloc, maxloc) = cv2.minmaxloc(gray)  cv2.circle(image, maxloc, 5, (255, 0, 0), 2)   # display results of naive attempt  cv2.imshow("naive", image)  # apply gaussian blur image find brightest # region gray = cv2.gaussianblur(gray, (args["radius"], args["radius"]), 0) (minval, maxval, minloc, maxloc) = cv2.minmaxloc(gray) image = orig.copy() cv2.circle(image, maxloc, args["radius"], (255, 0, 0), 2)  # display results of our newly improved method cv2.imshow("robust", image) cv2.waitkey(0) 


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -