how to calculate distances between pixels on a contour

asked 2018-07-10 07:13:03 -0500

sadegh6383 gravatar image

updated 2018-07-10 07:56:30 -0500

Hello, I have a contour in OPENCV C++ in the contour format, and I want to measure the distance between each two pixels on the contour ( the number of pixels on the contour between them). It is clear that there are two distances between every two points on a closed contour. I need a clear algorithm or a code to measure these two distances in pixel. Bests,

image description

edit retag flag offensive close merge delete


what do you mean with "It is clear that there are two distances " ?

berak gravatar imageberak ( 2018-07-10 07:45:46 -0500 )edit

I added the picture.

sadegh6383 gravatar imagesadegh6383 ( 2018-07-10 07:57:14 -0500 )edit

The points are given in a vector which has indices, right? Why not just do a difference on the indices in both directions and take the minimum value?

Der Luftmensch gravatar imageDer Luftmensch ( 2018-07-10 08:31:22 -0500 )edit

if you use CHAIN_APPROX_NONE, the contours are a "dense" array (no holes between the points).

so just counting how many there are between A and B would give you the L1 (or manhattan) distance.

would that be accurate enough for you ?

berak gravatar imageberak ( 2018-07-10 08:41:45 -0500 )edit

Yes Thank you and the rest of the chain will give L2.

sadegh6383 gravatar imagesadegh6383 ( 2018-07-10 08:48:27 -0500 )edit

@sadegh6383 -- Please add the code if you work it out. :)

sjhalayka gravatar imagesjhalayka ( 2018-07-10 11:05:40 -0500 )edit