crack detect red line opencv
i want to make a decision making process of detection of biscuit crack so i used the hough transform for detection of crack. here is the code. It means counting the red pixels,if present then say as crack and if not present say no crack simply. One more thing i want to measure the size of my biscuit.
Mat src = imread("/home/pi/Desktop/pics/grey.jpg");
Mat dst, cdst,pic;
Canny(src, dst, 30, 160, 3);
cvtColor(dst, pic, CV_GRAY2BGR);
imwrite("/home/pi/Desktop/pics/bisgry.jpg",pic);
// imshow("source",pic);
cdst=~pic;
vector<Vec2f> lines;
HoughLines(dst, lines, 1, CV_PI/180,33 ,1, 1 );
for( size_t i = 0; i < lines.size(); i++ )
{
float rho = lines[i][0], theta = lines[i][1];
Point pt1, pt2;
double a = cos(theta), b = sin(theta);
double x0 = a*rho, y0 = b*rho;
pt1.x = cvRound(x0 + 1000*(-b));
pt1.y = cvRound(y0 + 1000*(a));
pt2.x = cvRound(x0 - 1000*(-b));
pt2.y = cvRound(y0 - 1000*(a));
line( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
}
/*vector<Vec4i> lines;
HoughLinesP(dst, lines, 1, CV_PI/180, 50, 50, 10 );
for( size_t i = 0; i < lines.size(); i++ )
{
Vec4i l = lines[i];
line( cdst, Point(l[0], l[1]), Point(l[2], l[3]), Scalar(0,0,255), 3, CV_AA);
}*/
[enter image description here][1] imshow("source", src);
imshow("source1",pic);
imshow("detected lines", cdst);
imwrite("/home/pi/Desktop/pics/cracked.jpg",cdst);
waitKey();
@pklab there are the error sir i added headers imgproc.h,highgui.h,opencv2.h
pi@raspberrypi:~/Desktop $ g++ -ggdb `pkg-config --cflags --libs opencv` blob.cpp -o bolb
Ok i again run the code by including namespace cv and std but these are the errors. please give me some hints so that i can improve. i am learner and student not professional sir.
alarray<_Tp>’
Point2f pt1 = (rect_points[1] + rect_points[2]) / 2.0;
^
In file included from /usr/include/opencv2/contrib/retina.hpp:76:0,
from /usr/include/opencv2/contrib/contrib.hpp:979,
from /usr/local/include/opencv2/opencv.hpp:59,
from crackb.cpp:5:
/usr/include/c++/4.9/valarray:1170:1: note: template argument deduction/substitution failed:
crackb.cpp:118:59: note: mismatched types ‘const std::valarray<_Tp>’ and ‘double’
Point2f pt1 = (rect_points[1] + rect_points[2]) / 2.0;
file included from /usr/local/include/opencv2/core/core.hpp:4884:0,
from /usr/local/include/opencv2/highgui/highgui.hpp:46,
from crackb.cpp:2:
/usr/local/include/opencv2/core/mat.hpp:1301:20: note: cv::MatExpr cv::operator/(const
CV_EXPORTS MatExpr operator / (const MatExpr& e1, const MatExpr& e2);
^
/usr/local/include/opencv2/core/mat.hpp:1301:20: note: no known conversion for argument 1 from ‘cv::Point_<float>’ to ‘const cv::MatExpr&’
/usr/local/include/opencv2/core/mat.hpp:1300:20: note: cv::MatExpr cv::operator/(double, const cv::MatExpr&)
CV_EXPORTS MatExpr operator / (double s, const MatExpr& e);
^
/usr/local/include/opencv2/core/mat.hpp:1300:20: note: no known conversion for argument 1 from ‘cv::Point_<float ...
since your idea is based on finding one or more hough lines, you can simply check
lines.size()
.there is no need to count red pixels at all.
what if crack is an arc ? I would not use hough but simpler blob detection or contours with stats... for biscuit size too. I suggest post original image better if color.
@berak line.size().i didn't find any function in opencv and how to use it
@pklab i edit the original image i don't bother about corner crack
@gauravsharma01901 : maybe it's a good idea, to leave all this aside for a few days, and rather try to get basic c++ skills in the meantime. if you don't know, how to handle a vector, -- what on earth are you doing here, then ?
@berak dear berak i don't know why my compiler not reading vector<> i have example code of opencv also have vector. i also shows the errors. i have done with it but nothing happens
include<vector>
@gauravsharma01901 if you don't know how to use vector<> there is nothing we can do here...bye bye