Skip to content

Commit

Permalink
fixing ussues of windows users
Browse files Browse the repository at this point in the history
  • Loading branch information
IzeriaAbdellatif committed Feb 19, 2025
1 parent 01f80d7 commit a0b0405
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 10 deletions.
50 changes: 41 additions & 9 deletions Face_Landmarker/Face_Landmarker_Link.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,22 @@
else:
print("Invalid input. Please enter 'Y' or 'N'.")

from pathlib import Path

# media pipe face landmarker options
model_path = "face_landmarker.task"
# Get the directory of the current script
script_dir = Path(__file__).parent.resolve()

# Define the relative path to the model file
relative_model_path = Path('face_landmarker.task')

# Construct the full path
model_path = script_dir / relative_model_path

import os

if not os.path.exists(model_path):
print(f"Model file not found at {model_path}")
# Handle the error appropriately

BaseOptions = mp.tasks.BaseOptions
FaceLandmarker = mp.tasks.vision.FaceLandmarker
Expand All @@ -58,7 +71,7 @@

# Create a face landmarker instance with the video mode:
options = FaceLandmarkerOptions(
base_options=BaseOptions(model_asset_path=model_path),
base_options=BaseOptions(model_asset_path=str(model_path)),
running_mode=VisionRunningMode.VIDEO,
num_faces=1,
min_face_detection_confidence=0.5,
Expand Down Expand Up @@ -163,13 +176,21 @@ def calculate_rotation(face_landmarks, pcf, image_shape):


# here i make an open file dialogue window

# Create a Tkinter root window
root = tk.Tk()
root.withdraw() # Hide the root window

# Ensure the root window is on top
root.attributes('-topmost', True)
root.update() # Update window to apply attributes

# Open the file dialog to select the video file
file_path = filedialog.askopenfilename(title="Select Video File")

# After the file dialog is closed, remove the topmost attribute
root.attributes('-topmost', False)

# Check if the user selected a file
if file_path:
# Continue with the rest of your code using the file_path variable
Expand All @@ -186,13 +207,24 @@ def calculate_rotation(face_landmarks, pcf, image_shape):
# Path to the input video file
#video_path = "???.mp4"

# Path to the output CSV file
# Assuming 'file_path' is the path to the input video file
file_name = os.path.basename(file_path)
# print (file_name)
file_result, extension = os.path.splitext(file_path)
# print(file_result)
output_csv_path = str(file_result) + "_blendshape_data.csv"
print (output_csv_path)
file_result, extension = os.path.splitext(file_name)

# Prompt user to select the output CSV file path
output_csv_path = filedialog.asksaveasfilename(
title="Save CSV As",
initialfile=f"{file_result}_blendshape_data.csv",
defaultextension=".csv",
filetypes=[("CSV files", "*.csv"), ("All files", "*.*")]
)

if output_csv_path:
print(f"CSV will be saved to: {output_csv_path}")
# Your code to save the CSV data goes here
else:
print("CSV save operation canceled.")


# Create a VideoCapture object
cap = cv2.VideoCapture(video_path)
Expand Down
2 changes: 1 addition & 1 deletion Face_Landmarker/Face_Landmarker_Link_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@


# media pipe face landmarker options
model_path = "face_landmarker.task"
model_path = "C:\\Users\\abdel\\Desktop\\git&github\\Face_Landmark_Link\\Face_Landmarker\\face_landmarker.task"

BaseOptions = mp.tasks.BaseOptions
FaceLandmarker = mp.tasks.vision.FaceLandmarker
Expand Down
Binary file not shown.
Binary file not shown.
60 changes: 60 additions & 0 deletions myModifications.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Project Title

This project utilizes MediaPipe's Face Landmarker to process video files and extract facial blendshape data, saving the results to a CSV file.

## Modifications

### 1. GitHub Workflow Update

The `.yaml` configuration file has been updated to ensure successful application builds on GitHub.

### 2. Windows User Enhancements

Several issues specific to Windows users have been addressed:

- **Model Path Resolution:** The application now dynamically constructs the path to the `face_landmarker.task` model file, ensuring it's correctly located regardless of the user's environment.

- **File Dialog Behavior:** The file explorer dialog is now configured to appear in the foreground, preventing it from opening behind other applications.

### 3. Output CSV Directory Control

Users can now specify the directory for the generated CSV file, providing greater flexibility in managing output data.

## Building the Executable Locally

To build the executable file locally, follow these steps:

1. **Upgrade pip:**
```bash
python -m pip install --upgrade pip
```


2. **Install `flake8`:**
```bash
pip install flake8
```


3. **Install Required Packages:**
```bash
pip install -r Face_Landmarker/requirements.txt
```


4. **Build the Application:**
- **Option 1:** Run the script directly:
```bash
python Face_Landmarker/Face_Landmarker_Link.py
```
- **Option 2:** Use PyInstaller to create an executable:
```bash
pyinstaller Face_Landmarker/Face_Landmarker_Link.spec
```
This command will generate the executable in the `dist` directory.

**Note:** Ensure that all dependencies are installed and properly configured before building the application, also you can builded it on github

For more information on creating executables with PyInstaller, refer to the [PyInstaller Usage Guide](https://pyinstaller.org/en/v4.1/usage.html).

By following these instructions, you can successfully build and run the application on your local machine.

0 comments on commit a0b0405

Please sign in to comment.