OpenCV图像风格迁移所用模板-Candy
使用方法:
import cv2
image_file = 'xxx.jpg' #目标文件
model = 'Candy.t7' #模板文件
net = cv2.dnn.readNetFromTorch('models/' + model)
image = cv2.imread('images/' + image_file)
(h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(image, 1.0, (w, h),
(103.939, 116.779, 123.680), swapRB=False, crop=False)
net.setInput(blob)
out = net.forward()
out = out.reshape(3, out.shape[2], out.shape[3])
out[0] += 103.939
out[1] += 116.779
out[2] += 123.68
out /= 255
out = out.transpose(1, 2, 0)
cv2.imshow('Image', out)
out *= 255.0
cv2.imwrite('output-' + model + '_' + image_file, out) #输出文件
cv2.waitKey(0)
cv2.destroyAllWindows()
该程序可以将Candy.t7模板的风格迁移到xxx.jpg中
2021-10-22 18:15:17
14.83MB
图像风格迁移
1