我希望鸟瞰我用相机拍摄的图像,以便只显示白色通道。分辨率为640x480。这是图像 - 我所做的是首先应用直方图均衡器和二进制阈值,然后定义我将在getPerspectiveTransform中使用的4个坐标和结果坐标。
barTest.cpp
然后应用warpPerspective -
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);
那么白色是如何影响我的结果的呢?我哪里错了?
答案 0 :(得分:0)
这是我的结果:
#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();
}