1

I'm trying to use Openpose hand detector ( OpenPose Python Wrapper ). It made by tensorflow and let my opencv videowriter fail.

Here is the code

import detection_keypoints
import detection_rectangles
import cv2
cap = cv2.VideoCapture('video.mp4')
im_width, im_height = (int(cap.get(3)), int(cap.get(4)))
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter('./output.mp4', fourcc, 20.0, (int(cap.get(3)),int(cap.get(4))))
detection_graph, sess = detection_rectangles.load_inference_graph() # error line
success, frame = cap.read()
while success:
        success, frame = cap.read()  # get the next frame of the video
        cv2.rectangle(frame, (50, 50), (100, 100), (255, 0, 0), 2, 1)
        out.write(frame)  # write one frame into the output video

cv2.destroyAllWindows()  # close all the widows opened inside the program
cap.release()

detection_rectangles

def load_inference_graph():
    # load frozen tensorflow model into memory
    print("> ====== loading HAND frozen graph into memory")
    gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.33)
    detection_graph = tf.Graph()
    with detection_graph.as_default():
        od_graph_def = tf.GraphDef()
        with tf.gfile.GFile(PATH_TO_CKPT, 'rb') as fid:
            serialized_graph = fid.read()
            od_graph_def.ParseFromString(serialized_graph)
            tf.import_graph_def(od_graph_def, name='')
        sess = tf.Session(graph=detection_graph, config=tf.ConfigProto(gpu_options=gpu_options))
    print(">  ====== Hand Inference graph loaded.")
    return detection_graph, sess

After running these codes I get a 10.4 Mb output.mp4 But it can't be opened.(VLC player)

After comment out the error line

detection_graph, sess = detection_rectangles.load_inference_graph()

I got a 10.5 Mb output.mp4 and it could play successfully.... So I am wondering does tensorflow change some opencv configs or I miss something ?

Terry shu
  • 73
  • 1
  • 1
  • 4

0 Answers0