Ask Your Question
0

Midpoint on my line is wrong

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

NirvanaDon gravatar image

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

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'])

cv2.circle(ske,(centroid_x,centroid_y), 5, (127,0,0), -1)

image description

edit retag flag offensive close merge delete

Comments

why do you think, this is the wrong result ?

berak gravatar imageberak ( 2018-01-02 02:36:53 -0600 )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 -0600 )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 -0600 )edit

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

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

1 answer

Sort by ยป oldest newest most voted
0

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

supra56 gravatar image

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

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

Comments

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 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 624 times

Last updated: Jan 02 '18