Forums

i am not able to put text in a video? Although there is no error in the code that i have written but still i can't see any text

[edited by admin: formatting]

import tensorflow as tf
import cv2

fn_list=[]

# Capture video from file

cap = cv2.VideoCapture('test_lego.wmv')
image_path = '/home/shorav/tfClassifier/new_capture.jpg'

label_lines = [line.rstrip() for line
                  in tf.gfile.GFile("final_labels.txt")]

with tf.gfile.FastGFile("./final_graph.pb", 'rb') as f:
    graph_def = tf.GraphDef()                
    graph_def.ParseFromString(f.read())
    _ = tf.import_graph_def(graph_def, name='')
    Frame_number=0

while True:
    ret, frame = cap.read()

    if ret == True:
        Frame_number+=1

        fn_list.append(Frame_number)

        print "frame number is :", Frame_number


        gray = cv2.cvtColor(frame,cv2.COLOR_RGB2GRAY)
        ret,thresh= cv2.threshold(gray,100,255,cv2.THRESH_BINARY)
        contours, hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
        c = max(contours, key = cv2.contourArea)
        x,y,w,h = cv2.boundingRect(c)
        font = cv2.FONT_HERSHEY_SIMPLEX


        #cv2.drawContours(gray,contours,-1, (0,255,255), 2)
        for contour in contours:
            [x,y,w,h] = cv2.boundingRect(contour)
            cv2.rectangle(gray,(x,y),(x+w,y+h),(255,0,255),2)


            cv2.putText(frame,'Show the text',(100,50), font, 1, (0,255,0), 4,cv2.CV_AA)    
            cv2.imshow('frame',gray)
        if (Frame_number%10==0):
            cv2.imwrite('new_capture.jpg',frame)
            image_data = tf.gfile.FastGFile(image_path, 'rb').read()
            with tf.Session() as sess:
                    softmax_tensor = sess.graph.get_tensor_by_name('final_result:0')
                    predictions = sess.run(softmax_tensor, \
                             {'DecodeJpeg/contents:0': image_data})
                    top_k = predictions[0].argsort()[-len(predictions[0]):][::-1]
                    score_results=[]
                    final_label=[]
                    for node_id in top_k:
                        human_string = label_lines[node_id]
                        score = predictions[0][node_id]
                        print('%s (score = %.5f)' % (human_string, score))
                        score_results.append(score)
                        final_label.append(human_string)

            if cv2.waitKey(50) & 0xFF == ord('q'):
                break


    else:
         break
cap.release()
cv2.destroyAllWindows()

Hi there,

What is the text that you expect to see, which line of the code is supposed tot produce it, and what happens when you run the above code?

Conrad