Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detected lanes with Hough in OpenCV

Hi I've been trying to segment the image of a lane in which I have after performing different steps reached this result, I require is that the lane leading car or rail which is marked with the dividing lines of being noticed lane, someone who can help then attached the code.

Now I have been working on the analysis of images with OpenCV, what I'm trying to do is recognize the lane dividing lines, what I do is the following:

1.I receive a image, 2. Then transform it to grayscale 3.I apply the GaussianBlur 4.After I place me in the ROI 5.I apply the canny 6.then I look for lines with hough transform Lines 7.Draw the lines obtained from hough

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
#include "linefinder.h"

#define PI 3.1415926

using namespace cv;
using namespace std;

int main(int argc, char* argv[]) {
  int houghVote = 200;
  string arg = argv[1];
  Mat image;
  image = imread(argv[1]);  
  Mat gray;
  cvtColor(image,gray,CV_RGB2GRAY);
  GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
  vector<string> codes;
  Mat corners;
  findDataMatrix(gray, codes, corners);
  drawDataMatrixCodes(image, codes, corners);
  //Mat image = imread("");
  //Rect region_of_interest = Rect(x, y, w, h);
  //Mat image_roi = image(region_of_interest);
  std::cout << image.cols << "\n";
  std::cout << image.rows << "\n";
  Rect roi(0,200,640,206);
  Mat imgROI = image(roi);
  // Display the image
  imwrite("original.bmp", imgROI);
  // Canny algorithm
  Mat contours;
  Canny(imgROI, contours, 120, 300, 3); 
  imwrite("canny.bmp", contours);
  Mat contoursInv;
  threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

 /* 
 Hough tranform for line detection with feedback
 Increase by 25 for the next frame if we found some lines.  
 This is so we don't miss other lines that may crop up in the next frame
 but at the same time we don't want to start the feed back loop from scratch. 
 */
 std::vector<Vec2f> lines;
 if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset 
    houghVote = 200; 
 }/*else{ 
    houghVote += 25;
 } */
 while(lines.size() < 5 && houghVote > 0){
    HoughLines(contours,lines,1,PI/180, houghVote);
    houghVote -= 5;
 }
 std::cout << houghVote << "\n";
 Mat result(imgROI.size(),CV_8U,Scalar(255));
 imgROI.copyTo(result);
 // Draw the limes
 std::vector<Vec2f>::const_iterator it= lines.begin();
 Mat hough(imgROI.size(),CV_8U,Scalar(0));
 while (it!=lines.end()) {
    float rho= (*it)[0];   // first element is distance rho
    float theta= (*it)[1]; // second element is angle theta
    if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) { 
    // filter to remove   vertical and horizontal lines
        // point of intersection of the line with first row
        Point pt1(rho/cos(theta),0);        
        // point of intersection of the line with last row
        Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
        // draw a white line
        line( result, pt1, pt2, Scalar(255), 8); 
        line( hough, pt1, pt2, Scalar(255), 8);
    }
    ++it;
  }

  // Display the detected line image
  std::cout << "line image:"<< "\n";
  namedWindow("Detected Lines with Hough");
  imwrite("hough.bmp", result);

  // Create LineFinder instance
  LineFinder ld;

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(60,10);
  ld.setMinVote(4);

  // Detect lines
  std::vector<Vec4i> li= ld.findLines(contours);
  Mat houghP(imgROI.size(),CV_8U,Scalar(0));
  ld.setShift(0);
  ld.drawDetectedLines(houghP);
  std::cout << "First Hough" << "\n";
  imwrite("houghP.bmp", houghP);

  // bitwise AND of the two hough images
  bitwise_and(houghP,hough,houghP);
  Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
  Mat dst(imgROI.size(),CV_8U,Scalar(0));
  threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
  namedWindow("Detected Lines with Bitwise");
  imshow("Detected Lines with Bitwise", houghPinv);

  Canny(houghPinv,contours,100,350);
  li= ld.findLines(contours);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(5,2);
  ld.setMinVote(1);
  ld.setShift(image.cols/3);
  ld.drawDetectedLines(image);

  std::stringstream stream;
  stream << "Lines Segments: " << lines.size();

  putText(image, stream.str(), Point(10,image.rows-10), 2, 0.8, Scalar(0,0,255),0); 
  imwrite("processed.bmp", image);

  char key = (char) waitKey(10);
  lines.clear();
  }

