Tensorflow model in opencv

asked 2019-06-19 15:34:29 -0600

hgarg gravatar image

updated 2019-06-19 23:54:43 -0600

Hello, I have imported one tensorflow model (faster RCNN) in opencv and able to draw boxes around the objects using your code below:

cvNet = cv.dnn.readNetFromTensorflow('frozen_inference_graph.pb', 'graph.pbtxt')

img = cv.imread('example.png')
rows = img.shape[0]
cols = img.shape[1]
cvNet.setInput(cv.dnn.blobFromImage(img, size=(800, 600), swapRB=True, crop=False))
cvOut = cvNet.forward()

for detection in cvOut[0,0,:,:]:
    score = float(detection[2])
    if score > 0.25:
        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()

Now, can you please tell me how can I print the class name and prediction score along with the boxes. I want to get output like the image below:

https://user-images.githubusercontent...

Thank you

edit retag flag offensive close merge delete

Comments

This will help you solve your problem

eshirima gravatar imageeshirima ( 2019-06-20 00:27:29 -0600 )edit

About class name you must find class name file in the same site where you download weights and architecture

LBerger gravatar imageLBerger ( 2019-06-20 06:34:49 -0600 )edit

@eshirima thank you for sharing the link. I am able to print the labels now.

hgarg gravatar imagehgarg ( 2019-06-20 10:21:34 -0600 )edit

@LBerger thank you for your reply. I have the class name file and I am able to print them.

hgarg gravatar imagehgarg ( 2019-06-20 10:22:08 -0600 )edit