在做全景拼接的时候,为了保持图片中的空间约束与视觉的一致性,需要进行柱面投影,否则离中心图像距离越远的图像拼接后变形越大。
柱面投影公式为
int main(){cv::mat image1 = cv::imread("images/1.jpg", 1);if (!image1.data)return 0;imshow("image1", image1); mat imgout = mat(image1.rows, image1.cols, cv_8u柯岩c3);float w = image1.cols;float h = image1.rows;float f = 一光年是多少公里(w / 2) / atan(pi / 8); for (int i = 0; i < image1.rows; i++){for (int j = 0; j < image1.cols; j++){float x = j;float y = i;float x1 = f * atan((x - w / 2) / f) + f * atan(w / (2.0f * f));float y1 = f * (y - h / 2.0f) / sqrt((x - w / 2.0f) * (x - w / 2.0f) + f * f) + h / 2.0f; int col = (int)(x1 + 0.5f);//加0.5是为了四舍五入int row = (int)(y1 + 0.5f);//加0.5是为了四舍五入 if (col < image1.cols && row < image1.rows){imgout.at<vec3b>(row, c2021跨年图片ol)[0] = image1.at<vec3b>(i, j)[0];imgout.at<vec3b>(row, col)[1] = image1.at<vec3b>(i, j)[1];imgout.at<vec3b>(row, col)[2] = image1.at<vec3b>(i, j)[2];}}} imshow("imgout", imgout); waitkey(0);return 0;}
实现效果
cv::mat image1 = cv::imread("e:\\zcb_work\13\\pic2\\k.jpg", 0);if (!image1.data)return 0;imshow("image1", image1);cv::mat image2 = cv::imread("e:\\zcb_work\13\\pic2\\j.jpg", 0);if (!image2.data)return 0;imshow("imag中日甲午战争e2", image2); mat imgout1 = mat(image1.rows, image1.cols, cv_8uc1);imgout1.tto(0);mat imgout2 = mat(image2.rows, image2.cols, cv_8uc1);imgout2.tto(0);float w = image1.cols;float h = image1.rows;float f = (w / 2) / atan(pi / 8); for (int i = 0; i < image1.rows; i++){for 采购比价系统(int j = 0; j < image1.cols; j++){float x = j;float y = i;float x1 = f * atan((x - w / 2) / f) + f * atan(w / (2.0f * f));float y1 = f * (y - h / 2.0f) / sqrt((x - w / 2.0f) * (x - w / 2.0f) + f * f) + h / 2.0f; int col = (int)(x1 + 0.5f);//加0.5是为了四舍五入int row = (int)(y1 + 0.5f);//加0.5是为了四舍五入 if (col < image1.cols && row < image1.rows){imgout1.at<uchar>(row, col) = image1.at<uchar>(i, j);imgout2.at<uchar>(row, col) = image2.at<uchar>(i, j);//imgout.at<vec3b>(row, col)[1] = image1.at<vec3b>(i, j)[1];//imgout.at<vec3b>(row, col)[2] = image1.at<vec3b>(i, j)[2];}}} imshow("imgout1", imgout1);imshow("imgout2", imgout2);
实现效果
原图
柱面投影
用surf算法,特征检测,
合成这样,呵呵呵,
以上就是c语言 opencv实现柱面投影的详细内容,更多关于c语言 opencv柱面投影的资料请关注www.887551.com其它相关文章!
本文发布于:2023-04-04 07:17:17,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/bf447056919499e02ec11c457e48abab.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:C语言 OpenCV实现柱面投影.doc
本文 PDF 下载地址:C语言 OpenCV实现柱面投影.pdf
留言与评论(共有 0 条评论) |