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?