Comments (5)
from scramblery.
from scramblery.
hello @romasiugzdaite !
I realized I didn't focus on video scramble as much as static images, but we can still use it. π (I think I need to update scramblery soon... π)
For now, to fix your issue, I tried to create a simple code by commenting as much as possible so I hope it will be a roadmap for the next updateπ... just run the code by changing the video input name, and it should work... (but bump me if you got any errors/questions)
Note: This is designed for a single face in a video, if you have to apply scramble for multiple faces in a video let me know because the code might change significantly... π
from scramblery import scramblery
import cv2 ## use pip install opencv-python if you don't have this library.
def process_video(input_video_path, output_video_path, scramble_settings):
cap = cv2.VideoCapture(input_video_path)
# Checking if the video opened successfully....
if not cap.isOpened():
print("Error: Could not open video.")
return
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
fps = cap.get(cv2.CAP_PROP_FPS)
codec = cv2.VideoWriter_fourcc(*'XVID')
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
out = cv2.VideoWriter(output_video_path, codec, fps, (frame_width, frame_height))
frame_number = 0 # Keep track of frame number
while cap.isOpened():
ret, frame = cap.read()
# if frame is read correctly, ret is True
if not ret:
print("Can't receive frame. Exiting ...")
break
frame_number += 1 # Increment frame number
# Printing the progress...
print(f"Processing frame {frame_number} of {total_frames} ({(frame_number/total_frames)*100:.2f}%)")
# Try processing the frame through scrambleface function
try:
scrambled_frame = scramblery.scrambleface(frame, **scramble_settings)
except TypeError: # Catch the error when no faces are detected
scrambled_frame = frame # If an error occurs, use the original frame
# Write the frame into the output video file
out.write(scrambled_frame)
# Uncomment this section if you want to see the video while it's being processed
# cv2.imshow('frame', scrambled_frame)
# if cv2.waitKey(1) == ord('q'):
# break
# Release everything when the job is finished
cap.release()
out.release()
cv2.destroyAllWindows()
# Usage example
input_video_path = 'enes.mp4' # Update with your video in your path
output_video_path = 'enes_scramble.mp4' # output video name
scramble_settings = {
'splits': 25, #scramble ratio
'type': 'pixel', ## For now only "stack" and "pixel" are available.
'seamless': False, ## Seamless Cloning also needs to be update for next patch. so keep it as "false" for now.
'bg': True, ## note If you set it to "false" the background disappears, but the background is still visible at every frame where the face is not detected. So I don't recommend it for now...
'seed': None,
'write': False # It's important to set 'write' to False so the function returns the image instead of saving it
}
process_video(input_video_path, output_video_path, scramble_settings)
from scramblery.
from scramblery.
glad that worked! π I will extend this project soon to prevent these kinds of problems...
from scramblery.
Related Issues (2)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from scramblery.