diff --git a/extractor.py b/extractor.py index 4296e51..045d251 100644 --- a/extractor.py +++ b/extractor.py @@ -64,7 +64,6 @@ class BadApple: if width is None and height is None: target_width, target_height = orig_width, orig_height elif width is not None and height is not None: - # Check aspect ratio if orig_width * height != orig_height * width: raise ValueError("Violated aspect ratio") target_width, target_height = width, height @@ -82,7 +81,6 @@ class BadApple: frame_count = 0 with open(output_file, "w") as f, tqdm(total=total_frames, desc="Extracting frames") as pbar: - # Write header f.write(self.header(vid, fps) + f"\ntarget_resolution: {target_width}x{target_height}\n") while cap.isOpened(): ret, frame = cap.read() @@ -91,18 +89,18 @@ class BadApple: if frame_count % frame_interval == 0: if (target_width, target_height) != (orig_width, orig_height): frame = cv2.resize(frame, (target_width, target_height), interpolation=cv2.INTER_AREA) - rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) - rows = [] - for row in rgb_frame: - row_str = ";".join([f"{r},{g},{b}" for r, g, b in row]) - rows.append(row_str) + gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) + # threshold at 128, 1 if closer to white, 0 if closer to black + _, bw = cv2.threshold(gray, 128, 1, cv2.THRESH_BINARY) + # convert each row to string of 0s and 1s + rows = ["".join(str(bit) for bit in row) for row in bw] f.write("|".join(rows) + "\n") frame_count += 1 pbar.update(1) cap.release() - # print filesize - file_size_in_gb = os.path.getsize(output_file) / (2**30) + file_size = os.path.getsize(output_file) / (2**30) print(f"Extracted {frame_count} frames to {output_file} ({file_size:.2f} gb)") + def download_videos(self, keys: List[str]) -> None: os.makedirs("apples", exist_ok=True) for key in keys: diff --git a/x11/xHandler.c b/x11/xHandler.c index 330e4e7..1b1aa6e 100644 --- a/x11/xHandler.c +++ b/x11/xHandler.c @@ -20,11 +20,11 @@ void fill_color(Display *display, Window window, GC gc, Colormap cm, const char XFillRectangle(display, window, gc, 0, 0, WIDTH, HEIGHT); } -void fill_black(Display *display, Window window, GC gc, Colormap cm) { +void black(Display *display, Window window, GC gc, Colormap cm) { fill_color(display, window, gc, cm, "#000000"); } -void fill_white(Display *display, Window window, GC gc, Colormap cm) { +void white(Display *display, Window window, GC gc, Colormap cm) { fill_color(display, window, gc, cm, "#FFFFFF"); }