Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Cylindrical projection by OpenCV in C language

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

It is believed that many inexperienced people don't know what to do about how to realize cylindrical projection in OpenCV in C language. therefore, this paper summarizes the causes and solutions of the problem. I hope you can solve this problem through this article.

Preface

When doing panoramic stitching, in order to maintain the consistency of spatial constraints and vision in the picture, it is necessary to carry out cylindrical projection, otherwise the more distant from the central image, the greater the deformation after stitching.

The cylindrical projection formula is

The implementation code is for color images 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_8UC3); 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(row, col)[0] = image1.at(i, j)[0]; imgOut.at(row, col)[1] = image1.at(i, j)[1]; imgOut.at(row, col)[2] = image1.at(i, j)[2]; } } } imshow("imgOut", imgOut); waitKey(0); return 0;} 实现效果

For grayscale images cv::Mat image1 = cv::imread ("E:\ zcb_work\ 2113\ pic2\ k.jpg", 0); if (! image1.data) return 0; imshow ("image1", image1); cv::Mat image2 = cv::imread ("E:\ zcb_work\ 2113\ pic2\ j.jpg", 0) If (! image2.data) return 0; imshow ("image2", image2); Mat imgOut1 = Mat (image1.rows, image1.cols, CV_8UC1); imgOut1.setTo (0); Mat imgOut2 = Mat (image2.rows, image2.cols, CV_8UC1); imgOut2.setTo (0); float w = image1.cols; float h = image1.rows Float f = (w / 2) / atan (PI / 8); for (int I = 0; I < image1.rows; iTunes +) {for (int j = 0; j < image1.cols; jacks +) {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); / / add 0.5 to round int row = (int) (y1 + 0.5f) / / add 0.5 to round if (col < image1.cols & & row < image1.rows) {imgOut1.at (row, col) = image1.at (I, j); imgOut2.at (row, col) = image2.at (I, j) / / imgOut.at (row, col) [1] = image1.at (I, j) [1]; / / imgOut.at (row, col) [2] = image1.at (I, j) [2];} imshow ("imgOut1", imgOut1) Imshow ("imgOut2", imgOut2)

Realize the effect

Original drawing

Cylindrical projection

Using surf algorithm, feature detection

Synthesize it like this, hehe

After reading the above, have you mastered how to achieve cylindrical projection with OpenCV in C language? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report