Skip to content
Snippets Groups Projects
Commit 43eaca8e authored by Mathieu Beligon's avatar Mathieu Beligon
Browse files

[common] (twitch-dset) Add scripts dir, and stop using watchdog to monitor files that appear

parent 83a33a5c
No related branches found
No related tags found
Loading
File deleted
File added
File added
...@@ -48,10 +48,3 @@ class ThumbnailsGenerator: ...@@ -48,10 +48,3 @@ class ThumbnailsGenerator:
def _get_frame_number(self): def _get_frame_number(self):
return int(ffmpeg.probe(str(self.video_path))['format']['duration'].split('.')[0]) return int(ffmpeg.probe(str(self.video_path))['format']['duration'].split('.')[0])
if __name__ == '__main__':
_video_name = sys.argv[1]
print(f'Fragmenting video {_video_name}')
ThumbnailsGenerator(_video_name).run()
...@@ -5,13 +5,14 @@ from shutil import move ...@@ -5,13 +5,14 @@ from shutil import move
import numpy as np import numpy as np
from scipy.spatial import distance from scipy.spatial import distance
from skimage import io from skimage import io
from watchdog.events import FileSystemEvent, FileSystemEventHandler from skimage.transform import resize
from watchdog.observers import Observer
from research.constants import TWITCH_DSET from research.constants import TWITCH_DSET
RES_DIR: Path = TWITCH_DSET / 'robots-views'
RES_DIR.mkdir(parents=True, exist_ok=True)
ref_image = io.imread('mask.jpg') ref_image = io.imread(f'{__file__}/../mask.jpg')
_MASK = ref_image[:, :, 1] > 50 _MASK = ref_image[:, :, 1] > 50
_REF_IMG_MASKED = ref_image*_MASK[:, :, np.newaxis] _REF_IMG_MASKED = ref_image*_MASK[:, :, np.newaxis]
...@@ -24,30 +25,14 @@ def is_image_from_robot_view(path_to_image: Path) -> bool: ...@@ -24,30 +25,14 @@ def is_image_from_robot_view(path_to_image: Path) -> bool:
return distance.euclidean(img_masked.flatten() / 255, _REF_IMG_MASKED.flatten() / 255) < _THRESHOLD return distance.euclidean(img_masked.flatten() / 255, _REF_IMG_MASKED.flatten() / 255) < _THRESHOLD
class NewFrameHandler(FileSystemEventHandler): def process_image(path_to_image: Path):
if is_image_from_robot_view(path_to_image):
res_path = RES_DIR / f'{path_to_image.parent.name}-{path_to_image.name}'
move(str(path_to_image), str(res_path))
else:
remove(str(path_to_image))
def __init__(self):
self.res_dir = (TWITCH_DSET / 'robots-views')
self.res_dir.mkdir(exist_ok=True, parents=True)
def on_created(self, event: FileSystemEvent): def process_all_images_in_dir(dir_path: Path):
if event.is_directory or not event.src_path.endswith('jpg'): for path_to_image in dir_path.glob('*/*.jpg'):
return process_image(path_to_image)
file_path = Path(event.src_path)
if is_image_from_robot_view(file_path):
res = self.res_dir / f'{file_path.parent.name}-{file_path.name}'
move(file_path, res)
else:
remove(file_path)
def __hash__(self):
return hash(self.__class__.__name__)
if __name__ == '__main__':
obs = Observer()
obs.schedule(NewFrameHandler(), str(TWITCH_DSET / 'raw-frames'), recursive=True)
obs.start()
while 1:
pass
from time import sleep
from research.constants import TWITCH_DSET
from research.dataset.twitch.robot_view import process_all_images_in_dir
if __name__ == '__main__':
while 1:
process_all_images_in_dir(TWITCH_DSET / 'raw-frames')
sleep(.1)
import sys
from research.dataset.twitch.make_thumbnails import ThumbnailsGenerator
if __name__ == '__main__':
_video_name = sys.argv[1]
print(f'Fragmenting video {_video_name}')
ThumbnailsGenerator(_video_name).run()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment