-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
scrabbled face in the video #3
Comments
hello @romasiugzdaite ! 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) |
thanks, I will try now.
…On Thu, Oct 19, 2023 at 1:50 PM Enes ***@***.***> wrote:
hello @romasiugzdaite <https://github.com/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 scrambleryimport 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 exampleinput_video_path = 'enes.mp4' # Update with your video in your pathoutput_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)
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFHO7QLH3X6DO4AGIM42ATYAEHXVAVCNFSM6AAAAAA6GXVDA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZQG4ZTQOJXGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
it worked!!!!!!!!! thank you Enes!
…On Thu, Oct 19, 2023 at 1:50 PM Enes ***@***.***> wrote:
hello @romasiugzdaite <https://github.com/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 scrambleryimport 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 exampleinput_video_path = 'enes.mp4' # Update with your video in your pathoutput_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)
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFHO7QLH3X6DO4AGIM42ATYAEHXVAVCNFSM6AAAAAA6GXVDA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZQG4ZTQOJXGA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
glad that worked! 🙂 I will extend this project soon to prevent these kinds of problems... |
Amazing! I will advertise you on twitter!
…On Thu, 19 Oct 2023, 17:08 Enes, ***@***.***> wrote:
glad that worked! 🙂 I will extend this project soon to prevent these
kinds of problems...
—
Reply to this email directly, view it on GitHub
<#3 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFHO7SQ5A746VFMRBZ62ZTYAE7AFAVCNFSM6AAAAAA6GXVDA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZRGE4DKNZUGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
hi Enes,
we are trying to scramble just a face in the video, could you help us with that please?
The text was updated successfully, but these errors were encountered: