You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
645 B

import cv2 as cv
def candy(image_path):
# 加载模型
net = cv.dnn.readNetFromTorch('candy.t7')#选择一个模型的地址
# 读取图片
image = cv.imread(image_path)
(h, w) = image.shape[:2]
blob = cv.dnn.blobFromImage(image, 1, (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]+= 0
out[1]+= 0
out[2]+= 0
out /= 255
out = out.transpose(1, 2, 0)
out = out * 255
cv.imshow('result', out)
cv.waitKey(0)
cv.destroyAllWindows()