|
|
|
|
|
""" |
|
|
Fix Closed Eyes in Comic Generation |
|
|
Run this before or after frame extraction |
|
|
""" |
|
|
|
|
|
import os |
|
|
import sys |
|
|
import cv2 |
|
|
import numpy as np |
|
|
|
|
|
|
|
|
sys.path.append(os.path.dirname(os.path.abspath(__file__))) |
|
|
|
|
|
from backend.smart_frame_selector import select_best_frames_avoid_blinks, ensure_open_eyes_in_frames |
|
|
from backend.keyframes.keyframes_no_blinks import quick_fix_existing_frames |
|
|
|
|
|
def fix_closed_eyes_in_video(video_path=None): |
|
|
"""Complete solution to fix closed eyes""" |
|
|
|
|
|
print("ποΈ FIXING CLOSED EYES IN COMIC GENERATION") |
|
|
print("=" * 50) |
|
|
|
|
|
|
|
|
if os.path.exists('frames/final'): |
|
|
print("\nπ Found existing frames, analyzing...") |
|
|
ensure_open_eyes_in_frames('frames/final') |
|
|
|
|
|
response = input("\nβ Do you want to re-select frames? (y/n): ") |
|
|
if response.lower() == 'y': |
|
|
quick_fix_existing_frames() |
|
|
print("β
Frames have been re-selected!") |
|
|
|
|
|
|
|
|
elif video_path and os.path.exists(video_path): |
|
|
print(f"\n㪠Processing video: {video_path}") |
|
|
|
|
|
|
|
|
from backend.keyframes.keyframes_no_blinks import generate_keyframes_no_blinks |
|
|
generate_keyframes_no_blinks(video_path) |
|
|
|
|
|
print("β
Keyframes generated with eye detection!") |
|
|
|
|
|
else: |
|
|
print("\nβ No frames or video found") |
|
|
print("\nUsage:") |
|
|
print(" python fix_closed_eyes.py # Fix existing frames") |
|
|
print(" python fix_closed_eyes.py video.mp4 # Process new video") |
|
|
|
|
|
def integrate_with_app(): |
|
|
""" |
|
|
Modify app_enhanced.py to use eye detection |
|
|
|
|
|
Add this to your comic generation pipeline: |
|
|
""" |
|
|
code = ''' |
|
|
# In app_enhanced.py, replace: |
|
|
# generate_keyframes(self.video_path) |
|
|
|
|
|
# With: |
|
|
from backend.keyframes.keyframes_no_blinks import generate_keyframes_no_blinks |
|
|
generate_keyframes_no_blinks(self.video_path) |
|
|
''' |
|
|
|
|
|
print("\nπ To integrate with your app, add this code:") |
|
|
print(code) |
|
|
|
|
|
|
|
|
response = input("\nβ Do you want to automatically patch app_enhanced.py? (y/n): ") |
|
|
if response.lower() == 'y': |
|
|
patch_app_enhanced() |
|
|
|
|
|
def patch_app_enhanced(): |
|
|
"""Patch app_enhanced.py to use eye detection""" |
|
|
try: |
|
|
|
|
|
with open('app_enhanced.py', 'r') as f: |
|
|
content = f.read() |
|
|
|
|
|
|
|
|
if 'from backend.keyframes.keyframes import generate_keyframes' in content: |
|
|
content = content.replace( |
|
|
'from backend.keyframes.keyframes import generate_keyframes', |
|
|
'from backend.keyframes.keyframes_no_blinks import generate_keyframes_no_blinks as generate_keyframes' |
|
|
) |
|
|
|
|
|
|
|
|
with open('app_enhanced.py', 'w') as f: |
|
|
f.write(content) |
|
|
|
|
|
print("β
app_enhanced.py has been patched!") |
|
|
print("π Your comic generation will now avoid closed eyes!") |
|
|
else: |
|
|
print("β οΈ Could not find the import to patch") |
|
|
|
|
|
except Exception as e: |
|
|
print(f"β Error patching file: {e}") |
|
|
|
|
|
if __name__ == "__main__": |
|
|
if len(sys.argv) > 1: |
|
|
fix_closed_eyes_in_video(sys.argv[1]) |
|
|
else: |
|
|
fix_closed_eyes_in_video() |
|
|
|
|
|
|
|
|
integrate_with_app() |