0

我应该使用 HoughLines 函数检测道路的两条白线。我使用三个轨迹条来找到仅检测道路的两条白线的最佳参数。我试过这个:(问题是即使我更改了轨迹栏的值,它也不会更新图像,它仍然是第一个值)。我正在使用带有 C++ 的 opencv。

没有轨迹栏它可以工作,但没有它几乎不可能找到好的值,因为我不知道如何调整参数并且图像非常复杂。

#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/calib3d.hpp>


using namespace cv;
using namespace std;

const int kernel_size = 3;

Mat src, src_gray;
Mat dst, detected_edges;
Mat cdst;

int slider_value_one;
int slider_value_two;
int slider_value_three;


vector<Vec2f> lines; // will hold the results of the detection

static void Hough_transform(int, void*)
{
    // Standard Hough Line Transform
    HoughLines(detected_edges, lines, 1, CV_PI/180, 130,slider_value_one,slider_value_two); // runs the actual detectio
    // Draw the lines
    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( cdst, pt1, pt2, Scalar(0,0,255), 3, CV_AA);
    }
    //printing
    imshow("standard Hough Line Transform", cdst);
}//HoughTransform



int main(int argc, const char * argv[]) {
    //-----Loads an image
    src = imread("/Users/massimilianolorenzin/Documents/Progetti\ XCode/lab4/lab4/lab4/images/road2.png");
    /// ---- CANNY DETECTOR
    /// Convert the image to grayscale
    cvtColor( src, src_gray, CV_BGR2GRAY);
    /// Reduce noise with a kernel 3x3
    blur( src_gray, detected_edges, Size(3,3) );
    /// Canny detector
    Canny( detected_edges, detected_edges, 150, 450, kernel_size );

    // Copy edges to the images that will display the results in BGR
    cvtColor(detected_edges, cdst, COLOR_GRAY2BGR);



    /// ---- HOUGH LINE TRANSFORM
    namedWindow("standard Hough Line Transform"); // Create Window

    //first TrackBar
    createTrackbar( "First Par", "standard Hough Line Transform", &slider_value_one, 200, Hough_transform);
    Hough_transform(slider_value_one,0 );

    //second TrackBar
    createTrackbar( "Second Par", "standard Hough Line Transform", &slider_value_two, 100, Hough_transform);
    Hough_transform(slider_value_two, 0 );

    //third TrackBar
    createTrackbar( "Third Par", "standard Hough Line Transform", &slider_value_three, 100, Hough_transform);
    Hough_transform( slider_value_three, 0 );
//printing
    imshow("Input Image",src);
    imshow( "edges", detected_edges );

    waitKey(0);
    return 0;

HoughLines() 看起来没有回答使用轨迹栏设置的值。窗口正常显示,slider_value_one、slider_value_two、slider_value_three 具有正确的值,因为我打印并看到了它们,所以我不明白为什么 HoughLines() 不采用传递的值。

4

1 回答 1

0

在此处输入图像描述

上面是输入图像,下面是最终输出。有人问我,在这一步中,只是为了在路边创建两条线,下一步要求为两条线之间的区域着色(如照片中所示)。

于 2019-04-22T10:02:27.003 回答