Detect and extend white lines in an image.
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 Please guest me what should I do.
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
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<Vec2f> 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.
What about it isn't correct? It appears that you are getting three liens, one of which is exactly what I would expect you want.