Ask Your Question

How can I read pixel coordinate of a point in image in OpenCV to calculate the distance between two points in Image?

asked 2017-02-16 22:43:40 -0600

astronaut gravatar image

I was wondering how would I read a coordinate pixel value of some points. I would like to have a program in OpenVC that read pixel coordinates of point1 from the output of OpenCV program1 and also point2 coming from OpenCV program2. To clarify, I already have two existing OpenCV programs that calculate a single point each. Then I need to calculate the distance between point1 and point2 with the knowing formula as we know the pixel coordinates (x1,y1) of point1 and (x2,y2) of point2. What format needs to be stored the point so I can easily access and read them and then calculate the distance. Any code example? its more about the format of the output of those two OpenCV existing program and the format of reading those points from OpenCV in a new OpenCV program

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-02-17 03:13:04 -0600

LBerger gravatar image

updated 2017-02-17 03:13:24 -0600

you can use norm function :

        Point p1(10,2),p2(20,3);
        cout << norm(p1-p2);
edit flag offensive delete link more


To add some extra explanation, basically you need to store your points somewhere as integers, then combine them into a Point object before you can calculate the norm, which is the euclidean distance between two points.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-02-17 03:21:02 -0600 )edit

Question Tools

1 follower


Asked: 2017-02-16 22:43:40 -0600

Seen: 354 times

Last updated: Feb 17 '17