Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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

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: output:

C:\fakepath\frame_out.jpg

click to hide/show revision 3
No.3 Revision

updated 2019-01-12 10:51:41 -0600

berak gravatar image

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.jpgC:\fakepath\frame_out.jpg

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:output: C:\fakepath\frame_out.jpg

C:\fakepath\frame_out.jpg

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.jpgC:\fakepath\frame_out.jpg