Crack detection using opencv
<blockquote>
  <p>Hey I have a code of crack detection but while running the code I got
  error. Here is the code, the error is in 2.0f and 2.0  when I remove
  this all related error to this got solved but new error DrawMarker not
  declared in this scope.</p>
</blockquote>

<pre><code>#include &lt;opencv2\opencv.hpp&gt;
using namespace std;
using namespace cv;
#define CL_GREEN  Scalar(0  , 255, 0  )
#define CL_RED    Scalar(0  , 0  , 255)
#define CL_BLU    Scalar(255, 0  , 0  )
#define CL_BLACK  Scalar(0  , 0  , 0  )     
void Morph(const cv::Mat &amp;src, cv::Mat &amp;dst, int operation =    cv::MORPH_OPEN, 
int kernel_type = cv::MORPH_RECT, int size = 1);
struct contourStats{
double area, perimeter, axisMin, axisMax, axisAvg, eccentricity, axisRatio, circularity;
Point2d center;
RotatedRect rr;
contourStats(){}
contourStats(const vector&lt;Point&gt; &amp;contour)
{
    calculateStats(contour);
}
void calculateStats(const vector&lt;Point&gt; &amp;contour)
{
    Moments m = cv::moments(contour, true);
    area = m.m00;
    center = Point2f(-1, -1);
    if (area &gt; 0){
        center.x = cvRound(m.m10 / m.m00);
        center.y = cvRound(m.m01 / m.m00);
    }
    eccentricity = DBL_MAX;
    if ((m.m20 + m.m02) &gt; 0)
        eccentricity = (pow((m.m20 - m.m02), 2) - 4 * m.m11 * m.m11) / pow((m.m20 + m.m02), 2);
    // axis ratio:circles have ratio=1 lines have ratio-&gt;0
    rr = minAreaRect(contour);
    axisMin = min(rr.size.height, rr.size.width);
    axisMax = max(rr.size.height, rr.size.width);
    axisAvg = (axisMin+axisMax) / 2.0;
    axisRatio = axisMax &gt; 0 ? axisMin / axisMax : 0;
    perimeter = arcLength(contour, false);
    circularity = perimeter &gt; 0 ? 4 * CV_PI * area / pow(perimeter, 2) : 0;
}
void printStats(const string &amp;title)
{
    cout &lt;&lt; endl &lt;&lt; title &lt;&lt; endl
        &lt;&lt; "\tArea [px^2]: " &lt;&lt; area &lt;&lt; endl
        &lt;&lt; "\tAxis[px]: " &lt;&lt; axisMin &lt;&lt; "/" &lt;&lt; axisMax &lt;&lt; endl
        &lt;&lt; "\tAxis Ratio: " &lt;&lt; axisRatio &lt;&lt; endl
        &lt;&lt; "\tCircularity: " &lt;&lt; circularity &lt;&lt; endl
        &lt;&lt; "\tAbs(eccentricity): " &lt;&lt; abs(eccentricity) &lt;&lt; endl;
}
};

       int main(int argc, char** argv)
      {
    Mat src, gray, edges, cracks,tmp;
Mat biscuitMask;
//src = imread("../img/biscotto_rotated.jpg");
src = imread("../img/biscotto.jpg");
cvtColor(src, gray, CV_BGR2GRAY);
// GET ALL EDGES (CRACKS AND BISCUIT)
Canny(gray, edges, 100, 200, 3);
Morph(edges, edges, MORPH_CLOSE, MORPH_ELLIPSE, 5);
// GET THE BISCUIT ONLY
GaussianBlur(gray, gray, Size(7, 7), 0);
threshold(gray, biscuitMask, 0, 255, THRESH_OTSU);
// VALIDATE THE BISCUIT
vector&lt;vector&lt;Point&gt; &gt; contours;
biscuitMask.copyTo(tmp);
findContours(tmp, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
if ((contours.size() &gt; 1) || (contours[0].size() &lt; 6)) {
    cerr &lt;&lt; "ERROR: invalid mask for the biscuit!";
    return 1;
}
vector&lt;Point&gt; biscuitContour(contours[0]);
contourStats theBiscuit(biscuitContour);
theBiscuit.printStats("BISCUIT STATS:");
if (theBiscuit.circularity &lt; 0.85) {
    cout &lt;&lt; "WARNING: invalid biscuit circularity!";
}
drawMarker(src, theBiscuit.center, CL_BLU, MARKER_CROSS, theBiscuit.axisAvg / 8);
circle(src, theBiscuit.center, theBiscuit.axisAvg / 2, CL_BLU, 2);
//polylines(src, biscuitContour, true, CL_GREEN); 

// GET ONLY THE CRACKS INSIDE THE BISCUIT
Morph(biscuitMask, biscuitMask, MORPH_ERODE,MORPH_ELLIPSE, 5);
cracks = (edges &amp; biscuitMask);
imshow("cracks", cracks);

findContours(cracks, contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);

double minLenght = theBiscuit.axisAvg / 2;
double maxLenght = 0;
int biggest = -1;
vector&lt;contourStats&gt; crackStats(contours.size());
for (size_t i = 0; i &lt; contours.size(); i++)
{
    drawContours(src, contours, i, CL_GREEN, 1); //all contours in GREEN
    crackStats[i].calculateStats(contours[i]);   //analize potential cracks
    if (crackStats[i].axisMax &lt; minLenght)       //ignore short contours
        continue;
    drawContours(src, contours, i, CL_RED, 1);   //longer contours are cracks
    if (crackStats[i].axisMax &gt; maxLenght)       // get longest crack
        biggest = i;
}
// DRAW AROUND BIGGER CRACKS
if (biggest &gt; 0)  {
    cout &lt;&lt; "Cracks Found! Biggest size: " &lt;&lt; crackStats[biggest].axisMax &lt;&lt;
        "px (" &lt;&lt; 100 * crackStats[biggest].axisMax / theBiscuit.axisMax &lt;&lt; "%)" 
        &lt;&lt; endl;
    RotatedRect rr = crackStats[biggest].rr;
    Point2f rect_points[4];
    rr.points(rect_points);
    //draw enclosing rectangle
    for (int j = 0; j &lt; 4; j++) 
        line(src, rect_points[j], rect_points[(j + 1) % 4], CL_RED, 1, 8);
    //draw major axis
    Point2f pt0 = (rect_points[0] + rect_points[3]) / 2.0;
    Point2f pt1 = (rect_points[1] + rect_points[2]) / 2.0;
    Point2f pt2 = (rect_points[0] + rect_points[1]) / 2.0;
    Point2f pt3 = (rect_points[2] + rect_points[3]) / 2.0;
    double axis1 = norm(pt0 - pt1);
    double axis2 = norm(pt2 - pt3);
    if (axis1&gt;axis2)
        line(src, pt0, pt1, CL_BLACK, 2);
    else
        line(src, pt2, pt3, CL_BLACK, 2);
}
imshow("Src", src);
waitKey(0);
return 0;
}
void Morph(const cv::Mat &amp;src, cv::Mat &amp;dst, int operation,int kernel_type, int size)
{
cv::Point anchor = cv::Point(size, size);
cv::Mat element = getStructuringElement(kernel_type, cv::Size(2 * size +  1, 2 * size + 1), anchor);
morphologyEx(src, dst, operation, element, anchor);
}
</code></pre>

<p>Here is my image file of biscuit.....</p>

<p><a href="https://i.stack.imgur.com/g0VKE.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/g0VKE.jpg" alt="enter image description here"></a></p>

<p>Here the output of revised code</p>

<p><img src="https://i.stack.imgur.com/xjBsi.png" alt="enter image description here"></p>