from __future__ import print_function
import cv2 as cv
import numpy as np
import argparse
def update_map(ind, map_x, map_y)
if ind == 0
for i in range(map_x.shape[0])
for j in range(map_x.shape[1])
if j > map_x.shape[1]*0.25 and j < map_x.shape[1]*0.75 and i > map_x.shape[0]*0.25 and i < map_x.shape[0]*0.75
map_x[i,j] = 2 * (j-map_x.shape[1]*0.25) + 0.5
map_y[i,j] = 2 * (i-map_y.shape[0]*0.25) + 0.5
其他:
map_x[i,j] = 0
map_y[i,j] = 0
elif ind == 1
for i in range(map_x.shape[0])
map_x[i,:] = [x for x in range(map_x.shape[1])]
for j in range(map_y.shape[1])
map_y[:,j] = [map_y.shape[0]-y for y in range(map_y.shape[0])]
elif ind == 2
for i in range(map_x.shape[0])
map_x[i,:] = [map_x.shape[1]-x for x in range(map_x.shape[1])]
for j in range(map_y.shape[1])
map_y[:,j] = [y for y in range(map_y.shape[0])]
elif ind == 3
for i in range(map_x.shape[0])
map_x[i,:] = [map_x.shape[1]-x for x in range(map_x.shape[1])]
for j in range(map_y.shape[1])
map_y[:,j] = [map_y.shape[0]-y for y in range(map_y.shape[0])]
parser = argparse.ArgumentParser(description='Remapping tutorial 相关代码。')
parser.add_argument('--input', help='输入图像路径。', default='chicky_512.png')
args = parser.parse_args()
if src is None
print('不能打开或找到图片: ', args.input)
exit(0)
map_x = np.zeros((src.shape[0], src.shape[1]), dtype=np.float32)
map_y = np.zeros((src.shape[0], src.shape[1]), dtype=np.float32)
window_name = 'Remap 演示'
ind = 0
while True
update_map(ind, map_x, map_y)
ind = (ind + 1) % 4
dst =
cv.remap(src, map_x, map_y, cv.INTER_LINEAR)
if c == 27
break
cv::String findFile(const cv::String &relative_path, bool required=true, bool silentMode=false)
尝试查找请求的数据文件。
void imshow(const String &winname, InputArray mat)
在指定的窗口中显示图像。
int waitKey(int delay=0)
等待按下的按键。
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
创建一个窗口。
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR)
从文件加载一张图片。