Ask Your Question

duc.d.k's profile - activity

2015-05-16 22:22:27 -0600 received badge  Enthusiast
2015-05-14 04:02:29 -0600 commented question vector subscript out of range when finding the intersection point of two lines

oh, the input line has lines.size =2. So vector<point> endP has 4 points (endP[0], endP[1], endP[2],endP[3]) as your comment. You can refer the code at https://github.com/NamanCMU/Lane-Mark.... I use it for my lane tracking project.</point>

2015-05-14 03:31:01 -0600 commented question vector subscript out of range when finding the intersection point of two lines

Hi berak, Lines was found by the houghline function as before and these are converted the polar coordinates to Cartesian coordinates by vector<point> endPoints. We had 3 points (x,d1,d2) to finding the Vanishing Point. Could you please give your advance more detail? What the change that I need to do?

2015-05-13 22:33:23 -0600 asked a question vector subscript out of range when finding the intersection point of two lines

Hi all, I alway see the above error when running findIntersection function, bool laneDetection::findIntersection(vector<point> endP, Point& pi). Please see to my code and give me your advances. I appreciated for your helps!

// Draw Lines on the image

Mat laneDetection::drawLines(Mat img, vector<vec2f> lines, string name){

Mat imgRGB;
cvtColor(img,imgRGB,CV_GRAY2RGB); // converting the image to RGB for display
vector<Point> endPoints;

// Here, I convert the polar coordinates to Cartesian coordinates.
// Then, I extend the line to meet the boundary of the image.
for (int i = 0;i < lines.size();i++){
    float r = lines[i][0];
    float t = lines[i][1];

    float x = r*cos(t);
    float y = r*sin(t);

    Point p1(cvRound(x - 1.0*sin(t)*1000), cvRound(y + cos(t)*1000));
    Point p2(cvRound(x + 1.0*sin(t)*1000), cvRound(y - cos(t)*1000));

    clipLine(img.size(),p1,p2);
    if (p1.y > p2.y){
        endPoints.push_back(p1);
        endPoints.push_back(p2);
    }
    else{
        endPoints.push_back(p2);
        endPoints.push_back(p1);
    }

}

///// Finding the intersection point of two lines to plot only lane markings till the intersection
Point pint;
bool check = findIntersection(endPoints,pint);

if (check){
    line(imgRGB,endPoints[0],pint,Scalar(0,255,255),5);
    line(imgRGB,endPoints[2],pint,Scalar(0,255,255),5);
}   
/////

// Saving to intercepts.csv
float xIntercept = min(endPoints[0].x,endPoints[2].x);
myfile << name << "," << xIntercept * 2 << "," << pint.x * 2 << endl;

visualize(imgRGB); // Visualize the final result

return imgRGB;

}

// Finding the Vanishing Point bool laneDetection::findIntersection(vector<point> endP, Point& pi){

Point x = endP[2] - endP[0];
Point d1 = endP[1] - endP[0];
Point d2 = endP[3] - endP[2];

float cross = d1.x*d2.y - d1.y*d2.x;
if (abs(cross) < 1e-8) // No intersection
    return false;

double t1 = (x.x * d2.y - x.y * d2.x)/cross;
pi = endP[0] + d1 * t1;
return true;

}

2015-04-17 00:31:50 -0600 asked a question extract the lane markings

Please review my code and tell me your advance because I cannot run this code. It alway return the below error: src CXX0017: Error: symbol “src” not found

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include <math.h>

using namespace cv;
void LaneMarkingsDetector(Mat &srcGray, Mat &dstGray, int tau)
    {
        dstGray.setTo(0);
        int aux = 0;
        for (int j=0; j<srcGray.rows; ++j)
        {
            unsigned char *ptRowSrc = srcGray.ptr<uchar>(j);
            unsigned char *ptRowDst = dstGray.ptr<uchar>(j);
            for (int i=tau; i<srcGray.cols - tau; ++i)
            {
                if ( ptRowSrc[i]!=0)
                {
                    aux = 2*ptRowSrc[i];
                    aux += -ptRowSrc[i-tau];
                    aux += -ptRowSrc[i+tau];
                    aux += -abs((int)(ptRowSrc[i-tau] - ptRowSrc[i+tau]));
                    aux = (aux<0)?(0):(aux);
                    aux = (aux>255)?(255):(aux);
                    ptRowDst[i] = (unsigned char)aux;
                }
            }
        }
    } 

int main(int argc, char** argv)
{
    Mat dst, gray_dst,cdst;
    Mat src = imread("street.jpg");
    cvtColor(src, gray_dst, CV_RGB2GRAY);
    namedWindow( "Source", 1 );
    namedWindow( "laneMarkingsDetector", 1 );
    //Canny(src, gray_dst, 50, 200, 3);
    LaneMarkingsDetector(gray_dst,dst, 1);
    imshow( "Source", gray_dst );

    //imshow( "laneMarkingsDetector", dst );

    waitKey(0);
    return 0;
}

I referred the LaneMarkingsDetector function in the post of "Lane markings detection and vanishing point detection with OpenCV" Marcos Nieto Thank so much!