当前位置:网站首页>使用OpenCV实现哈哈镜效果
使用OpenCV实现哈哈镜效果
2022-07-22 05:18:00 【果州做题家】
使用OpenCV实现哈哈镜效果
导入工具包
import cv2
import numpy as np
import math
from vcam import vcam,meshGen
#导入python绘图matplotlib
import matplotlib.pyplot as plt
#使用ipython的魔法方法,将绘制出的图像直接嵌入在notebook单元格中
%matplotlib inline
#定义可视化图像函数
def look_img(img):
'''opencv读入图像格式为BGR,matplotlib可视化格式为RGB,因此需将BGR转RGB'''
img_RGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
plt.imshow(img_RGB)
plt.show()
单张图片的镜子效果
file = "./data/test01.jpg"
for mode in range(8):
# Reading the input image
img = cv2.imread(file)
img = cv2.resize(img,(300,300))
H,W = img.shape[:2]
# Creating the virtual camera object
c1 = vcam(H=H,W=W)
# Creating the surface object
plane = meshGen(H,W)
# We generate a mirror where for each 3D point, its Z coordinate is defined as Z = F(X,Y)
if mode == 0:
plane.Z += 20*np.exp(-0.5*((plane.X*1.0/plane.W)/0.1)**2)/(0.1*np.sqrt(2*np.pi))
elif mode == 1:
plane.Z += 20*np.exp(-0.5*((plane.Y*1.0/plane.H)/0.1)**2)/(0.1*np.sqrt(2*np.pi))
elif mode == 2:
plane.Z -= 10*np.exp(-0.5*((plane.X*1.0/plane.W)/0.1)**2)/(0.1*np.sqrt(2*np.pi))
elif mode == 3:
plane.Z -= 10*np.exp(-0.5*((plane.Y*1.0/plane.W)/0.1)**2)/(0.1*np.sqrt(2*np.pi))
elif mode == 4:
plane.Z += 20*np.sin(2*np.pi*((plane.X-plane.W/4.0)/plane.W)) + 20*np.sin(2*np.pi*((plane.Y-plane.H/4.0)/plane.H))
elif mode == 5:
plane.Z -= 20*np.sin(2*np.pi*((plane.X-plane.W/4.0)/plane.W)) - 20*np.sin(2*np.pi*((plane.Y-plane.H/4.0)/plane.H))
elif mode == 6:
plane.Z += 100*np.sqrt((plane.X*1.0/plane.W)**2+(plane.Y*1.0/plane.H)**2)
elif mode == 7:
plane.Z -= 100*np.sqrt((plane.X*1.0/plane.W)**2+(plane.Y*1.0/plane.H)**2)
else:
print("Wrong mode selected")
exit(-1)
# Extracting the generated 3D plane
pts3d = plane.getPlane()
# Projecting (Capturing) the plane in the virtual camera
pts2d = c1.project(pts3d)
# Deriving mapping functions for mesh based warping.
map_x,map_y = c1.getMaps(pts2d)
# Generating the output
output = cv2.remap(img,map_x,map_y,interpolation=cv2.INTER_LINEAR)
output = cv2.flip(output,1)
#look_img(output)
look_img(np.hstack((img,np.zeros((H,2,3),dtype=np.uint8),output)))
边栏推荐
- STM32 tutorial on using various sensors
- 1143. 最长公共子序列
- GD32F470之串口空闲中断+DMA篇
- 开源多云应用敏捷全链路技术平台Choerodon猪齿鱼发布0.23版本
- I, AI doctoral student, online crowdfunding research topic
- 【专题分享】汉得企业级PaaS平台HZERO之开源专题
- 1840. The highest building height is greedy
- 汉得企业级PaaS平台 HZERO 发布 1.5.0.RELEASE 版本
- AT4163 [ARC099D] Eating Symbols Hard
- ARC110F Esoswap
猜你喜欢
Codeforce D2. RGB substring (Hard version) Sliding Window
Digital path and practical thinking
UE4 植被工具的使用
SAP wper (POS interface monitor) idco posting voucher ALV Report
codeforce D2. RGB Substring (hard version) 滑動窗口
SAP WPER(POS接口监控器)IDCO过账凭证ALV报表
Thread series coordination principle
Ora-16525 DG broker not available
ORA-16525 dg broker不可用
跨域问题(CORS)详细说明和解决
随机推荐
opencv支持H264视频编码
UE4 地形工具的简单使用
1143. 最长公共子序列
线程系列协程原理
How to solve the problem of win10? The app store cannot be opened, and the error code is 0x80131500
1840. 最高建筑高度 贪心
HZERO企业级数字PaaS平台 (二)| 企业级权限体系
【红队】ATT&CK - 浏览器扩展实现持久化
[vs] how to check where the thread is blocked
SAP wper (POS interface monitor) idco posting voucher ALV Report
When the win10 system is turned on, the response is slower than usual. How to solve it by turning around and waiting for 1 minute?
Thread series coordination principle
Use ffmpeg to push and pull streams
Simple tutorial of STM32 control motor
汉得数字平台体系及试用知多少?
AT4379 [AGC027E] ABBreviate
ORA-16525 dg broker不可用
Tiktok tiktok get Tiktok video details interface
Contract awarding and use of NPM private server
还在写增删改查代码?直接一键生成