Then I show the original image and the result

enter image description here

enter image description here

Detected lanes with Hough in OpenCV

Hi Now I've been trying to segment the image of a lane in which I have after performing different steps reached this result, I require is that the lane leading car or rail which is marked with the dividing lines of being noticed lane, someone who can help then attached the code.

Now I have been working on the analysis of images with OpenCV, what I'm trying to do is recognize the lane dividing lines, what I do is the following:is:

1.I receive a an image, 2. Then transform it to grayscale grayscale transform 3.I apply the applying GaussianBlur 4.After 4. After I place me get in the ROI 5.I apply the canny 6.then I look for wily 6. After looking lines with hough transform Lines lines Hough transform 7.Draw the lines obtained from houghthe Hough

But I've run into a problem which is: it does not recognize dotted boundaries, and does not recognize the yellow lines. Someone give me an idea I've tried everything but can not get anything ...

I hope you help me solve this problem, you will thank a lot. Deputy code and some sample images.

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
#include "linefinder.h"

#define PI 3.1415926

using namespace cv;
using namespace std;

int main(int argc, char* argv[]) {
  int houghVote = 200;
  string arg = argv[1];
  Mat image;
  image = imread(argv[1]);  
  Mat gray;
  cvtColor(image,gray,CV_RGB2GRAY);
  GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
  vector<string> codes;
  Mat corners;
  findDataMatrix(gray, codes, corners);
  drawDataMatrixCodes(image, codes, corners);
  //Mat image = imread("");
  //Rect region_of_interest = Rect(x, y, w, h);
  //Mat image_roi = image(region_of_interest);
  std::cout << image.cols << "\n";
  std::cout << image.rows << "\n";
  Rect roi(0,200,640,206);
  Mat imgROI = image(roi);
  // Display the image
  imwrite("original.bmp", imgROI);
  // Canny algorithm
  Mat contours;
  Canny(imgROI, contours, 120, 300, 3); 
  imwrite("canny.bmp", contours);
  Mat contoursInv;
  threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

 /* 
 Hough tranform for line detection with feedback
 Increase by 25 for the next frame if we found some lines.  
 This is so we don't miss other lines that may crop up in the next frame
 but at the same time we don't want to start the feed back loop from scratch. 
 */
 std::vector<Vec2f> lines;
 if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset 
    houghVote = 200; 
 }/*else{ 
    houghVote += 25;
 } */
 while(lines.size() < 5 && houghVote > 0){
    HoughLines(contours,lines,1,PI/180, houghVote);
    houghVote -= 5;
 }
 std::cout << houghVote << "\n";
 Mat result(imgROI.size(),CV_8U,Scalar(255));
 imgROI.copyTo(result);
 // Draw the limes
 std::vector<Vec2f>::const_iterator it= lines.begin();
 Mat hough(imgROI.size(),CV_8U,Scalar(0));
 while (it!=lines.end()) {
    float rho= (*it)[0];   // first element is distance rho
    float theta= (*it)[1]; // second element is angle theta
    if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) { 
    // filter to remove   vertical and horizontal lines
        // point of intersection of the line with first row
        Point pt1(rho/cos(theta),0);        
        // point of intersection of the line with last row
        Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
        // draw a white line
        line( result, pt1, pt2, Scalar(255), 8); 
        line( hough, pt1, pt2, Scalar(255), 8);
    }
    ++it;
  }

  // Display the detected line image
  std::cout << "line image:"<< "\n";
  namedWindow("Detected Lines with Hough");
  imwrite("hough.bmp", result);

  // Create LineFinder instance
  LineFinder ld;

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(60,10);
  ld.setMinVote(4);

  // Detect lines
  std::vector<Vec4i> li= ld.findLines(contours);
  Mat houghP(imgROI.size(),CV_8U,Scalar(0));
  ld.setShift(0);
  ld.drawDetectedLines(houghP);
  std::cout << "First Hough" << "\n";
  imwrite("houghP.bmp", houghP);

  // bitwise AND of the two hough images
  bitwise_and(houghP,hough,houghP);
  Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
  Mat dst(imgROI.size(),CV_8U,Scalar(0));
  threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
  namedWindow("Detected Lines with Bitwise");
  imshow("Detected Lines with Bitwise", houghPinv);

  Canny(houghPinv,contours,100,350);
  li= ld.findLines(contours);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(5,2);
  ld.setMinVote(1);
  ld.setShift(image.cols/3);
  ld.drawDetectedLines(image);

  std::stringstream stream;
  stream << "Lines Segments: " << lines.size();

  putText(image, stream.str(), Point(10,image.rows-10), 2, 0.8, Scalar(0,0,255),0); 
  imwrite("processed.bmp", image);

  char key = (char) waitKey(10);
  lines.clear();
  }

