gpt4 book ai didi

c++ - 鸟瞰opencv

转载 作者:行者123 更新时间:2023-11-28 04:50:47 26 4
gpt4 key购买 nike

我想鸟瞰我用相机拍摄的图像,以便只显示白色车道。分辨率为 640x480。这是图片 - image from camera我所做的是首先应用直方图均衡器和二进制阈值,然后定义我将在 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);
}

而不是只得到两条平行线,我得到的是 - enter image description here

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

最佳答案

这是我的结果:

enter image description here


#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();
}

关于c++ - 鸟瞰opencv,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48264861/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com