10 _detectedEdges = Mat();
32 Mat mask = Mat(src.size(), CV_8UC1, Scalar(1));
33 for(
int i = 0;i < mask.rows/2; i++){
34 for(
int j = 0;j < mask.cols;j++){
35 mask.at<uchar>(
Point(j,i)) = 0;
41 _detectedEdges = Mat(img.size(),CV_8UC1);
42 _detectedEdges.setTo(0);
46 for (
int j = img.rows/2;j<img.rows;j++){
47 unsigned char *imgptr = img.ptr<uchar>(j);
48 unsigned char *detEdgesptr = _detectedEdges.ptr<uchar>(j);
51 for (
int i = _LMWidth;i < img.cols - _LMWidth; ++i){
54 val += -imgptr[i - _LMWidth];
55 val += -imgptr[i + _LMWidth];
56 val += -abs((
int)(imgptr[i - _LMWidth] - imgptr[i + _LMWidth]));
59 val = (val>255)?255:val;
61 detEdgesptr[i] = (
unsigned char) val;
67 threshold(_detectedEdges,_detectedEdges,_thres,255,0);
75 Mat _detectedEdgesRGB;
76 cvtColor(_detectedEdges,_detectedEdgesRGB, CV_GRAY2BGR);
77 HoughLines(_detectedEdges,_lines,_rho,_theta,_houghThres);
80 if (_lines.size() > 1){
82 Mat samples = Mat(_lines.size(),2,CV_32F);
84 for (
int i = 0;i < _lines.size();i++){
85 samples.at<
float>(i,0) = _lines[i][0];
86 samples.at<
float>(i,1) = _lines[i][1];
89 kmeans(samples, 2, labels, TermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS, 1000, 0.001), 5, KMEANS_PP_CENTERS, centers );
95 vector<Point2f> right;
96 for(
int i = 0;i < labels.rows; i++){
97 if (labels.at<
int>(i) == 0) left.push_back(Point2f(samples.at<
float>(i,0), samples.at<
float>(i,1)));
98 else right.push_back(Point2f(samples.at<
float>(i,0), samples.at<
float>(i,1)));
101 vector<Point2f> leftR = ransac(left);
102 vector<Point2f> rightR = ransac(right);
105 if (leftR.size() < 1 || rightR.size() < 1 ||
106 (float)(cos((leftR[0].
y + leftR[1].
y)/2) * cos((rightR[0].y + rightR[1].y)/2)) >= 0)
return retVar;
109 _lines.push_back(Vec2f((leftR[0].
x + leftR[1].
x)/2, (leftR[0].y + leftR[1].y)/2));
110 _lines.push_back(Vec2f((rightR[0].x + rightR[1].x)/2, (rightR[0].y + rightR[1].y)/2));
127 for(
int i = 0;i < data.size();i++){
128 Point2f p1 = data[i];
131 for(
int j = i + 1;j < data.size();j++){
132 Point2f p2 = data[j];
136 for (
int k = 0;k < data.size();k++){
137 Point2f p3 = data[k];
138 float normalLength = norm(p2 - p1);
139 float distance = abs((
float)((p3.x - p1.x) * (p2.y - p1.y) - (p3.y - p1.y) * (p2.x - p1.x)) / normalLength);
140 if (distance < _ransacThres) n++;
144 if (n > maxInliers) {
162 cvtColor(img,imgRGB,CV_GRAY2RGB);
163 vector<Point> endPoints;
167 for (
int i = 0;i < lines.size();i++){
168 float r = lines[i][0];
169 float t = lines[i][1];
174 Point p1(cvRound(x - 1.0*sin(t)*1000), cvRound(y + cos(t)*1000));
175 Point p2(cvRound(x + 1.0*sin(t)*1000), cvRound(y - cos(t)*1000));
177 clipLine(img.size(),p1,p2);
179 endPoints.push_back(p1);
180 endPoints.push_back(p2);
183 endPoints.push_back(p2);
184 endPoints.push_back(p1);
191 bool check = findIntersection(endPoints,pint);
194 line(imgRGB,endPoints[0],pint,Scalar(0,0,255),5);
195 line(imgRGB,endPoints[2],pint,Scalar(0,0,255),5);
200 float xIntercept =
min(endPoints[0].
x,endPoints[2].x);
201 myfile << name <<
"," << xIntercept * 2 <<
"," << pint.
x * 2 << endl;
211 Point x = endP[2] - endP[0];
212 Point d1 = endP[1] - endP[0];
213 Point d2 = endP[3] - endP[2];
216 if (abs(cross) < 1e-8)
219 double t1 = (x.
x * d2.
y - x.
y * d2.
x)/cross;
220 pi = endP[0] + d1 * t1;
229 namedWindow(
"detectedFeatures");
230 imshow(
"detectedFeatures",imgRGB);
242 Mat img1 = imread(ippath,0);
247 Mat imgFinal = detect.
lineItr(img1, lines, imname);
250 imwrite(oppath,imgFinal);
252 while ( getline (imageNames,imname) ){
253 ippath =
"./images/";
254 oppath =
"./output/";
257 Mat img2 = imread(ippath,0);
265 if (lines2.size() < 2) {
266 imgFinal = detect.
lineItr(img2,lines, imname);
268 imwrite(oppath,imgFinal);
274 vector<Vec2f> pp = KF2.
predict();
276 vector<Vec2f> lines2Final = KF2.
update(lines2);
278 imgFinal = detect.
lineItr(img2,lines2, imname);
282 imwrite(oppath,imgFinal);
bool findIntersection(vector< Point >, Point &)
TFSIMD_FORCE_INLINE Vector3 cross(const Vector3 &v) const
cv::KalmanFilter KF2(stateDim, measDim, ctrlDim, CV_32F)
int main(int argc, char **argv)
void filteringPipeLine(Mat)
TFSIMD_FORCE_INLINE tfScalar distance(const Vector3 &v) const
Mat lineItr(Mat, vector< Vec2f >, string)
TFSIMD_FORCE_INLINE const tfScalar & y() const
vector< Vec2f > update(vector< Vec2f >)
TFSIMD_FORCE_INLINE const tfScalar & x() const
TFSIMD_FORCE_INLINE const tfScalar & y() const
TFSIMD_FORCE_INLINE const tfScalar & x() const
vector< Point2f > ransac(vector< Point2f >)
vector< Vec2f > houghTransform()
vector< Vec2f > predict()