Ask Your Question
0

Get length in pixels between edges of two contours

asked 2018-01-11 05:17:59 -0600

michlvl gravatar image

updated 2018-01-11 08:22:25 -0600

Hi.

I'm using OpenCV 3.3.1 on Windows 7.

I want to get length (in pixels) between two contours. Here are thresholded and original images (figure may rotated by different angles): image description

This is what I need to get:

image description image description image description

I can find centers of this figures:

image description

but I dont know how to find distance from center to edge...

Please give me advices.

UPDATE

Thanks @StevenPuttemans for idea, I tried to implement it, but during this time found one more important note that figure's position is changing and it may be rotated by random angle (sorry, I should note about it earlier):

image description image description image description

edit retag flag offensive close merge delete

Comments

supra56 gravatar imagesupra56 ( 2018-01-11 05:51:13 -0600 )edit

@supra56 please man, start by reading the question ... he needs a way of defining the outer pixel border, not the actual distance between two points ...

StevenPuttemans gravatar imageStevenPuttemans ( 2018-01-11 06:39:50 -0600 )edit

@StevenPuttemans.I will stop making comment from now on.

supra56 gravatar imagesupra56 ( 2018-01-11 07:46:10 -0600 )edit
2

@supra56 It's all good. Everyone makes mistakes, especially me.

sjhalayka gravatar imagesjhalayka ( 2018-01-11 20:11:10 -0600 )edit

Oh come on ... I did not say you can no longer post comments. Just lately you have been replying without any consideration of what is actually being asked for and thats what I wanted to get you to understand. That is all ... let us not overdramatize this.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-01-12 03:11:02 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-01-11 06:38:49 -0600

If your objects appear in a fixed position I would follow these steps

  1. Given both contours, check which one is right and which one is left, by looking at the x coordinate of center
  2. Now for the left contour, look at all the points of your contour (loop over them) and pic the x coordinate which is smallest on the x axis compared to center.
  3. Do the opposite for the second contour, looking for the largest x value, and thus the point most to the right
edit flag offensive delete link more

Comments

Thanks for idea, this may works in case contours are not rotaing. Unfortunatelly, my figure can have random angle of rotation, so in this case "lowest X coordinate" is not the most left edge of contour... (added this not in update)

michlvl gravatar imagemichlvl ( 2018-01-11 08:18:14 -0600 )edit

Will your object still be rectangular. Then you simply need to do edge detection, find the dominant edge direction and rotate your image to a horizontal position.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-01-11 08:35:41 -0600 )edit

May be you can use minArea for each shape

LBerger gravatar imageLBerger ( 2018-01-11 09:37:54 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-01-11 05:17:59 -0600

Seen: 87 times

Last updated: Jan 11