I have used net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)
and then looping through the live video frames to get the outputs for each frames using net.forward()
.
But the net.forward()
takes 7 to 10 seconds for each frames to give the result. Please help me how to improve the performance (reduce the time taking to process in net.forward()
).
Means: From Step1 to Step2 takes 7 to 10 seconds for each frames.
(Step1 and Step2 are mentioned in the below code).
import cv2
import time
import numpy as np
protoFile = "deploy.prototxt"
weightsFile = "iter_10.caffemodel"
inWidth = 300
inHeight = 300
# web camera
cap = cv2.VideoCapture(0)
hasFrame, frame = cap.read()
net = cv2.dnn.readNetFromCaffe(protoFile, weightsFile)
k = 0
while 1:
k+=1
t = time.time()
print("Start time = {}".format(t))
hasFrame, frame = cap.read()
if not hasFrame:
cv2.waitKey()
print("Wait====>")
break
inpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight),
(0, 0, 0), swapRB=False, crop=False)
net.setInput(inpBlob)
# Step1
print("before forward = {}".format(time.time() - t))
output = net.forward()
# Step2
#taking close to 7 to 10 seconds for each frame
print("forward = {}".format(time.time() - t))