1

我正在尝试使用 Openpose 手部检测器( OpenPose Python Wrapper )。它由 tensorflow 制作,让我的 opencv videowriter 失败。

这是代码

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()

检测矩形

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

运行这些代码后,我得到一个 10.4 Mb output.mp4 但无法打开。(VLC 播放器)

注释掉错误行后

detection_graph, sess = detection_rectangles.load_inference_graph()

我有一个 10.5 Mb output.mp4,它可以成功播放....所以我想知道 tensorflow 是否会更改一些 opencv 配置或者我错过了什么?

4

0 回答 0