Ashik
Ashik

Reputation: 357

Measuring object size using webcam

I need to calculate distance between two points using a webcam. Now the catch is I don't need it to be any way related to actual measurements in cm or whatever. What I want is to use different webcams of different resolutions and they should all give the same measurement. I'll explain.

Suppose I am viewing a square shape using a webcam of 640x480 and it measures as one unit. I then view the same object from the same positions using a webcam of 1024x768 and it should still measure as 1 unit. How do I do this?

Upvotes: 0

Views: 3148

Answers (1)

Balaji R
Balaji R

Reputation: 1845

You didn't mentioned about the process by which you are measuring the dimensions of the object. I'm gonna assume you are measuring by using a single camera. You can take this method as a reference & this can be applied to any methodology.

Here are the steps to measure the size of object:

  1. How will you measure length of a line drawn in this picture? enter image description here
  2. You need a ruler as a reference. To make this ruler you have to know the real world ruler size which will be in pixels in our case.
  3. Now make a graph. I'm gonna take a unit line as a reference graph. I'm taking centimeter scale as reference.
    enter image description here

  4. Place this graph in front of the camera & detect the Two red dots. Now calculate the number of pixels between this two points ref. Lets assume the distance is 1000 pixels. So 1 cm is taking 1000 pixels. So 1 pixel is equal to 0.1 cm & take this as a Reference_pixels_count.

  5. Repeat this step 4 for all the resolutions & find the Reference_pixels_count for that Resolution.

  6. Now place an object & get the size of image.find corners & cycle through each corner and find the distance between each corner. Multiply this distance with the Reference_pixels_count to get the actual dimension of the object.enter image description here

NOTE: This method can work only for flat object with negligible depth change.

Upvotes: 1

Related Questions