当前位置:网站首页>22. pixel remapping
22. pixel remapping
2022-06-26 01:35:00 【Nightmare satiety】
#include <opencv2/opencv.hpp>
#include <iostream>
#include <math.h>
using namespace cv;
Mat src, dst, map_x, map_y;
const char* OUTPUT_TITLE = "remap demo";
int index = 0;
void update_map(void);
int main(int argc, char** argv) {
src = imread("../../source/lena.png");
if (!src.data) {
printf("could not load image...\n");
return -1;
}
char input_win[] = "input image";
namedWindow(input_win, WINDOW_AUTOSIZE);
namedWindow(OUTPUT_TITLE, WINDOW_AUTOSIZE);
imshow(input_win, src);
map_x.create(src.size(), CV_32FC1);
map_y.create(src.size(), CV_32FC1);
int c = 0;
while (true) {
c = waitKey(500);
if ((char)c == 27) {
break;
}
index = c % 4;
update_map();
remap(src, dst, map_x, map_y, INTER_LINEAR, BORDER_CONSTANT, Scalar(0, 255, 255));
imshow(OUTPUT_TITLE, dst);
}
return 0;
}
void update_map(void) {
for (int row = 0; row < src.rows; row++) {
for (int col = 0; col < src.cols; col++) {
switch (index) {
case 0:
if (col > (src.cols * 0.25) && col <= (src.cols*0.75) && row > (src.rows*0.25) && row <= (src.rows*0.75)) {
map_x.at<float>(row, col) = 2 * (col - (src.cols*0.25));
map_y.at<float>(row, col) = 2 * (row - (src.rows*0.25));
}
else {
map_x.at<float>(row, col) = 0;
map_y.at<float>(row, col) = 0;
}
break;
case 1:
map_x.at<float>(row, col) = (src.cols - col - 1);
map_y.at<float>(row, col) = row;
break;
case 2:
map_x.at<float>(row, col) = col;
map_y.at<float>(row, col) = (src.rows - row - 1);
break;
case 3:
map_x.at<float>(row, col) = (src.cols - col - 1);
map_y.at<float>(row, col) = (src.rows - row - 1);
break;
}
}
}
}
边栏推荐
- Computer network knowledge summary (interview)
- 2022年电气试验考试试题模拟考试平台操作
- Shengxin weekly issue 33
- [Excel知识技能] Excel数据类型
- "Hot post" Statistics
- Complete review (including syntax) -- MySQL regular expressions
- Nacos registry
- Data analysis slicer, PivotTable and PivotChart (necessary in the workplace)
- Oracle常用的基础命令
- MySQL例题一 综合案例(多条件组合查询)
猜你喜欢

FIFO code implemented in C language

The overall process of adding, deleting, modifying and querying function items realized by super detailed SSM framework

Dgus new upgrade: fully support digital video playback function

I2C protocol

马斯克 VS 乔布斯,谁是21世纪最伟大的创业家

Region of Halcon: generation of multiple regions (4)

Digital circuit - adder

Shengxin weekly issue 34

Web information collection, naked runners on the Internet

Redis之Strings命令
随机推荐
STM32GPIO
马斯克 VS 乔布斯,谁是21世纪最伟大的创业家
Reading notes on how to connect the network - hubs, routers and routers (III)
MOS管防倒灌电路设计及其过程分析
Oracle数据库完全卸载步骤(暂无截图)
containerd客户端比较
Containerd client comparison
MySQL例题一 综合案例(多条件组合查询)
[flower carving experience] 11 start esp32c3
vite打包构建时 @charset utf-8警告问题处理;
Camera - 02 image sensor
完整复习(包含语法)--MYSQL正则表达式
Maze walking
Idempotence of interfaces -- talk about idempotence of interfaces in detail, that is, solutions
Region of Halcon: generation of multiple regions (4)
Shengxin weekly issue 34
Duck feeding data instant collection solution resources
15 `bs object Node name Node name String` get nested node content
JSON basic syntax
From query database performance optimization to redis cache - talk about cache penetration, avalanche and breakdown