Then I show the original image and the result

enter image description here

enter image description here

Detected lanes with Hough in OpenCV

Now I've been working on the analysis of images with OpenCV, what I'm trying to do is recognize the lane dividing lines, what I do is:

1.I receive an image, 2. Then grayscale transform 3.I applying GaussianBlur 4. After I get in the ROI 5.I apply the wily 6. After looking lines with lines Hough transform 7.Draw lines obtained from the Hough

But I've run into a problem which is: it does not recognize dotted boundaries, and nor does not always recognize the yellow lines. Someone give me an idea I've tried everything but can not get anything ...

I hope you help me solve this problem, you will thank a lot. Deputy I attached code and some sample images.images. #include "opencv2/highgui/highgui.hpp" #include <opencv2 objdetect="" objdetect.hpp=""> #include <opencv2 imgproc="" imgproc.hpp=""> #include <iostream> #include <vector> #include <stdio.h> #include "linefinder.h"

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
#include "linefinder.h"

#define PI 3.1415926

using namespace cv;
using namespace std;

int main(int argc, char* argv[]) {
  int houghVote = 200;
  string arg = argv[1];
  Mat image;
  image = imread(argv[1]);  
  Mat gray;
  cvtColor(image,gray,CV_RGB2GRAY);
  GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
  vector<string> codes;
  Mat corners;
  findDataMatrix(gray, codes, corners);
  drawDataMatrixCodes(image, codes, corners);
  //Mat image = imread("");
  //Rect region_of_interest = Rect(x, y, w, h);
  //Mat image_roi = image(region_of_interest);
  std::cout << image.cols << "\n";
  std::cout << image.rows << "\n";
  Rect roi(0,200,640,206);
  Mat imgROI = image(roi);
  // Display the image
  imwrite("original.bmp", imgROI);
  // Canny algorithm
  Mat contours;
  Canny(imgROI, contours, 120, 300, 3); 
  imwrite("canny.bmp", contours);
  Mat contoursInv;
  threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

 /* 
 Hough tranform for line detection with feedback
 Increase by 25 for the next frame if we found some lines.  
 This is so we don't miss other lines that may crop up in the next frame
 but at the same time we don't want to start the feed back loop from scratch. 
 */
 std::vector<Vec2f> lines;
 if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset 
    houghVote = 200; 
 }/*else{ 
    houghVote += 25;
 } */
 while(lines.size() < 5 && houghVote > 0){
    HoughLines(contours,lines,1,PI/180, houghVote);
    houghVote -= 5;
 }
 std::cout << houghVote << "\n";
 Mat result(imgROI.size(),CV_8U,Scalar(255));
 imgROI.copyTo(result);
 // Draw the limes
 std::vector<Vec2f>::const_iterator it= lines.begin();
 Mat hough(imgROI.size(),CV_8U,Scalar(0));
 while (it!=lines.end()) {
    float rho= (*it)[0];   // first element is distance rho
    float theta= (*it)[1]; // second element is angle theta
    if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) { 
    // filter to remove   vertical and horizontal lines
        // point of intersection of the line with first row
        Point pt1(rho/cos(theta),0);        
        // point of intersection of the line with last row
        Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
        // draw a white line
        line( result, pt1, pt2, Scalar(255), 8); 
        line( hough, pt1, pt2, Scalar(255), 8);
    }
    ++it;
  }

  // Display the detected line image
  std::cout << "line image:"<< "\n";
  namedWindow("Detected Lines with Hough");
  imwrite("hough.bmp", result);

  // Create LineFinder instance
  LineFinder ld;

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(60,10);
  ld.setMinVote(4);

  // Detect lines
  std::vector<Vec4i> li= ld.findLines(contours);
  Mat houghP(imgROI.size(),CV_8U,Scalar(0));
  ld.setShift(0);
  ld.drawDetectedLines(houghP);
  std::cout << "First Hough" << "\n";
  imwrite("houghP.bmp", houghP);

  // bitwise AND of the two hough images
  bitwise_and(houghP,hough,houghP);
  Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
  Mat dst(imgROI.size(),CV_8U,Scalar(0));
  threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
  namedWindow("Detected Lines with Bitwise");
  imshow("Detected Lines with Bitwise", houghPinv);

  Canny(houghPinv,contours,100,350);
  li= ld.findLines(contours);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(5,2);
  ld.setMinVote(1);
  ld.setShift(image.cols/3);
  ld.drawDetectedLines(image);

  std::stringstream stream;
  stream << "Lines Segments: " << lines.size();

  putText(image, stream.str(), Point(10,image.rows-10), 2, 0.8, Scalar(0,0,255),0); 
  imwrite("processed.bmp", image);

  char key = (char) waitKey(10);
  lines.clear();
  }

