TadasBaltrusaitis / OpenFace

OpenFace – a state-of-the art tool intended for facial landmark detection, head pose estimation, facial action unit recognition, and eye-gaze estimation.
Other
6.71k stars 1.82k forks source link

How to output csv file from input mp4 using openfaceoffline? #1084

Open limchengwei opened 1 month ago

limchengwei commented 1 month ago

Hi, I would like to input mp4 video(s) and wish to get the CSV outputs? I have tried the code below, but I did not get CSV file in output_directory path? Help please, thank you.

import subprocess
import os

def process_video(video_path):
    # Check if the video file exists
    if not os.path.isfile(video_path):
        print(f"Error: Video file '{video_path}' not found.")
        return

    # Run OpenFaceOffline.exe with the video file
    result = subprocess.run(["OpenFaceOffline.exe", "FaceLandmarkVid.exe", "-f", video_path, "-out_dir", "output_directory"], capture_output=True)

    # Print the output
    print(result.stdout.decode())
    print(result.stderr.decode())

if __name__ == "__main__":
    # Specify the path to the MP4 video file
    video_path = "C:/Users/XXX/OneDrive/Desktop/Gaze.mp4"

    # Process the video file with OpenFaceOffline
    process_video(video_path)
beibidesr commented 4 weeks ago

coffused about this problem

kendrew06 commented 4 weeks ago

您的邮件我已收到,有需要会尽快回复This is an automatic reply, confirming that your e-mail was received.Thank you

brmarkus commented 4 weeks ago

@limchengwei when you run one of the samples, do you get the expected output? And then you want to integrate (parts of) OpenFace into your application?

limchengwei commented 4 weeks ago

Hi, I would like to use python script to input MP4 videos to get the CSV outputs. Kindly help me.

brmarkus commented 4 weeks ago

Have you found a working base already? When you found one of the samples to provide what you want, then this sample is a good base to start extracting what you are looking for. Using one of the samples first is a minimal consistancy check for whether your setup is correct and complete. Using one of the samples first also shows you how to use it, which command line parameters are required (e.g. "https://github.com/TadasBaltrusaitis/OpenFace/wiki/Command-line-arguments").

brmarkus commented 4 weeks ago

@limchengwei have you found a working sample?

From your initial post you try to call:

result = subprocess.run(["OpenFaceOffline.exe", "FaceLandmarkVid.exe", "-f", video_path, "-out_dir", "output_directory"], capture_output=True)

But do you really want to call two executables, OpenFaceOffline.exe and FaceLandmarkVid.exe in the same command line?

Under Linux (in a Docker container of OpenFace) this is working for me:

result = subprocess.run(["/home/openface-build/build/bin/FaceLandmarkVid", "-f", video_path, "-out_dir", "/home/openface-build/build/bin/outdir/"], capture_output=True)