Last active
February 21, 2023 18:17
-
-
Save joelselvaraj/5fffac1b144dff53f73200fd2eed7889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import cv2 | |
import os | |
from sys import platform | |
import argparse | |
import numpy as np | |
import json | |
try: | |
sys.path.append('/usr/local/python') | |
from openpose import pyopenpose as op | |
except ImportError as e: | |
print('Error: OpenPose library could not be found. Did you enable `BUILD_PYTHON` in CMake and have this Python script in the right folder?') | |
raise e | |
params = dict() | |
params["model_folder"] = "/home/joel/openpose/models/" | |
params["disable_blending"] = True #for black background | |
params["display"] = 0 | |
params["write_json"] = "/home/joel/jsonresults/" #json output folder for the video | |
try: | |
# Starting OpenPose | |
opWrapper = op.WrapperPython() | |
opWrapper.configure(params) | |
opWrapper.start() | |
# Process Image | |
datum = op.Datum() | |
cap = cv2.VideoCapture("/input/video/path.avi") | |
fps = cap.get(cv2.CAP_PROP_FPS) | |
video=None | |
count=0 #PREFIX FOR JSON output file | |
while (cap.isOpened()): | |
count=count+1 | |
hasframe, frame= cap.read() | |
if hasframe== True: | |
datum.cvInputData = frame | |
datum.name=str(count) #for each frame the count is prefixed for the output json file name. This way we get individual file for each frame. | |
opWrapper.emplaceAndPop([datum]) | |
opframe=datum.cvOutputData | |
height, width, layers = opframe.shape | |
if video == None: | |
fourcc = cv2.VideoWriter_fourcc('M', 'J', 'P', 'G') | |
video = cv2.VideoWriter(outputfilepath, fourcc, fps, (width, height)) | |
video.write(opframe) | |
else: | |
break | |
cv2.destroyAllWindows() | |
video.release() | |
except Exception as e: | |
print(e) | |
sys.exit(-1) | |
print("COMPLETED!!!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment