File size: 4,708 Bytes
d00fcd3
 
 
 
 
 
 
 
 
 
 
 
d92753f
 
d00fcd3
 
 
f4e7872
 
 
 
 
 
b2c5962
 
f4e7872
 
 
 
a8ddb2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2d82617
a8ddb2e
 
 
 
 
 
0941f95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a8ddb2e
 
 
 
f4e7872
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
---
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](https://cdn-uploads.huggingface.co/production/uploads/5f57ea2d3f32f12a3c0692e6/_hqev7bG2Aygd2kYvlx_y.jpeg)

***

# 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