Hzzone / pytorch-openpose

pytorch implementation of openpose including Hand and Body Pose Estimation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How can I fix the FPS at 10?

konntamonn opened this issue · comments

First of all, thank you for creating this code.
I am currently working on a video and the FPS value is not stable. Therefore, I would like to fix the FPS at 10.
I would like to know what position and what kind of code I should write.

I rewrote the code for generating videos, which might be helpful for you.

import cv2
import os
import glob
from tqdm import tqdm

# images route
root_path = os.path.abspath("./results_img")
# output vedio route
video_save_path = os.path.abspath("./frame2vedio")


def generateVedio(name_list):
    global video_save_path
    for i in tqdm(range(len(name_list))):
        person_name = name_list[i]
        frame_path = root_path + "/" + person_name
        image_files = glob.glob(frame_path + "/*.jpg")
        image_files.sort(key=lambda x: int(os.path.splitext(os.path.basename(x))[0].split("_")[-1]))

        size = (2304, 1440)
        fourcc = cv2.VideoWriter_fourcc(*"mp4v")
        # 20 is the FPS, you can change it
        videowrite = cv2.VideoWriter(video_save_path + "/" + person_name + ".mp4", fourcc, 20, size)
        img_array = []
        for filename in image_files:
            img = cv2.imread(filename)
            img_array.append(img)

        for j in range(len(image_files)):
            videowrite.write(img_array[j])

        print("视频{0}.mp4生成完毕!".format(person_name))


if __name__ == "__main__":
    name_list = os.listdir(root_path)
    print(name_list)
    generateVedio(name_list)

Add something like this in demo_camera.py cv2.imwrite('results_img/demo2/demo2_{}.jpg'.format(i), canvas) in order to reserve the images in a folder.