Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (17.6k points)

i have created a model for classification of two types of shoes

now how to deploy it in OpenCv (videoObject detection)??

thanks in advance

1 Answer

0 votes
by (17.6k points)

Using OpenCV DNN module:

import cv2

# Load a model imported from Tensorflow

tensorflowNet = cv2.dnn.readNetFromTensorflow('card_graph/frozen_inference_graph.pb', 'exported_pbtxt/output.pbtxt')

# Input image

img = cv2.imread('image.jpg')

rows, cols, channels = img.shape

# Use the given image as input, which needs to be blob(s).

tensorflowNet.setInput(cv2.dnn.blobFromImage(img, size=(300, 300), swapRB=True, crop=False))

# Runs a forward pass to compute the net output

networkOutput = tensorflowNet.forward()

# Loop on the outputs

for detection in networkOutput[0,0]:

    score = float(detection[2])

    if score > 0.9:

        left = detection[3] * cols

        top = detection[4] * rows

        right = detection[5] * cols

        bottom = detection[6] * rows

        #draw a red rectangle around detected objects

        cv2.rectangle(img, (int(left), int(top)), (int(right), int(bottom)), (0, 0, 255), thickness=2)

# Show the image with a rectagle surrounding the detected objects 

cv2.imshow('Image', img)



you need frozen inference graph and pbtxt file to run your model in OpenCV

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
2 answers
0 votes
1 answer
asked Mar 21, 2021 in Python by laddulakshana (16.4k points)
0 votes
2 answers

Browse Categories