Rotten-Scripts
Rotten-Scripts copied to clipboard
[Bug]:
Is there an existing issue for this?
- [x] I have searched the existing issues.
Current Behavior
When executing Python/SIFT_Algorithm/SIFT_Algorithm.py, the script crashes due to multiple fatal runtime errors:
- Undefined Module Alias: On lines 86–87, the script calls cv.waitKey(0) and cv.destroyAllWindows(). Since OpenCV is imported as cv2, Python immediately crashes on exit with: NameError: name 'cv' is not defined. Did you mean: 'cv2'?
- Array Overwrite Causing TypeError: On line 20, the input image matrix is read into variable image. On line 55, image = image_name[-1].split(".") reassigns image to a list of strings. When passed into cv2.drawMatches() on line 70, OpenCV throws: TypeError: Expected Ptrcv::UMat for argument 'img1'
- Broken Image File Export: On line 57, cv2.imwrite("output", img) passes the hardcoded string "output" without an extension instead of the formatted output variable constructed on line 56.
Expected Behavior
- The script should run keypoint detection, descriptor extraction, brute-force matching, and result rendering without runtime errors.
- The image NumPy ndarray matrix (cv::Mat) should remain unmodified so cv2.drawMatches() can render matching keypoints between images.
- File path string parsing should use a separate variable name (e.g., base_filename) to avoid mutating image data.
- Processed feature-detected images should be saved correctly with a valid .jpg filename extension.
- Window cleanup must call cv2.waitKey(0) and cv2.destroyAllWindows() cleanly.
To Reproduce
- Step 1: Clone the repository and navigate to the directory: git clone https://github.com/HarshCasper/Rotten-Scripts.git cd Rotten-Scripts/Python/SIFT_Algorithm
- Step 2: Install dependencies: pip install opencv-python opencv-contrib-python numpy
- Step 3: Run the script: python SIFT_Algorithm.py
- Step 4: Enter any valid image path when prompted: Enter the path of the image: sample.jpg
- Step 5: Observe the crashes during feature matching (TypeError) and GUI window cleanup (NameError).
Anything else?
- Environment: Tested across Windows, macOS, and Linux on Python 3.8 - 3.12.
- Proposed Code Fix:
- Line 55-57: base_filename = os.path.splitext(os.path.basename(path))[0] output_path = f"{base_filename}_detected.jpg" cv2.imwrite(output_path, img)
- Line 86-87: cv2.waitKey(0) cv2.destroyAllWindows()
- Contribution: I have tested the complete fix locally and verified clean execution. Please assign this issue to me so I can open a Pull Request.
Code of Conduct
- [x] I agree to follow this project's Code of Conduct