import cv2 as cv
import numpy as np
import time

img = cv.imread('\\Users\\hmzsh\\Pictures\\Fingerspelling Dataset\\A\\A00727.png')
cv.imshow('window',  img)
cv.waitKey(1)

# Give the configuration and weight files for the model and load the network.
config_path = "\\Users\\hmzsh\\Documents\\yoloImage\\cross-hands.cfg"
weights_path = "\\Users\\hmzsh\\Documents\\yoloImage\\cross-hands.weights"
net = cv.dnn.readNetFromDarknet(config_path, weights_path)
net.setPreferableBackend(cv.dnn.DNN_BACKEND_OPENCV)
# net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)

ln = net.getLayerNames()
print(len(ln), ln)

# construct a blob from the image
blob = cv.dnn.blobFromImage(img, 1/255.0, (416, 416), swapRB=True, crop=False)
r = blob[0, 0, :, :]

cv.imshow('blob', r)
text = f'Blob shape={blob.shape}'
cv.displayOverlay('blob', text)
cv.waitKey(1)

net.setInput(blob)
t0 = time.time()
outputs = net.forward(ln)
t = time.time()

cv.displayOverlay('window', f'forward propagation time={t-t0}')
cv.imshow('window',  img)
cv.waitKey(0)
cv.destroyAllWindows()

net.setInput(blob)
t0 = time.time()
outputs = net.forward(ln)
t = time.time()
