Real time detection of curved lines with Hough Transform

Hi, I have to perform real time detection of curved lines on a video feed. I have try Hough Transform but it is not working to me, the detected lines are too fragmented. I have read I should use “General Hough Transform” instead of Hough Transform, but I do not know where to start. This is the code that I have at the moment:


// in header, edge and mergedLines are defined as ofImage.

void Filter::update(const ofVideoPlayer &video){
    reset(); // clean everything

    if(video.isFrameNew()) {
        //apply blur using ofxBlurUtils
        applyBlur(video);
        blurredVideoFbo.readToPixels(blurredPixels);
        convertColor(blurredPixels, gray, CV_RGB2GRAY);

        //canny detection using ofxCv
        Canny(gray, edge, (double)cannyThreshold1.get(),
                          (double)cannyThreshold2.get(), 3);
        gray.update();
        edge.update();
        // this function merge the top border and the bottom border of the lines
        // into one. This is because the edge detection is returning the contour of the line,
        // but I need a line of 1 pixel.
        mergeLines(edge);
        applyHough(mergedLines);

    }
}

void Filter::applyBlur(const ofVideoPlayer &video){
    blurredVideoFbo.begin();
    blur.begin();
    // the blur effect is flipping the image upside down. Revert it
    //gray.draw(0,videoHeight, videoWidth, -videoHeight);
    video.draw(0,videoHeight, videoWidth, -videoHeight);
    //video.draw(0,0, videoWidth, videoHeight);
    blur.endRGB();
    blurredVideoFbo.end();
}

void Filter::applyHough(const ofImage& mergeLines){
    convertColor(mergedLines, mergedLinesBn, CV_RGB2GRAY);

    // https://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/hough_lines/hough_lines.html?highlight=hough%20transform
    // to do, pass the merged lines instead of the edge one
    // add parameters.
    auto threshMat = toCv(mergedLinesBn);
    HoughLinesP(threshMat, lines, threshold, CV_PI/180, 10, minLineLength, maxLineGap);
};

void Filter::reset(){
    mergedLines.setColor(ofColor(0));
    lines.clear();
}

void Filter::draw()
        ofBackground(0);
        ofSetColor(255);
        ofSetLineWidth(1);
        for( size_t i = 0; i < lines.size(); i++ ){
            Vec4i l = lines[i];
            ofDrawLine(l[0], l[1], l[2], l[3]);
        }
}

I am using ofxCV by @kylemcdonald. I have found these resources online https://docs.opencv.org/3.4/d2/d15/group__cudaimgproc__hough.html, https://github.com/opencv/opencv/blob/master/samples/gpu/generalized_hough.cpp.

In these two articles it is described a real time approach for detecting curves, and it is more or less what I am doing, (besides the fact that my lines are horizontal, white on a black background) meaning grayscale conversion and canny edge detection (i do not need to select the region of interest, luckily enough).

https://medium.com/@mrhwick/simple-lane-detection-with-opencv-bfeb6ae54ec0, but it does not work good with curved lines.

Does someone have experience with this topic? does it worth to check GeneralizedHoughBallard or it is not the right approach for realtime? (i do not have cuda on this machine)

PS. I have already read Using pattern recognition to identify random shapes but same category by @Hennio but it covers a different scenario.