OpenCV-风格迁移-五、示例代码

import cv2

image = cv2.imread('2.png')
cv2.imshow('yuan_tu', image)
cv2.waitKey(10000)
"图像处理"
(h, w) = image.shape[:2]

blod = cv2.dnn.blobFromImage(image, 1, (w, h), (0, 0, 0), swapRB=True, crop=False)

# 以下为各种类型的风格
# net = cv2.dnn.readNet(r'model\starry_night.t7')
# net = cv2.dnn.readNet(r'model\candy.t7')
# net = cv2.dnn.readNet(r'model\composition_vii.t7')
# net = cv2.dnn.readNet(r'model\feathers.t7')
# net = cv2.dnn.readNet(r'model\la_muse.t7')
# net = cv2.dnn.readNet(r'model\mosaic.t7')
# net = cv2.dnn.readNet(r'model\the_scream.t7')
# net = cv2.dnn.readNet(r'model\the_wave.t7')
net = cv2.dnn.readNet(r'model\udnie.t7')

net.setInput(blod)
# 对输入图像进行前向传播
out = net.forward()
# 将输出结果转换为合适的格式
out_new = out.reshape(out.shape[1], out.shape[2], out.shape[3])
# 对输入图像进行归一化
cv2.normalize(out_new, out_new, norm_type=cv2.NORM_MINMAX)
# 转置输出结果的维度
result = out_new.transpose(1, 2, 0)

cv2.imshow('Stylized Image', result)
cv2.waitKey(0)
cv2.destroyAllWindows()

注意:迁移风格的类型可以通过网盘链接: https://pan.baidu.com/s/1ekE1P_Sn4vryVS60qjmR1w?pwd=2b2v (提取码: 2b2v )获取。

上一篇:C++——AVL树-一、AVL树的概念


下一篇:【Postgresql】根据响应数据反向实现建表语句与insert语句