当前位置:   article > 正文

opencv逆透视c语言算法,OpenCV4.1.0透视变换的基本操作

opencv逆透视变换标定

C++:透视变换,代码如下:

void contrast() {

VideoCapture capture(0);

Mat frame;

int cap_w = capture.get(CV_CAP_PROP_FRAME_WIDTH);

int cap_h = capture.get(CV_CAP_PROP_FRAME_HEIGHT);

int cx = 531, cy = 125, dx = 531, dy = 389, ax = 95, ay = 120, bx = 85, by = 383;

if (capture.isOpened()) {

while (true) {

capture >> frame;

imshow("frame", frame);

Point2f AffinePoints0[4] = { Point2f(cap_w, 0), Point2f(cap_w, cap_h), Point2f(0, 0), Point2f(0, cap_h) };

Point2f AffinePoints1[4] = { Point2f(ax, ay), Point2f(bx, by), Point2f(cx, cy), Point2f(dx, dy) };

Mat dst_perspective = PerspectiveTrans(frame, AffinePoints0, AffinePoints1);

imshow("dst_perspective", dst_perspective);

Mat dst_perspective_back = PerspectiveTrans(dst_perspective, AffinePoints1, AffinePoints0);

imshow("back", dst_perspective_back);

waitKey(10);

}

}

else {

printf("open failed!\n");

}

}

我这里AffinePoints1的四个点坐标做了左右镜像的效果,可以看到透视变换的操作是可逆的,效果如下:

a36a71b5a1d3d0d43a3c2c0416597baa.png 透视变换具有可逆性

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/153341
推荐阅读
相关标签
  

闽ICP备14008679号