赞
踩
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的四个点坐标做了左右镜像的效果,可以看到透视变换的操作是可逆的,效果如下:
透视变换具有可逆性
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。