Search code examples
opencvmathshapesemgucvmeasurement

Measure real size of irregular shapes in picture


I have two "contours" shapes in a array, one contourn is the square that i know his real size, and the other is the mole that i need to make the proportional measurement. Here is the image example:

enter image description here

The square has 10x10mm, how can i know the size of the other shape based on the square?

What i tried so far is this:

var molePerimeter = CvInvoke.ArcLength(contours[0], false);
double moleArea = CvInvoke.ContourArea(contours[0], false);
var squarePerimeter = CvInvoke.ArcLength(squares[0], true);
double squareArea = CvInvoke.ContourArea(squares[0], false);
textBox2.AppendText("Area: " + squareArea / moleArea);
textBox2.AppendText("perimeter: " + squarePerimeter / molePerimeter);

But i dont thinks that is corret.


Solution

  • Assuming that the mole is probably in a circular shape, You may use cv::boundingRect(), it would return you a cv::Rect(), which you may use to get the rectangular dimensions of the mole.

    similarly you have the rectangular dimensions of the white patch. Say the dimensions of mole are (w1 x h1) and that of white patch are (w2 x h2).

    Now to calculate the dimension of mole w.r.t real world dimensions:

    real_w_patch, real_h_patch = 10, 10
    
    real_w_mole = w1/w2 * real_w_patch
    real_h_mole = h1/h2 * real_h_patch
    

    NOTE: Make sure that all the variables are either in float or double to make precise calculations.