Files
picar/car/GestureRecognition/opencvtensorflowex.py
Piv e577ad4011 Add 'car/' from commit 'eee0e8dc445691e600680f4abc77f2814b20b054'
git-subtree-dir: car
git-subtree-mainline: 1d29a5526c
git-subtree-split: eee0e8dc44
2020-04-19 11:07:44 +09:30

23 lines
757 B
Python

import cv2 as cv
cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'graph.pbtxt')
img = cv.imread('IMG_0825.jpg')
img = cv.resize(img, None, fx=0.1, fy=0.1, interpolation = cv.INTER_AREA)
rows = img.shape[0]
cols = img.shape[1]
print(str(rows) + " " + str(cols))
cvNet.setInput(cv.dnn.blobFromImage(img, size=(300, 300), swapRB=True, crop=False))
cvOut = cvNet.forward()
for detection in cvOut[0,0,:,:]:
score = float(detection[2])
if score > 0.6:
left = detection[3] * cols
top = detection[4] * rows
right = detection[5] * cols
bottom = detection[6] * rows
cv.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (23, 230, 210), thickness=2)
cv.imshow('img', img)
cv.waitKey()