Then I show the original image and the result

enter image description here

enter image description here

Detected lanes with Hough in OpenCV

Now I've been working on the analysis of images with OpenCV, what I'm trying to do is recognize the lane dividing lines, what I do is:

1.I

  1. I receive an image, 2. image,
  2. Then grayscale transform 3.I transform
  3. I applying GaussianBlur 4. GaussianBlur
  4. After I get in the ROI 5.I ROI
  5. I apply the wily 6. wily
  6. After looking lines with lines Hough transform 7.Draw transform
  7. Draw lines obtained from the Hough

But I've run into a problem which is: it does not recognize dotted boundaries, nor does not always recognize the yellow lines. Someone give me an idea I've tried everything but can not get anything ...

I hope you help me solve this problem, you will thank a lot. I attached code and some sample images. #include "opencv2/highgui/highgui.hpp" #include <opencv2 objdetect="" objdetect.hpp=""> #include <opencv2 imgproc="" imgproc.hpp=""> #include <iostream> #include <vector> #include <stdio.h> #include "linefinder.h"

#define PI 3.1415926

using namespace cv;
using namespace std;

int main(int argc, char* argv[]) {
  int houghVote = 200;
  string arg = argv[1];
  Mat image;
  image = imread(argv[1]);  
  Mat gray;
  cvtColor(image,gray,CV_RGB2GRAY);
  GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
  vector<string> codes;
  Mat corners;
  findDataMatrix(gray, codes, corners);
  drawDataMatrixCodes(image, codes, corners);
  //Mat image = imread("");
  //Rect region_of_interest = Rect(x, y, w, h);
  //Mat image_roi = image(region_of_interest);
  std::cout << image.cols << "\n";
  std::cout << image.rows << "\n";
  Rect roi(0,200,640,206);
  Mat imgROI = image(roi);
  // Display the image
  imwrite("original.bmp", imgROI);
  // Canny algorithm
  Mat contours;
  Canny(imgROI, contours, 120, 300, 3); 
  imwrite("canny.bmp", contours);
  Mat contoursInv;
  threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

 /* 
 Hough tranform for line detection with feedback
 Increase by 25 for the next frame if we found some lines.  
 This is so we don't miss other lines that may crop up in the next frame
 but at the same time we don't want to start the feed back loop from scratch. 
 */
 std::vector<Vec2f> lines;
 if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset 
    houghVote = 200; 
 }/*else{ 
    houghVote += 25;
 } */
 while(lines.size() < 5 && houghVote > 0){
    HoughLines(contours,lines,1,PI/180, houghVote);
    houghVote -= 5;
 }
 std::cout << houghVote << "\n";
 Mat result(imgROI.size(),CV_8U,Scalar(255));
 imgROI.copyTo(result);
 // Draw the limes
 std::vector<Vec2f>::const_iterator it= lines.begin();
 Mat hough(imgROI.size(),CV_8U,Scalar(0));
 while (it!=lines.end()) {
    float rho= (*it)[0];   // first element is distance rho
    float theta= (*it)[1]; // second element is angle theta
    if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) { 
    // filter to remove   vertical and horizontal lines
        // point of intersection of the line with first row
        Point pt1(rho/cos(theta),0);        
        // point of intersection of the line with last row
        Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
        // draw a white line
        line( result, pt1, pt2, Scalar(255), 8); 
        line( hough, pt1, pt2, Scalar(255), 8);
    }
    ++it;
  }

  // Display the detected line image
  std::cout << "line image:"<< "\n";
  namedWindow("Detected Lines with Hough");
  imwrite("hough.bmp", result);

  // Create LineFinder instance
  LineFinder ld;

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(60,10);
  ld.setMinVote(4);

  // Detect lines
  std::vector<Vec4i> li= ld.findLines(contours);
  Mat houghP(imgROI.size(),CV_8U,Scalar(0));
  ld.setShift(0);
  ld.drawDetectedLines(houghP);
  std::cout << "First Hough" << "\n";
  imwrite("houghP.bmp", houghP);

  // bitwise AND of the two hough images
  bitwise_and(houghP,hough,houghP);
  Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
  Mat dst(imgROI.size(),CV_8U,Scalar(0));
  threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
  namedWindow("Detected Lines with Bitwise");
  imshow("Detected Lines with Bitwise", houghPinv);

  Canny(houghPinv,contours,100,350);
  li= ld.findLines(contours);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(5,2);
  ld.setMinVote(1);
  ld.setShift(image.cols/3);
  ld.drawDetectedLines(image);

  std::stringstream stream;
  stream << "Lines Segments: " << lines.size();

  putText(image, stream.str(), Point(10,image.rows-10), 2, 0.8, Scalar(0,0,255),0); 
  imwrite("processed.bmp", image);

  char key = (char) waitKey(10);
  lines.clear();
  }

