码迷,mamicode.com
首页 > 其他好文 > 详细

(24)像素重映射

时间:2018-12-29 19:39:11      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:input   size   src   iostream   users   detail   waitkey   wait   win   

所谓的像素重映射就是:我们对原图的每一个像素值进行提取,然后经过一个函数变换,映射到我们空白的目标图片上,就得到一张新的图片,这个就是像素重映射。具体的基础知识,看这个博客:https://blog.csdn.net/qq_41167777/article/details/84947439

===========================

 

下面这个代码运行,有好几种结果,主要就是,你按下 1,2,3,0,等等,会出现不同的图片展示。

 

===============================

 1 #include <opencv2/opencv.hpp>
 2 #include <iostream>
 3 using namespace std;
 4 using namespace cv;
 5 
 6 Mat src, dst, map_x, map_y;
 7 const char* input_win = "input";
 8 int index = 0;
 9 const char* out_put = "hough-line-detection";
10 void update_map(void);
11 int main(int agrc, char** agrv) {
12     src = imread("C:\\Users\\32829\\Desktop\\111.jpg");
13     if (!src.data) {
14         printf("no load..\n");
15         return -1;
16     }
17     namedWindow(input_win, CV_WINDOW_AUTOSIZE);
18     namedWindow(out_put, CV_WINDOW_AUTOSIZE);
19     imshow(input_win, src);
20     map_x.create(src.size(), CV_32FC1);
21     map_y.create(src.size(), CV_32FC1);
22     int c = 0;
23     while (true) {
24         c = waitKey(500);
25         if ((char)c == 27) {
26             break;
27         }
28         index = c % 4;
29         update_map();
30         remap(src, dst, map_x, map_y, CV_INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 255, 255));
31         imshow(out_put, dst);
32     }
33 }
34 void update_map(void) {
35     for (int row = 0; row < src.rows; row++) {
36         for (int col = 0; col < src.cols; col++) {
37             switch (index) {
38             case 0:
39                 if (col > (src.cols*0.25) && col<(src.cols*0.75) && row>(src.rows*0.25) && row < (src.rows*0.75)) {
40                     map_x.at<float>(row, col) = 2 * (col - (src.cols*0.25));
41                     map_y.at<float>(row, col) = 2 * (row - (src.rows*0.25));
42                 }
43                 else {
44                     map_x.at<float>(row, col) = 0;
45                     map_y.at<float>(row, col) = 0;
46                 }
47                 break;
48             case 1:
49                 map_x.at<float>(row, col) = (src.cols - col - 1);
50                 map_y.at<float>(row, col) = row;
51                 break;
52             case 2:
53                 map_x.at<float>(row, col) = col;
54                 map_y.at<float>(row, col) = (src.rows - row - 1);
55                 break;
56             case 3:
57                 map_x.at<float>(row, col) = (src.cols - col - 1);
58                 map_y.at<float>(row, col) = (src.rows - row - 1);
59                 break;
60             }
61         }
62     }
63 }

 

(24)像素重映射

标签:input   size   src   iostream   users   detail   waitkey   wait   win   

原文地址:https://www.cnblogs.com/xiaoyoucai/p/10197524.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!