Ask Your Question
0

How do I measure for the width and height of the object (OpenCV)?

asked 2014-07-08 21:18:27 -0600

norzanbzura gravatar image

If I want to use this on my program, how do I implement it? I've no idea. Thank you for your attention.

w = sqrt( (p1.x-p0.x)*(p1.x-p0.x) + (p1.y-p0.y)*(p1.y-p0.y) );
h = sqrt( (p2.x-p1.x)*(p2.x-p1.x) + (p2.y-p1.y)*(p2.y-p1.y) );
edit retag flag offensive close merge delete

Comments

1

You have to be more specific, you know all of the parameters and you just want to know how to implement it? you want to know how to find thous parameters? both questions?

itay gravatar imageitay ( 2014-07-09 00:23:46 -0600 )edit

And what is your code doing? Calculating width and height from retrieved bounding box crosspoints?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-09 07:23:21 -0600 )edit

Yes Steven. I want to calculate the object width and height from the bounding box.

norzanbzura gravatar imagenorzanbzura ( 2014-08-19 18:49:18 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-08-20 03:03:28 -0600

Okay to provide a solution to your problem, starting from the following facts:

  1. Your top left corner is p0.
  2. Your bottom right corner is p1.
  3. Both points are made of the type cv::Point(x,y).

Which makes point 2 quite useless. If I am wrong here, then please provide explanation of what p0, p1 and p2 are.

Then the following code will work perfectly:

int width = p1.x - p0.x;
int height = p1.y - p0.h;

However your functions seem more complex and I am guessing you do not have a bounding box yet. SO like said before, could you give the code leading to those 3 points and explain what they are?

edit flag offensive delete link more

Comments

Actually after looking closer at your code, what you are doing is calculating the diagonal between two lines using the equation of pythagoras. Any reason for doing so?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-20 03:10:11 -0600 )edit
1

Actually I just make this code as my reference. But actually I want to do is to calculate the height and width of the object. That's it. By the way, thank you for helping me!

norzanbzura gravatar imagenorzanbzura ( 2014-08-20 10:09:43 -0600 )edit

That is no problem and you are welcome. I would like you to ask to accept the answer as the solution once you get the chance. This will make the topic show solved for future use.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-22 04:35:27 -0600 )edit

Is it original image height and width? my question is how to calculate original height and width of objects.

Sujith gravatar imageSujith ( 2016-02-26 00:58:43 -0600 )edit

No this is the width and heigth in pixels. You will need a calibrated setup in order to know the sizes in world dimensions, like millimeters.

StevenPuttemans gravatar imageStevenPuttemans ( 2016-02-27 03:27:28 -0600 )edit

Question Tools

Stats

Asked: 2014-07-08 21:18:27 -0600

Seen: 1,796 times

Last updated: Aug 20 '14