Then I show the original image and the result

enter image description here

enter image description here

Detected lanes with Hough in OpenCV

Now I've been working on the analysis of images with OpenCV, what I'm trying to do is recognize the lane dividing lines, what I do is:

  1. I receive an image,
  2. Then grayscale transform
  3. I applying GaussianBlur
  4. After I get in the ROI
  5. I apply the wily
  6. After looking lines with lines Hough transform
  7. Draw lines obtained from the Hough

But I've run into a problem which is: it does not recognize dotted boundaries, nor does not always recognize the yellow lines. Someone give me an idea I've tried everything but can not get anything ...

I hope you help me solve this problem, you will thank a lot. I attached code and some sample images. images.

#include "opencv2/highgui/highgui.hpp"
 #include <opencv2 objdetect="" objdetect.hpp="">
    <opencv2/objdetect/objdetect.hpp>
#include <opencv2 imgproc="" imgproc.hpp="">
    <opencv2/imgproc/imgproc.hpp>
#include <iostream>
 #include <vector>
 #include <stdio.h>
 #include "linefinder.h"

"linefinder.h"

#define PI 3.1415926

using namespace cv;
using namespace std;

int main(int argc, char* argv[]) {
  int houghVote = 200;
  string arg = argv[1];
  Mat image;
  image = imread(argv[1]);  
  Mat gray;
  cvtColor(image,gray,CV_RGB2GRAY);
  GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
  vector<string> codes;
  Mat corners;
  findDataMatrix(gray, codes, corners);
  drawDataMatrixCodes(image, codes, corners);
  //Mat image = imread("");
  //Rect region_of_interest = Rect(x, y, w, h);
  //Mat image_roi = image(region_of_interest);
  std::cout << image.cols << "\n";
  std::cout << image.rows << "\n";
  Rect roi(0,200,640,206);
  Mat imgROI = image(roi);
  // Display the image
  imwrite("original.bmp", imgROI);
  // Canny algorithm
  Mat contours;
  Canny(imgROI, contours, 120, 300, 3); 
  imwrite("canny.bmp", contours);
  Mat contoursInv;
  threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

 /* 
 Hough tranform for line detection with feedback
 Increase by 25 for the next frame if we found some lines.  
 This is so we don't miss other lines that may crop up in the next frame
 but at the same time we don't want to start the feed back loop from scratch. 
 */
 std::vector<Vec2f> lines;
 if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset 
    houghVote = 200; 
 }/*else{ 
    houghVote += 25;
 } */
 while(lines.size() < 5 && houghVote > 0){
    HoughLines(contours,lines,1,PI/180, houghVote);
    houghVote -= 5;
 }
 std::cout << houghVote << "\n";
 Mat result(imgROI.size(),CV_8U,Scalar(255));
 imgROI.copyTo(result);
 // Draw the limes
 std::vector<Vec2f>::const_iterator it= lines.begin();
 Mat hough(imgROI.size(),CV_8U,Scalar(0));
 while (it!=lines.end()) {
    float rho= (*it)[0];   // first element is distance rho
    float theta= (*it)[1]; // second element is angle theta
    if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) { 
    // filter to remove   vertical and horizontal lines
        // point of intersection of the line with first row
        Point pt1(rho/cos(theta),0);        
        // point of intersection of the line with last row
        Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
        // draw a white line
        line( result, pt1, pt2, Scalar(255), 8); 
        line( hough, pt1, pt2, Scalar(255), 8);
    }
    ++it;
  }

  // Display the detected line image
  std::cout << "line image:"<< "\n";
  namedWindow("Detected Lines with Hough");
  imwrite("hough.bmp", result);

  // Create LineFinder instance
  LineFinder ld;

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(60,10);
  ld.setMinVote(4);

  // Detect lines
  std::vector<Vec4i> li= ld.findLines(contours);
  Mat houghP(imgROI.size(),CV_8U,Scalar(0));
  ld.setShift(0);
  ld.drawDetectedLines(houghP);
  std::cout << "First Hough" << "\n";
  imwrite("houghP.bmp", houghP);

  // bitwise AND of the two hough images
  bitwise_and(houghP,hough,houghP);
  Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
  Mat dst(imgROI.size(),CV_8U,Scalar(0));
  threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
  namedWindow("Detected Lines with Bitwise");
  imshow("Detected Lines with Bitwise", houghPinv);

  Canny(houghPinv,contours,100,350);
  li= ld.findLines(contours);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(5,2);
  ld.setMinVote(1);
  ld.setShift(image.cols/3);
  ld.drawDetectedLines(image);

  std::stringstream stream;
  stream << "Lines Segments: " << lines.size();

  putText(image, stream.str(), Point(10,image.rows-10), 2, 0.8, Scalar(0,0,255),0); 
  imwrite("processed.bmp", image);

  char key = (char) waitKey(10);
  lines.clear();
  }

