Hello,
I have an image with white lines in it and I just need a program to extend those white lines [C:\fakepath\vlcsnap.png](/upfiles/14531351914900935.png)
Please guest me what should I do.
#include
#include
#include
#include
using namespace std;
using namespace cv;
int thresh = 100;
Mat dst, cdst;
Mat img, original;
Mat whiteFilter(const Mat& src)
{
assert(src.type() == CV_8UC3);
Mat whiteOnly;
inRange(src, Scalar(150, 150, 150), Scalar(255, 255, 255), whiteOnly);
return whiteOnly;
}
void on_trackbar(int, void*)
{//This function gets called whenever a
// trackbar position is changed
Mat whiteOnly = whiteFilter(original);
img = original.clone();
Canny(whiteOnly, dst, 50, 200, 3);
cvtColor(dst, cdst, CV_GRAY2BGR);
vector lines;
HoughLines(dst, lines, 1, CV_PI / 180, thresh, 0, 0);
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(img, pt1, pt2, Scalar(255, 255, 255), 1, CV_AA);
}
imshow("detected lines", img);
}
int main(int argc, char** argv)
{
Mat input = imread("D:/Pictures/vlcsnap.png");
if (input.empty())
{
cout << "File not found" << endl;
return 0;
}
img = input.clone();
original = input.clone();
imshow("input", input);
Mat whiteOnly = whiteFilter(input);
imshow("whiteOnly", whiteOnly);
Canny(whiteOnly, dst, 50, 200, 3);
cvtColor(dst, cdst, CV_GRAY2BGR);
imshow("detected lines", img);
createTrackbar("thresh", "detected lines", &thresh, 200, on_trackbar);
waitKey();
return 0;
}
The result I'm getting is not what i desire please help me.
Result [C:\fakepath\white.png](/upfiles/14531361399046206.png)
[C:\fakepath\detected.png](/upfiles/14531361566655249.png)
↧