{"id":27972972,"url":"https://github.com/alsult/compvision_puzzle","last_synced_at":"2026-04-29T20:10:41.206Z","repository":{"id":284339989,"uuid":"954616465","full_name":"AlSult/CompVision_Puzzle","owner":"AlSult","description":"A computer vision pipeline that reconstructs a shuffled puzzle using SIFT feature matching, RANSAC, and image preprocessing.","archived":false,"fork":false,"pushed_at":"2025-04-23T08:05:46.000Z","size":6121,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-03T08:05:13.711Z","etag":null,"topics":["computer-vision","contour-detection","feature-matching","homography","image-processing","image-segmentation","opencv","peppa-pig","puzzle-reconstruction","python","ransac-algorithm","sift-features"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AlSult.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-25T11:02:18.000Z","updated_at":"2025-04-23T08:11:29.000Z","dependencies_parsed_at":"2025-04-23T09:32:22.911Z","dependency_job_id":null,"html_url":"https://github.com/AlSult/CompVision_Puzzle","commit_stats":null,"previous_names":["alsult/compvision_puzzle"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AlSult/CompVision_Puzzle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlSult%2FCompVision_Puzzle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlSult%2FCompVision_Puzzle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlSult%2FCompVision_Puzzle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlSult%2FCompVision_Puzzle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AlSult","download_url":"https://codeload.github.com/AlSult/CompVision_Puzzle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AlSult%2FCompVision_Puzzle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32441695,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T18:12:22.909Z","status":"ssl_error","status_checked_at":"2026-04-29T18:11:33.322Z","response_time":110,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["computer-vision","contour-detection","feature-matching","homography","image-processing","image-segmentation","opencv","peppa-pig","puzzle-reconstruction","python","ransac-algorithm","sift-features"],"created_at":"2025-05-07T23:21:34.634Z","updated_at":"2026-04-29T20:10:41.188Z","avatar_url":"https://github.com/AlSult.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Peppa Puzzle Reconstructor\n\nThis project automatically reconstructs a shuffled image of a Peppa Pig puzzle using computer vision techniques. The algorithm identifies and extracts puzzle pieces, matches them with their correct positions in a reference image using feature matching and RANSAC, and overlays them to restore the original image.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"peppa/pieces1.png\" width=\"30%\" alt=\"Shuffled Puzzle Pieces\"/\u003e\n  \u003cimg src=\"peppa/pieces2.png\" width=\"30%\" alt=\"Shuffled Puzzle Pieces\"/\u003e\n  \u003cimg src=\"peppa/peppa.png\" width=\"30%\" alt=\"Reconstructed Version\"/\u003e\n\u003c/p\u003e\n\n## Preprocessing\n\nBefore reconstruction can take place, the shuffled puzzle image undergoes several preprocessing steps to isolate individual puzzle pieces:\n\n1. **Grayscale Conversion**  \n   The input image is converted to grayscale to simplify edge detection and reduce computational load.\n\n2. **Edge Detection**  \n   Canny edge detection is applied to highlight the contours of each puzzle piece.\n\n3. **Morphological Operations**  \n   Dilation and closing operations are used to strengthen the edges and close small gaps, making contours more distinct.\n\n4. **Contour Detection**  \n   External contours are identified to extract bounding boxes around each puzzle piece.\n\n5. **Filtering by Area**  \n   Small contours (noise or irrelevant fragments) are filtered out using a minimum area threshold to retain only meaningful puzzle segments.\n\nThe result of this preprocessing step is a set of cropped images — each representing a potential puzzle piece — which are then passed on for feature matching and reconstruction.\n### Visual Output of Preprocessing\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"preprocessed_images/preprocessed_pieces1.png\" width=\"30%\" alt=\"Preprocessed Pieces\"/\u003e\n  \u003cimg src=\"preprocessed_images/preprocessed_pieces2.png\" width=\"30%\" alt=\"Preprocessed Pieces\"/\u003e\n  \u003cimg src=\"preprocessed_images/preprocessed_peppa.png\" width=\"30%\" alt=\"Preprocessed Pieces\"/\u003e\n\u003c/p\u003e\n  \n## How It Works\n\n1. **Piece Extraction**  \n   Detects individual puzzle pieces from a shuffled image using edge detection and contour analysis via OpenCV.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"extracted_pieces/piece_1.png\" width=\"10%\" alt=\"Extracted Piece 1\"/\u003e\n  \u003cimg src=\"extracted_pieces/piece_2.png\" width=\"10%\" alt=\"Extracted Piece 2\"/\u003e\n  \u003cimg src=\"extracted_pieces/piece_3.png\" width=\"10%\" alt=\"Extracted Piece 3\"/\u003e\n\u003c/p\u003e\n\n3. **Feature Matching with RANSAC**  \n   Each puzzle piece is matched to a reference image using SIFT keypoints and descriptors. RANSAC is applied to estimate a homography matrix for accurate alignment.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"matched_images/matched_1.png\" width=\"45%\" alt=\"Matched Piece 1\"/\u003e\n  \u003cimg src=\"matched_images/matched_2.png\" width=\"45%\" alt=\"Matched Piece 2\"/\u003e\n\u003c/p\u003e\n\n4. **Transparent Background**  \n   White areas in the puzzle pieces are made transparent to blend seamlessly during reconstruction.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"reconstructed/rec_pz.png\" width=\"50%\" alt=\"White areas\"/\u003e\n\u003c/p\u003e\n\n5. **Puzzle Reconstruction**  \n   Each aligned piece is overlayed onto a transparent canvas, rebuilding the complete puzzle.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"reconstructed/rec_pz1.png\" width=\"50%\" alt=\"White areas\"/\u003e\n\u003c/p\u003e\n\n## Results\nThe reconstruction works even when the pieces are rotated or slightly misaligned, thanks to the robustness of the SIFT + RANSAC approach. While it performs well on clean images with distinct features, accuracy may decrease with blurry or low-contrast images.   \n\n## Limitations\n\nWhile the reconstruction pipeline is generally accurate, there are cases where two connected puzzle pieces are mistakenly treated as a single object during contour detection. This typically happens when:\n\n- The gap between pieces is too small or visually subtle\n- Morphological operations (dilation, closing) merge adjacent edges\n- The white background isn't fully separated from piece boundaries\n\nAs a result, a few puzzle segments may be incorrectly aligned or misplaced in the final reconstruction.\n\nSome extracted regions contained multiple puzzle pieces, as it's shown during the detection phase:\n![Detected Pieces](extracted_pieces/detected.png)\n\nFuture improvements could include:\n- Adaptive contour separation techniques\n- Color-based segmentation to better split adjacent regions\n- Manual validation for ambiguous cases\n\n\n## Files Used\n\n- `peppa/peppa.png`: The original complete puzzle image (reference).\n- `peppa/pz.png`: The image containing randomly placed/shuffled puzzle pieces.\n\n## Requirements\n\n- Python 3\n- OpenCV (with `cv2.SIFT_create()` support, e.g., via `opencv-contrib-python`)\n- NumPy\n\nInstall dependencies:\n\n```bash\npip install opencv-contrib-python numpy\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsult%2Fcompvision_puzzle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falsult%2Fcompvision_puzzle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falsult%2Fcompvision_puzzle/lists"}