Closed joshwongg closed 2 months ago
Hi Josh, are you getting any kind of error messages or is the function not logging anything at all?
Additionally I would ensure file paths are correct and can be opened fine using cv2
in Python. You could try something like this:
import cv2
# Check if the files can be opened
expression_cap = cv2.VideoCapture(filepath)
baseline_cap = cv2.VideoCapture(baseline_filepath)
if not expression_cap.isOpened():
print(f"Error: Cannot open video file {filepath}")
if not baseline_cap.isOpened():
print(f"Error: Cannot open video file {baseline_filepath}")
expression_cap.release()
baseline_cap.release()
Hi George, I've used the following code to test file paths as well as if video quality allows for face detection
import cv2
import mediapipe as mp
mp_face_detection = mp.solutions.face_detection
mp_drawing = mp.solutions.drawing_utils
video_path = r"C:\Users\jjsw972\OneDrive - The University of Newcastle\Desktop\joshtrialthink.mp4"
cap = cv2.VideoCapture(video_path)
if not cap.isOpened():
raise ValueError(f"Error opening video file: {video_path}")
with mp_face_detection.FaceDetection(min_detection_confidence=0.2) as face_detection:
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = face_detection.process(rgb_frame)
if results.detections:
for detection in results.detections:
mp_drawing.draw_detection(frame, detection)
cv2.imshow('Face Detection', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
Everything seems to work well, however, I know have a new error which appears when using the facial expressivity function which did not occur the last time we spoke:
TensorFlow version: 2.15.0
ERROR:root:Face not detected by mediapipe file: ('C:\\Users\\jjsw972\\OneDrive - The University of Newcastle\\Desktop\\joshtrialthink.mp4',) & Error: OpenCV(4.10.0) :-1: error: (-5:Bad argument) in function 'VideoCapture'
> Overload resolution failed:
> - Expected 'filename' to be a str or path-like object
> - VideoCapture() missing required argument 'apiPreference' (pos 2)
> - Argument 'index' is required to be an integer
> - VideoCapture() missing required argument 'apiPreference' (pos 2)
INFO:root:Face not detected by mediapipe in file ('C:\\Users\\jjsw972\\OneDrive - The University of Newcastle\\Desktop\\joshtrialthink.mp4',)
I'm not sure if this is a problem with tensorflow, as the same videos work fine when i use a face detection / file path check.
Does this error occur when running the code you shared in your first message? or are you using a different script?
Because from the error message one possible issue that comes up is that it looks like you set filepath
to ('C:\\Users\\jjsw972\\OneDrive - The University of Newcastle\\Desktop\\joshtrialthink.mp4',)
, which is a Tuple
. Instead you would want to set it to 'C:\\Users\\jjsw972\\OneDrive - The University of Newcastle\\Desktop\\joshtrialthink.mp4'
. Is that the case?
Amazing, thanks for picking that up now! It works and doesn't produce the NaN now.
From running the code, the output comes out as so, in both in the PowerShell and excel spreadsheet:
Summary: overall_mean lower_face_mean upper_face_mean ... lips_std eyebrows_std mouth_openness_std
0 0.000867 0.000809 0.000899 ... 0.003784 0.004089 0.245542
I'm just wondering now, how can I see the rest of the values (such as such as lips/eyebrows mean or overall/lower/upper std)?
Thanks!
Hm I believe that's an issue with how you are printing/saving the resulting dataframes. Instead what you could do is save the files in csv format from Python. Something like that should do the trick:
if isinstance(framewise_loc, pd.DataFrame):
framewise_loc.to_csv(r"C:\Users\jjsw972\OneDrive - The University of Newcastle\Desktop\Framewise_Location.csv", index=False)
if isinstance(framewise_disp, pd.DataFrame):
framewise_disp.to_csv(r"C:\Users\jjsw972\OneDrive - The University of Newcastle\Desktop\Framewise_Displacement.csv", index=False)
if isinstance(summary, pd.DataFrame):
summary.to_csv(r"C:\Users\jjsw972\OneDrive - The University of Newcastle\Desktop\Summary.csv", index=False)
Amazing, that works great! Thanks for all your help!
Hi,
I've been trying to run the facial expressivity function, but all values returned are NaN. I'm running the code through Miniconda. This is the code that I've been using:
Any help is very much appreciated! Thanks