Ask Your Question

Midpoint on my line is wrong

asked 2018-01-01 20:40:12 -0500

NirvanaDon gravatar image

updated 2018-01-02 02:34:51 -0500

berak gravatar image

Hey guys, i'm trying to get the midpoint of my line using this code but it seems wrong. Can anyone advice me please?

M = cv2.moments(ske)

centroid_x = int(M['m10']/M['m00'])

centroid_y = int(M['m01']/M['m00']),(centroid_x,centroid_y), 5, (127,0,0), -1)

image description

edit retag flag offensive close merge delete


why do you think, this is the wrong result ?

berak gravatar imageberak ( 2018-01-02 02:36:53 -0500 )edit

hey, i tried reducing the circle to radius 1 but it shows that my midpoint is above the white pixel line

NirvanaDon gravatar imageNirvanaDon ( 2018-01-02 06:54:50 -0500 )edit

the center of mass of a line (that's what you calculate) is not nessecarily on the line (think of an U or an O)

(mass center != midpoint)

berak gravatar imageberak ( 2018-01-02 07:13:23 -0500 )edit

Is there another way i can find midpoint of the line? please advice

NirvanaDon gravatar imageNirvanaDon ( 2018-01-02 07:49:39 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-01-02 20:24:50 -0500

supra56 gravatar image

updated 2018-01-02 20:25:32 -0500

Here is link that may solve your problem.You may have to convert from python to c++. So here is link:midpoint of my line

edit flag offensive delete link more


i tried to use trackgoodfeature like the guy did. but there are many corners in my white pixel image because of the gap

NirvanaDon gravatar imageNirvanaDon ( 2018-01-03 00:34:20 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-01-01 20:40:12 -0500

Seen: 233 times

Last updated: Jan 02 '18