Written by Steve S. Lee [email protected]
Python script that can:
- Detect feature points in two images.
- Export detected feature points in csv format.
- Find matching feature points between two images.
- Export matching feature points in csv format.
- Export an image that graphically shows detected feature points and matched feature points.
This module uses SIFT, SURF, and ORB, some of which are patented and cannot be used for commercial purposes without license. Academic use only.
This module requires cv2, numpy, csv, skimage, and matplotlib. Install these before using the module.
-Required Parameters:
- firstImage(BGR.)
- secondImage(BGR.)
-Optional Parameters:
- outputcsvFileName(String. No file exported by default.)
- Pass in name of the csv file that will be exported. Include file extension.
- detectorType(String. Uses "ORB" by default.)
- Options: "ORB", "SIFT", and "SURF".
- crossCheck(Bool. Set "True" by default".)
- normType(enum cv::NormTypes. Uses NORM_HAMMING by default.)
- Options: Refer to the table of various norm types here under "NormTypes": https://docs.opencv.org/3.4/d2/de8/group__core__array.html.
- createImageWithPtsAndLines(String. No image exported by default.)
- Pass in name of the image file that will be exported. Include file extension.
- numOfPtsAndLinesToShow(Int. Number of total matches and detected feature points by default.)
- Pass in number of points and matches to display in the image with pts and lines.
- enableSingleColor(Bool. Matching lines are unique colors by default.)
- If set True, matching lines in the image with points and lines become all neon-green and points become all red.
Example 1: Only required parameters.
img1 = cv2.imread("image1.jpg", 0)
img2 = cv2.imread("image2.jpg", 0)
pointsFromImage1, pointsFromImage2 = moduler.getPointsFromImages(firstImage=img1, secondImage=img2)
Example 2: All of the available parameters.
img1 = cv2.imread("image1.jpg", 0)
img2 = cv2.imread("image2.jpg", 0)
pointsFromImage1, pointsFromImage2 = moduler.getPointsFromImages(firstImage=img1, secondImage=img2, outputcsvFileName="matchedPointsRaw.csv", detectorType="SIFT", crossCheck=True, normType=cv2.NORM_HAMMING2, createImageWithPtsAndLines="imageWithPtsAndLines.jpg", numOfPtsAndLinesToShow=10, enableSingleColor=True)
Recommendations:
- If ORB detector is used, use "NORM_HAMMING".
- If SIFT or SURF detector is used, use either "NORM_L1" or "NORM_L2".
"Required" Parameters:
- inputcsvFileName(String.)
- CSV file of points from the function getPointsFromImages(...).
- inputPointsFromImage1(Array.)
- Array of points from the function getPointsFromImages(...).
- inputPointsFromImage2(Array.)
- Array of points from the function getPointsFromImages(...).
- outputcsvFileName(String. Doesn't output csv file by default.)
- Pass in name of the csv file that will be exported. Include file extension.
** It is possible to not pass in "inputcsvFileName", "inputPointsFromImage1", and "inputPointsFromImage2", but to get the desired output, either "inputcsvFileName" or "inputPointsFromImage1", and "inputPointsFromImage2" should be passed in.
Example 1: Using the array of points from images 1 and 2.
img1 = cv2.imread("image1.jpg", 0)
img2 = cv2.imread("image2.jpg", 0)
pointsFromImage1, pointsFromImage2 = moduler.getPointsFromImages(firstImage=img1, secondImage=img2)
robustMatchesFromImage1, robustMatchesFromImage2 = moduler.find_robust_matches_ranscac(inputPointsFromImage1=pointsFromImage1, inputPointsFromImage2=pointsFromImage2)
Example 2: Using the csv with array of points from images 1 and 2.
img1 = cv2.imread("image1.jpg", 0)
img2 = cv2.imread("image2.jpg", 0)
pointsFromImage1, pointsFromImage2 = moduler.getPointsFromImages(firstImage=img1, secondImage=img2)
robustMatchesFromImage1, robustMatchesFromImage2 = moduler.find_robust_matches_ranscac(inputcsvFileName="matchedPointsRaw.csv")
Example 3: Example 1, but with exporting csv file option enabled.
img1 = cv2.imread("image1.jpg", 0)
img2 = cv2.imread("image2.jpg", 0)
pointsFromImage1, pointsFromImage2 = moduler.getPointsFromImages(firstImage=img1, secondImage=img2)
robustMatchesFromImage1, robustMatchesFromImage2 = moduler.find_robust_matches_ranscac(inputPointsFromImage1=pointsFromImage1, inputPointsFromImage2=pointsFromImage2, outputcsvFileName="robustMatches.csv")
Example 4: Example 2, but with exporting csv file option enabled.
img1 = cv2.imread("image1.jpg", 0)
img2 = cv2.imread("image2.jpg", 0)
pointsFromImage1, pointsFromImage2 = moduler.getPointsFromImages(firstImage=img1, secondImage=img2)
robustMatchesFromImage1, robustMatchesFromImage2 = moduler.find_robust_matches_ranscac(inputcsvFileName="matchedPointsRaw.csv", outputcsvFileName="robustMatches.csv")
- Sponsored by Raj Rao Nadakuditi.