cv2.dnn.blobFromImage()处理速度很慢!

OpenCV自带的,用于预处理的函数cv2.dnn.blobFromImage(),处理速度很慢!

测试代码:

start = time.time()
# Normalization + Swap RB + Layout from HWC to NCHW
# blob = cv2.dnn.blobFromImage(letterbox_img, 1/255.0, swapRB=True)
blob_img = np.float32(letterbox_img) / 255.0
blob = np.expand_dims(blob_img.transpose((2,0,1)),0)
preprocess_time = time.time()
print(f"preprocess time: {(preprocess_time - start)*1000}ms")

用cv2.dnn.blobFromImage()的运行结果:preprocess time: 4.48ms
用blob_img = np.float32(letterbox_img) / 255.0 和 blob = np.expand_dims(blob_img.transpose((2,0,1)),0) 两行代码实现同样的功能:preprocess time:2.12ms

结论:cv2.dnn.blobFromImage(),处理速度很慢,用numpy函数代替

你可能感兴趣的:(cv2.dnn.blobFromImage()处理速度很慢!)