Ask Your Question
0

Find Centroid Coordinate of whole frame in OpenCV

asked 2018-10-28 03:34:53 -0600

AbhiTronix gravatar image

Hello everyone, I'm searching on the internet for an optimum code to find the Centroid's XY-Coordinates of OpenCV Frame, but failed to do so.

I know how to find the centroid/center of a contour, as below(in python):

image = cv2.imread("test.png"])
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blurred = cv2.GaussianBlur(gray, (5, 5), 0)
thresh = cv2.threshold(blurred, 60, 255, cv2.THRESH_BINARY)[1]


# find contours in the thresholded image
cnts = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] 
#print cnts

# loop over the contours
for c in cnts:
    # compute the center of the contour
    M = cv2.moments(c)
    cX = int(M["m10"] / M["m00"])
    cY = int(M["m01"] / M["m00"])

Where CX, CY is the required XY-coordinates but how to find that for whole video-frame/image in OpenCV, Please anyone can help me for the same?

edit retag flag offensive close merge delete

Comments

1

it might simply not be possible (like this). why do you think, you need that ? what is the context of it ?

berak gravatar imageberak ( 2018-10-28 03:55:12 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-10-28 04:22:27 -0600

AbhiTronix gravatar image

updated 2018-10-28 04:30:06 -0600

berak gravatar image

Here is the straightforward yet simple answer to my question,

(h, w) = image.shape[:2]
cv2.circle(image, (w//2, h//2), 7, (255, 255, 255), -1) #where w//2, h//2 are the required frame/image centeroid's XYcoordinates.

I was just not thinking out of the box previously, Cheers :)

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-10-28 03:34:53 -0600

Seen: 6,424 times

Last updated: Oct 28 '18