Skip to content

Instantly share code, notes, and snippets.

@ilhan-athn7
Created June 16, 2025 08:49
Show Gist options
  • Save ilhan-athn7/e5ebadf8b38f4914eebf5ba8ac76a549 to your computer and use it in GitHub Desktop.
Save ilhan-athn7/e5ebadf8b38f4914eebf5ba8ac76a549 to your computer and use it in GitHub Desktop.
barcode_picture_remover
import os
import cv2
from pyzbar.pyzbar import decode
folder_path = 'path/to/your/folder'
if not os.path.isdir(folder_path):
print(f"Folder not found: {folder_path}")
exit(1)
for filename in os.listdir(folder_path):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp', '.gif')):
file_path = os.path.join(folder_path, filename)
image = cv2.imread(file_path)
if image is None:
print(f"Failed to read image: {filename}")
continue
barcodes = decode(image)
if barcodes:
print(f"Deleting {filename} — barcode detected")
os.remove(file_path)
else:
print(f"No barcode found in {filename}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment