|
--- |
|
license: cc-by-nc-sa-4.0 |
|
task_categories: |
|
- text-to-image |
|
- image-to-image |
|
language: |
|
- en |
|
tags: |
|
- southpark |
|
- cartoon |
|
- animation |
|
- comedy |
|
- images |
|
- frames |
|
pretty_name: southpark |
|
size_categories: |
|
- 100K<n<1M |
|
--- |
|
|
|
# South Park |
|
|
|
## South Park Images Dataset |
|
|
|
*** |
|
|
|
![South Park.jpg](/static-proxy?url=https%3A%2F%2Fcdn-uploads.huggingface.co%2Fproduction%2Fuploads%2F5f57ea2d3f32f12a3c0692e6%2F_hqev7bG2Aygd2kYvlx_y.jpeg%3C%2Fspan%3E)%3C%2Fspan%3E%3C!-- HTML_TAG_END --> |
|
|
|
*** |
|
|
|
# Installation |
|
|
|
```python |
|
from huggingface_hub import snapshot_download |
|
|
|
repo_id = "asigalov61/South-Park" |
|
repo_type = 'dataset' |
|
|
|
local_dir = "./South-Park" |
|
|
|
snapshot_download(repo_id, repo_type=repo_type, local_dir=local_dir) |
|
|
|
``` |
|
|
|
*** |
|
|
|
# Make your own dataset |
|
|
|
```sh |
|
!pip install opencv-python |
|
``` |
|
|
|
```python |
|
import cv2 |
|
import os |
|
from tqdm import tqdm |
|
|
|
#=============================================================================================== |
|
|
|
def scan_videos(directory, videos_extensions=['.mkv', '.mp4', '.avi']): |
|
|
|
video_files = [os.path.join(directory, f) for f in os.listdir(directory) if os.path.splitext(f)[1].lower() in videos_extensions] |
|
|
|
return video_files |
|
|
|
def extract_frames(video_path, |
|
output_folder, |
|
interval=0.1, |
|
square_size=480, |
|
scale_size=128, |
|
images_ext='.jpg' |
|
): |
|
|
|
if not os.path.exists(output_folder): |
|
os.makedirs(output_folder) |
|
|
|
cap = cv2.VideoCapture(video_path) |
|
fps = cap.get(cv2.CAP_PROP_FPS) |
|
frame_interval = int(fps * interval) |
|
frame_count = 0 |
|
total_frames = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) |
|
|
|
print('Video file:', os.path.basename(video_path)) |
|
|
|
with tqdm(total=total_frames, desc='Extracting frames') as pbar: |
|
|
|
while True: |
|
|
|
ret, frame = cap.read() |
|
|
|
if not ret: |
|
break |
|
|
|
if frame_count % frame_interval == 0: |
|
|
|
# Calculate the coordinates for cropping the center square |
|
height, width = frame.shape[:2] |
|
center_y, center_x = height // 2, width // 2 |
|
half_size = square_size // 2 |
|
top_left_x = max(center_x - half_size, 0) |
|
top_left_y = max(center_y - half_size, 0) |
|
bottom_right_x = min(center_x + half_size, width) |
|
bottom_right_y = min(center_y + half_size, height) |
|
|
|
square_frame = frame[top_left_y:bottom_right_y, top_left_x:bottom_right_x] |
|
|
|
# Normalize brightness and contrast |
|
normalized_frame = cv2.normalize(square_frame, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX) |
|
|
|
# Resize |
|
resized_frame = cv2.resize(normalized_frame, (scale_size, scale_size)) |
|
|
|
frame_name = os.path.join(output_folder, f"frame_{frame_count}{images_ext}") |
|
cv2.imwrite(frame_name, resized_frame) |
|
|
|
frame_count += 1 |
|
|
|
pbar.update(1) |
|
|
|
cap.release() |
|
|
|
print(f"Frames extracted to {output_folder}") |
|
|
|
#=============================================================================================== |
|
|
|
videos_dir = 'Videos' |
|
videos_extensions = ['.mkv', '.mp4', '.avi'] |
|
|
|
frames_output_dir = 'Output' |
|
frames_extraction_interval = 0.1 # FPS * frames_extraction_interval |
|
original_frame_size = 480 |
|
final_frame_size = 128 |
|
output_frames_extension = '.jpg' |
|
|
|
#=============================================================================================== |
|
|
|
print('=' * 70) |
|
print('Scanning videos dir...') |
|
video_files = scan_videos(videos_dir) |
|
print('Done!') |
|
|
|
print('=' * 70) |
|
print('Found', len(video_files), 'video files') |
|
print('=' * 70) |
|
|
|
print('Starting extraction...') |
|
print('=' * 70) |
|
|
|
for video in video_files: |
|
|
|
extract_frames(video, |
|
os.path.join(frames_output_dir, os.path.splitext(os.path.basename(video))[0]), |
|
frames_extraction_interval, |
|
original_frame_size, |
|
final_frame_size, |
|
output_frames_extension |
|
) |
|
|
|
print('=' * 70) |
|
|
|
print('Extraction finished!') |
|
print('=' * 70) |
|
|
|
print('Scanning for extracted frames...') |
|
|
|
frames_list = list() |
|
|
|
for (dirpath, dirnames, filenames) in os.walk(frames_output_dir): |
|
frames_list += [os.path.join(dirpath, file) for file in filenames if file.endswith(output_frames_extension)] |
|
|
|
print('Done!') |
|
print('=' * 70) |
|
|
|
print('Found', len(frames_list), 'video frames') |
|
print('=' * 70) |
|
|
|
print('Done!') |
|
print('=' * 70) |
|
``` |
|
|
|
*** |
|
|
|
### Project Los Angeles |
|
### Tegridy Code 2024 |