(output_dir)
| 985 | |
| 986 | |
| 987 | def image_integrity(output_dir): |
| 988 | def verify_image(f, filename, ext): |
| 989 | try: |
| 990 | with Image.open(f) as img: |
| 991 | img.verify() |
| 992 | except Exception: |
| 993 | dest_dir = os.path.join(results_folder, "image_integrity") |
| 994 | os.makedirs(dest_dir, exist_ok=True) |
| 995 | shutil.copy(f, os.path.join(dest_dir, filename)) |
| 996 | prGreen(f"[INTEGRITY] Corrupted or suspicious image: {filename}") |
| 997 | |
| 998 | for ext in ["png", "jpg"]: |
| 999 | dir_path = os.path.join(output_dir, ext) |
| 1000 | if os.path.isdir(dir_path): |
| 1001 | files = [f for f in os.listdir(dir_path) if os.path.isfile(os.path.join(dir_path, f))] |
| 1002 | with ThreadPoolExecutor(max_workers=os.cpu_count() - 1) as executor: |
| 1003 | for filename in tqdm(files, desc=f"Image integrity {ext.upper()} test: "): |
| 1004 | f = os.path.join(dir_path, filename) |
| 1005 | executor.submit(verify_image, f, filename, ext) |
| 1006 | prGreen("IMAGE INTEGRITY TEST DONE") |
| 1007 | |
| 1008 | |
| 1009 | def object_detection(output_dir): |
no test coverage detected