Ask Your Question
0

finding the brightest area

asked 2019-01-10 03:05:13 -0600

I have a photo that has areas with high brightness.

image description

applying different algorithms i made white the brightest points and black the rest points

then i need to determine the center of the bright white surface

image description

i do in next way

img = cv2.imread("frame1.jpg") #read

hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # convert

h, s, v = cv2.split(hsv) # split to h s v

limit = v.max () # get max bright in V

hsv_min = np.array((0, 0, limit), np.uint8) # put min and max

hsv_max = np.array((255, 255, limit), np.uint8)

img = cv2.inRange(hsv, hsv_min, hsv_max) # brightness filter

moments = cv2.moments(img, 1) # get moments

x_moment = moments['m01']

y_moment = moments['m10']

area = moments['m00']

x = int(x_moment / area) # x

y = int(y_moment / area) # y

cv2.putText(img, "center_brightness_surface!", (x,y), cv2.FONT_HERSHEY_SIMPLEX, 1, (100,100,100), 2)

cv2.imshow('frame_out', img)

cv2.imwrite("frame_out.jpg" , img)

cv2.waitKey (0)

cv2.destroyAllWindows ()

it is working but x and y not on surface. x y which i got far away from real center of brightness surface

please tell me how can i get center of brightness surface

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-01-12 10:48:54 -0600

supra56 gravatar image

updated 2019-01-12 10:55:26 -0600

Here is code:

#!/usr/bin/ env python3
#openCV 4.0

import cv2 as cv
import numpy as np

img = cv.imread("brightest.jpg") #read
hsv = cv.cvtColor(img, cv.COLOR_BGR2HSV) # convert
h, s, v = cv.split(hsv) # split to h s v
limit = v.max () # get max bright in V

hsv_min = np.array((0, 0, limit), np.uint8) # put min and max
hsv_max = np.array((225, 225, limit), np.uint8)

img1 = cv.inRange(hsv, hsv_min, hsv_max) # brightness filter

moments = cv.moments(img1, 1) # get moments

x_moment = moments['m01']
y_moment = moments['m00']

area = moments['m00']

x = int(x_moment / area) # x
y = int(y_moment / area) # y

cv.putText(img1, "center_brightness_surface!", (x,y+220), cv.FONT_HERSHEY_SIMPLEX,1, (255,255,0),2)
cv.imwrite("frame_out.jpg" , img1)
cv.imshow('Brightest', img)
cv.imshow('frame_out', img1)

cv.waitKey (0)
cv.destroyAllWindows ()

Here is output: C:\fakepath\frame_out.jpg

edit flag offensive delete link more

Comments

supra: put a ! in front of the [](link_to_image) to make it visible immediately ;)

berak gravatar imageberak ( 2019-01-12 10:52:45 -0600 )edit

Thanks, berak.

supra56 gravatar imagesupra56 ( 2019-01-12 10:57:54 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2019-01-10 03:05:13 -0600

Seen: 2,474 times

Last updated: Jan 12 '19