Then I show the original image and the result

enter image description here

enter image description here

Detected lanes with Hough in OpenCV

Now I've been working on the analysis of images with OpenCV, what I'm trying to do is recognize the lane dividing lines, what I do is:

  1. I receive an image,
  2. Then grayscale transform
  3. I applying GaussianBlur
  4. After I get in the ROI
  5. I apply the wily
  6. After looking lines with lines Hough transform
  7. Draw lines obtained from the Hough

But I've run into a problem which is: it does not recognize dotted boundaries, nor does not always recognize the yellow lines. Someone give me an idea I've tried everything but can not get anything ...

I hope you help me solve this problem, you will thank a lot. I attached code and some sample images.

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
#include "linefinder.h"

#define PI 3.1415926

using namespace cv;
using namespace std;

int main(int argc, char* argv[]) {
  int houghVote = 200;
  string arg = argv[1];
  Mat image;
  image = imread(argv[1]);  
  Mat gray;
  cvtColor(image,gray,CV_RGB2GRAY);
  GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
  vector<string> codes;
  Mat corners;
  findDataMatrix(gray, codes, corners);
  drawDataMatrixCodes(image, codes, corners);
  //Mat image = imread("");
  //Rect region_of_interest = Rect(x, y, w, h);
  //Mat image_roi = image(region_of_interest);
  std::cout << image.cols << "\n";
  std::cout << image.rows << "\n";
  Rect roi(0,200,640,206);
  Mat imgROI = image(roi);
  // Display the image
  imwrite("original.bmp", imgROI);
  // Canny algorithm
  Mat contours;
  Canny(imgROI, contours, 120, 300, 3); 
  imwrite("canny.bmp", contours);
  Mat contoursInv;
  threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

 /* 
 Hough tranform for line detection with feedback
 Increase by 25 for the next frame if we found some lines.  
 This is so we don't miss other lines that may crop up in the next frame
 but at the same time we don't want to start the feed back loop from scratch. 
 */
 std::vector<Vec2f> lines;
 if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset 
    houghVote = 200; 
 }/*else{ 
    houghVote += 25;
 } */
 while(lines.size() < 5 && houghVote > 0){
    HoughLines(contours,lines,1,PI/180, houghVote);
    houghVote -= 5;
 }
 std::cout << houghVote << "\n";
 Mat result(imgROI.size(),CV_8U,Scalar(255));
 imgROI.copyTo(result);
 // Draw the limes
 std::vector<Vec2f>::const_iterator it= lines.begin();
 Mat hough(imgROI.size(),CV_8U,Scalar(0));
 while (it!=lines.end()) {
    float rho= (*it)[0];   // first element is distance rho
    float theta= (*it)[1]; // second element is angle theta
    if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) { 
    // filter to remove   vertical and horizontal lines
        // point of intersection of the line with first row
        Point pt1(rho/cos(theta),0);        
        // point of intersection of the line with last row
        Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
        // draw a white line
        line( result, pt1, pt2, Scalar(255), 8); 
        line( hough, pt1, pt2, Scalar(255), 8);
    }
    ++it;
  }

  // Display the detected line image
  std::cout << "line image:"<< "\n";
  namedWindow("Detected Lines with Hough");
  imwrite("hough.bmp", result);

  // Create LineFinder instance
  LineFinder ld;

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(60,10);
  ld.setMinVote(4);

  // Detect lines
  std::vector<Vec4i> li= ld.findLines(contours);
  Mat houghP(imgROI.size(),CV_8U,Scalar(0));
  ld.setShift(0);
  ld.drawDetectedLines(houghP);
  std::cout << "First Hough" << "\n";
  imwrite("houghP.bmp", houghP);

  // bitwise AND of the two hough images
  bitwise_and(houghP,hough,houghP);
  Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
  Mat dst(imgROI.size(),CV_8U,Scalar(0));
  threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
  namedWindow("Detected Lines with Bitwise");
  imshow("Detected Lines with Bitwise", houghPinv);

  Canny(houghPinv,contours,100,350);
  li= ld.findLines(contours);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(5,2);
  ld.setMinVote(1);
  ld.setShift(image.cols/3);
  ld.drawDetectedLines(image);

  std::stringstream stream;
  stream << "Lines Segments: " << lines.size();

  putText(image, stream.str(), Point(10,image.rows-10), 2, 0.8, Scalar(0,0,255),0); 
  imwrite("processed.bmp", image);

  char key = (char) waitKey(10);
  lines.clear();
  }

