赞
踩
- blobFromImage(image,
- scalefactor=None,
- size=None,
- mean=None,
- swapRB=None,
- crop=None,
- ddepth=None):
crop=True
,则,输入图片的尺寸调整resize后,一个边对应与 size 的一个维度,而另一个边的值大于等于 size 的另一个维度;然后从 resize 后的图片中心进行 crop. 如果crop=False
,则无需 crop,只需保持图片的长宽比- import cv2
- from cv2 import dnn
- import numpy as np
- import matplotlib.pyplot as plt
-
- img_cv2 = cv2.imread("test.jpeg")
- print("原图像大小: ", img_cv2.shape)
-
- inWidth = 256
- inHeight = 256
- outBlob1 = cv2.dnn.blobFromImage(img_cv2,
- scalefactor=1.0 / 255,
- size=(inWidth, inHeight),
- mean=(0, 0, 0),
- swapRB=False,
- crop=False)
- print("未裁剪输出: ", outBlob1.shape)
- outimg1 = np.transpose(outBlob1[0], (1, 2, 0))
-
- outBlob2 = cv2.dnn.blobFromImage(img_cv2,
- scalefactor=1.0 / 255,
- size=(inWidth, inHeight),
- mean=(0, 0, 0),
- swapRB=False,
- crop=True)
- print("裁剪输出: ", outBlob2.shape)
- outimg2 = np.transpose(outBlob2[0], (1, 2, 0))
-
- plt.figure(figsize=[10, 10])
- plt.subplot(1, 3, 1)
- plt.title('输入图像', fontsize=16)
- plt.imshow(cv2.cvtColor(img_cv2, cv2.COLOR_BGR2RGB))
- plt.axis("off")
- plt.subplot(1, 3, 2)
- plt.title('输出图像 - 未裁剪', fontsize=16)
- plt.imshow(cv2.cvtColor(outimg1, cv2.COLOR_BGR2RGB))
- plt.axis("off")
- plt.subplot(1, 3, 3)
- plt.title('输出图像 - 裁剪', fontsize=16)
- plt.imshow(cv2.cvtColor(outimg2, cv2.COLOR_BGR2RGB))
- plt.axis("off")
- plt.show()
- NMSBoxes(bboxes,
- scores,
- score_threshold,
- nms_threshold,
- eta=None,
- top_k=None)
readNet(model, config=None, framework=None)
*.caffemodel
(Caffe)、*.pb
(TensorFlow)、*.t7
或 *.net
(Torch)、 *.weights
(Darknet)、*.bin
(DLDT).*.prototxt
(Caffe)、*.pbtxt
(TensorFlow)、*.cfg
(Darknet)、*.xml
(DLDT).readNetFromCaffe(prototxt, caffeModel=None)
readNetFromDarknet(cfgFile, darknetModel=None)
readNetFromTensorflow(model, config=None)
readNetFromTorch(model, isBinary=None)
readNetFromONNX(onnxFile)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。