A T-Shirt Measurements using Image processing

/
0 Comments
Project can be categorized to my free lancer career. Identifying the distance of a object by using image processing is currently on research level when we considering very accurate value. In this project I have succeed to measure a distance of a object by mapping to points get by user inputs. I used python as a programming language and opencv as a framework for image processing.

Use cases are shown below to measure a distance of two points.

  • Image should be added as a input
  • User should be clicked to point if he/she wants to measure length     
When a user clicks a point its coordinates can be get using image processing techniques. It's not that much difficulty to locate. Image can be considered as a 2d matrix. That means if it is a pixel * b pixel image it can be represented as a a * b matrix. When a user clicks a point its coordinates can be identified by using above mentioned matrix.       

Example

[  .  ] 
[ . . ]
[. . .]

        This image can be represented as a matrix by assigning 255 for black dot and 0 for white dot. According to the above definition image can be represented as below.

[0 0 255 0 0]
[0 255 0 255 0]
[255 0 255 0 255]

Hope you get the better idea about that. So after user clicks two point I calculated the euclidean distance of those two points. Then by using that how can we calculate the actual length.

I solved it using pre-defined value. In order to calculate it I followed below steps.

  • Camera to object distance should be a constant (2 m). I will explain it later.
  • Capture a image of a object.
  • Measure a length of known two points. 
  • Entered above captured image as a input to the program.
  • Calculate its euclidean distance.     
Then we can define a small equation for known euclidean distance. Below variables can be used to represented it.

a - Actual length of known two points
e - Euclidean distance of known two points calculated from the image array (Describe above)
y-  Euclidean distance of unknown two points calculated from the image array 
x - Length of unknown two points 

Equation can be generated according to the above variables.

a / e = x / y

Therefore, x = y * ( a / e )

The value of ( a / e ) is a constant.
So , ( a / e ) = c

x = y * c

If you carefully read my article you are able to realized that you can get very accurate distance for this image.
But the problem is how can we use this equation and the constant for all images that input for the application. 
We defined above constant using a ratio. It's depend on distance of the camera and the object. In order to use this constant for all the images distance of camera to object should be a constant.
That's why I mentioned it above.

Now you should have a problem about this. In order to get the euclidean distance each pixel should be represented to the user to get input click. The problem is if user inputs a image with large number of pixels (Ex - 2000 * 3000) screen is not enough to represent it.

As a solution for the above problem I had to reduced the pixel size of the input image. But this can be harm for our constant. So when you define the constant this step should be added to the above flow too. And the import thing is this reducing factor should be a constant for all the input images. Otherwise our constant not be a constant any more. 

By using below link you can download my source code from GitHub and you can test it using your own input images.
But there is a problem which still not solved. I used a decimal factor for the reducing image pixel size because most of the images lay with 2000 * 3000 pixel size. That's a assumption. So If you input a image with low pixel size my calculations can be wrong. So when you input a image please remember to re-size it to above mentioned pixel size.         

Complete Application - youtube


You may also like

No comments :

Powered by Blogger.