【问题标题】:bird's eye view opencv鸟瞰opencv
【发布时间】:2018-01-15 14:19:05
【问题描述】:

我想要鸟瞰我用相机拍摄的图像,以便只显示白色车道。分辨率为 640x480。这是图片 - 我所做的是首先应用直方图均衡器和二进制阈值,然后定义我将在 getPerspectiveTransform 中使用的 4 个坐标和结果坐标。

    int bottom_leftx = 110;
    int bottom_lefty = 480;

    int upper_leftx = 260;
    int upper_lefty = 120;

    int upper_rightx = 410;
    int upper_righty = 120;

    int bottom_rightx = 560;
    int bottom_righty = 480;


    Point2f src_vertices[4];
    src_vertices[0] = Point(bottom_leftx, bottom_lefty);
    src_vertices[1] = Point(upper_leftx, upper_lefty);
    src_vertices[2] = Point(upper_righty, upper_righty);
    src_vertices[3] = Point(bottom_rightx, bottom_righty);


    Point2f dst_vertices[4];
    dst_vertices[0] = Point(0, 480);
    dst_vertices[1] = Point(0, 0);
    dst_vertices[2] = Point(640, 0);
    dst_vertices[3] = Point(640, 480);

然后应用warpPerspective -

void getBirdView(Point2f *p1, Point2f *p2, const Mat& src, Mat& dst) {
    Mat warpMatrix = getPerspectiveTransform(p1, p2);

    warpPerspective(src, dst, warpMatrix, dst.size(), INTER_LINEAR, BORDER_CONSTANT);
}

我得到的不是只有两条平行线,而是 -

那么白色是如何产生我的结果的呢?我哪里错了?

【问题讨论】:

    标签: c++ opencv


    【解决方案1】:

    这是我的结果:


    #include <opencv2/opencv.hpp>
    #include <iostream>
    using namespace cv;
    
    void transform(Point2f* src_vertices, Point2f* dst_vertices, Mat& src, Mat &dst){
        Mat M = getPerspectiveTransform(src_vertices, dst_vertices);
        warpPerspective(src, dst, M, dst.size(), INTER_LINEAR, BORDER_CONSTANT);
    }
    
    int main(){
        Mat src = imread("test.png");
    
        Point2f src_vertices[4];
        src_vertices[0] = Point(270,120);
        src_vertices[1] = Point(395, 120);
        src_vertices[2] = Point(560, 480);
        src_vertices[3] = Point(110, 480);
    
        Point2f dst_vertices[4];
        dst_vertices[0] = Point(0, 0);
        dst_vertices[1] = Point(640, 0);
        dst_vertices[2] = Point(640, 480);
        dst_vertices[3] = Point(0, 480);
    
        Mat M = getPerspectiveTransform(src_vertices, dst_vertices);
        Mat dst(480, 640, CV_8UC3);
        warpPerspective(src, dst, M, dst.size(), INTER_LINEAR, BORDER_CONSTANT);
    
        Mat dst2(480, 640, CV_8UC3);
        transform(src_vertices, dst_vertices, src, dst2);
    
    
        imshow("src", src);
        imshow("dst", dst);
        imshow("dst2", dst2);
        waitKey();
    }
    

    【讨论】:

    • 嗯,如果我这样做 - void getBirdView(Point2f *p1, Point2f *p2, Mat&amp; src, Mat&amp; dst) { Mat warpMatrix = getPerspectiveTransform(p1, p2); warpPerspective(src, dst, warpMatrix, dst.size(), INTER_LINEAR, BORDER_CONSTANT); } Mat rotated; getBirdView(src_vertices, dst_vertices, dst, rotated); 不起作用
    猜你喜欢
    • 1970-01-01
    • 2021-04-05
    • 2016-10-02
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 2013-03-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多