文件名称:图像风格迁移所用模板-starry_night.t7
文件大小:24.32MB
文件格式:T7
更新时间:2023-04-13 12:18:40
图像风格迁移
OpenCV图像风格迁移所用模板文件之starry_night.t7 使用代码: import cv2 image_file = xxx.jpg' #目标文件 model = 'starry_night.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.namedWindow('Image', cv2.WINDOW_NORMAL) cv2.imshow('Image', out) out *= 255.0 cv2.imwrite('output-' + model + '_' + image_file, out) #输出文件 cv2.waitKey(0) cv2.destroyAllWindows() 效果: 将starry_night.t7中的画风迁移到xxx.jpg中