Then I show the original image and the result

enter image description here

enter image description here

Then I show the image obtained after modifying suggested, as seen already noticeable distinguishing small lines but I wish that distinguish each not only to form a line for all of them, actually modify the gap and also the angle by pi / 720

result image

Detected lanes with Hough in OpenCV

Now I've been working on the analysis of images with OpenCV, what I'm trying to do is recognize the lane dividing lines, what I do is:

  1. I receive an image,
  2. Then grayscale transform
  3. I applying GaussianBlur
  4. After I get in the ROI
  5. I apply the wily
  6. After looking lines with lines Hough transform
  7. Draw lines obtained from the Hough

But I've run into a problem which is: it does not recognize dotted boundaries, nor does not always recognize the yellow lines. Someone give me an idea I've tried everything but can not get anything ...

I hope you help me solve this problem, you will thank a lot. I attached code and some sample images.

#include "opencv2/highgui/highgui.hpp"
#include <opencv2/objdetect/objdetect.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <vector>
#include <stdio.h>
#include "linefinder.h"

#define PI 3.1415926

using namespace cv;
using namespace std;

int main(int argc, char* argv[]) {
  int houghVote = 200;
  string arg = argv[1];
  Mat image;
  image = imread(argv[1]);  
  Mat gray;
  cvtColor(image,gray,CV_RGB2GRAY);
  GaussianBlur( gray, gray, Size( 5, 5 ), 0, 0 );
  vector<string> codes;
  Mat corners;
  findDataMatrix(gray, codes, corners);
  drawDataMatrixCodes(image, codes, corners);
  //Mat image = imread("");
  //Rect region_of_interest = Rect(x, y, w, h);
  //Mat image_roi = image(region_of_interest);
  std::cout << image.cols << "\n";
  std::cout << image.rows << "\n";
  Rect roi(0,200,640,206);
  Mat imgROI = image(roi);
  // Display the image
  imwrite("original.bmp", imgROI);
  // Canny algorithm
  Mat contours;
  Canny(imgROI, contours, 120, 300, 3); 
  imwrite("canny.bmp", contours);
  Mat contoursInv;
  threshold(contours,contoursInv,128,255,THRESH_BINARY_INV);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

 /* 
 Hough tranform for line detection with feedback
 Increase by 25 for the next frame if we found some lines.  
 This is so we don't miss other lines that may crop up in the next frame
 but at the same time we don't want to start the feed back loop from scratch. 
 */
 std::vector<Vec2f> lines;
 if (houghVote < 1 or lines.size() > 2){ // we lost all lines. reset 
    houghVote = 200; 
 }/*else{ 
    houghVote += 25;
 } */
 while(lines.size() < 5 && houghVote > 0){
    HoughLines(contours,lines,1,PI/180, houghVote);
    houghVote -= 5;
 }
 std::cout << houghVote << "\n";
 Mat result(imgROI.size(),CV_8U,Scalar(255));
 imgROI.copyTo(result);
 // Draw the limes
 std::vector<Vec2f>::const_iterator it= lines.begin();
 Mat hough(imgROI.size(),CV_8U,Scalar(0));
 while (it!=lines.end()) {
    float rho= (*it)[0];   // first element is distance rho
    float theta= (*it)[1]; // second element is angle theta
    if ( theta > 0.09 && theta < 1.48 || theta < 3.14 && theta > 1.66 ) { 
    // filter to remove   vertical and horizontal lines
        // point of intersection of the line with first row
        Point pt1(rho/cos(theta),0);        
        // point of intersection of the line with last row
        Point pt2((rho-result.rows*sin(theta))/cos(theta),result.rows);
        // draw a white line
        line( result, pt1, pt2, Scalar(255), 8); 
        line( hough, pt1, pt2, Scalar(255), 8);
    }
    ++it;
  }

  // Display the detected line image
  std::cout << "line image:"<< "\n";
  namedWindow("Detected Lines with Hough");
  imwrite("hough.bmp", result);

  // Create LineFinder instance
  LineFinder ld;

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(60,10);
  ld.setMinVote(4);

  // Detect lines
  std::vector<Vec4i> li= ld.findLines(contours);
  Mat houghP(imgROI.size(),CV_8U,Scalar(0));
  ld.setShift(0);
  ld.drawDetectedLines(houghP);
  std::cout << "First Hough" << "\n";
  imwrite("houghP.bmp", houghP);

  // bitwise AND of the two hough images
  bitwise_and(houghP,hough,houghP);
  Mat houghPinv(imgROI.size(),CV_8U,Scalar(0));
  Mat dst(imgROI.size(),CV_8U,Scalar(0));
  threshold(houghP,houghPinv,150,255,THRESH_BINARY_INV); // threshold and invert to black lines
  namedWindow("Detected Lines with Bitwise");
  imshow("Detected Lines with Bitwise", houghPinv);

  Canny(houghPinv,contours,100,350);
  li= ld.findLines(contours);
  // Display Canny image
  imwrite("contours.bmp", contoursInv);

  // Set probabilistic Hough parameters
  ld.setLineLengthAndGap(5,2);
  ld.setMinVote(1);
  ld.setShift(image.cols/3);
  ld.drawDetectedLines(image);

  std::stringstream stream;
  stream << "Lines Segments: " << lines.size();

  putText(image, stream.str(), Point(10,image.rows-10), 2, 0.8, Scalar(0,0,255),0); 
  imwrite("processed.bmp", image);

  char key = (char) waitKey(10);
  lines.clear();
  }

Then I show the original image and the result

enter image description here

enter image description here

Then I show the image obtained after modifying suggested, as seen already noticeable distinguishing small lines but I wish that distinguish each not only to form a line for all of them, actually modify the gap and also the angle by pi / 720

result image