Skip to content

Commit

Permalink
package extraction&matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle-Xu001 committed Apr 23, 2023
1 parent 45faba2 commit 5598a99
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 27 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,30 @@ This submission consists of various methods for video stitching from multi-camer
- `PositioningSystem.py` - Define the function for point transformation and box transformation based on the `trans_params.json` files. It transforms the local coordinates of individual camera to the global coordinates.

- `PositioningSystem_Test.py` - Test the positoning system of three farms by visualizing the panorama results of position transformation from each camera

----
## Usage
### Feature Extraction
- **Image Feature Extraction Test**: Extract different kinds of features from the input image and visualize the result
```bash
$ python feature_extraction_test.py
```
- **Image Feature Extraction Test**: Extract various features (SIFT, BRISK, ORB) from input images and visualize results
```bash
$ ./main.sh -t feature_extraction
```
<div align="center">
<img src="result/feature_extraction.png" width="500" height="300"/>
<br/>
Figure 1 Feature Extraction Comparison
Figure 1: Feature Extraction Comparison
</div>

### Feature Matching
- **Feature Matching Test**: Match the features with BF/KNN methods. Select suitable matching method based on the Inliers Result
```bash
$ python feature_matching_test.py
```
```bash
$ ./main.sh -t feature_matching
```
</br>

- **ROIs Matching Test**: Match the features within corresponding areas to avoid wrong matches across different regions. As a result of the Separate Region Processing, false matches and computation time will be effectively reduced, and the number of correct matching inliers will increase.
```bash
```bash
$ python ROIs_matching_test.py
```
```
<div align="center">
<img src="result/feature_matching.png" width="375" height="250"/>
<img src="result/ROIs.png" width="375" height="250"/>
Expand Down
39 changes: 39 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
usage() {
echo "Usage: ${0} [-t|--type] [-img1] [-img2]]" 1>&2
exit 1
}

ROT=0
while [[ $# -gt 0 ]];do
key=${1}
case ${key} in
-t|--type)
TYPE=${2}
echo "TYPE : $TYPE"
shift 2
;;
-img1)
IMG1=${2}
echo "IMAGE 1 : $IMG1"
shift 2
;;
-img2)
IMG2=${2}
echo "IMAGE 2 : $IMG2"
shift 2
;;
*)
usage
shift
;;
esac
done

if [[ $TYPE == "feature_extraction" ]];
then
python3 src/feature_extraction_test.py --img $IMG1 #--rotate
elif [[ $TYPE == "feature_matching" ]];
then
python3 src/feature_matching_test.py --img1 $IMG1 --img2 $IMG2 #--rotate
fi
Empty file added src/__init__.py
Empty file.
22 changes: 18 additions & 4 deletions feature_extraction_test.py → src/feature_extraction_test.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,32 @@
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))

import argparse
import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt

from stitch import utils, Image


if __name__ == '__main__':
'''This script is used for feature extraction from each image'''
"""
This script is used for feature extraction testing.
"""
# Define parser arguments
parser = argparse.ArgumentParser(description="Image Stitching")
parser.add_argument("--img", type=str)
parser.add_argument("--rotate", action="store_true" , help="Rotate the image to get better visualization")
args, _ = parser.parse_known_args()

# Load exmaple image
img = cv.imread("dataset/example_image/APAP-railtracks/1.JPG")
img = cv.imread(args.img)
# img = cv.imread("dataset/example_image/APAP-railtracks/1.JPG")
# img = cv.imread("dataset/Arie/lamp_01_Arie.PNG")
# img = cv.imread("dataset/example_image/park/1.jpg")

# img = np.rot90(img,1) # Rotate the image to get better visualization
if bool(args.rotate):
img = np.rot90(img,1) # Rotate the image to get better visualization

Img = Image(img)

Expand Down
35 changes: 24 additions & 11 deletions feature_matching_test.py → src/feature_matching_test.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
import matplotlib.pyplot as plt
import os
import sys
sys.path.append(os.path.join(os.path.dirname(__file__), "../"))

import argparse
import itertools
import numpy as np
import cv2 as cv
import itertools
import matplotlib.pyplot as plt

from stitch import Image, utils


if __name__ == '__main__':
'''This script will be tested for feature matching'''
# Define parser arguments
parser = argparse.ArgumentParser(description="Image Stitching")
parser.add_argument("--img1", type=str)
parser.add_argument("--img2", type=str)
parser.add_argument("--rotate", action="store_true", help="Rotate the image to get better visualization")
args, _ = parser.parse_known_args()

draw_params = dict(matchColor = (0,255,0),
singlePointColor = (255,0,0),
flags = cv.DrawMatchesFlags_DEFAULT)

# load the matching images
#img1 = cv.imread("dataset/Arie/lamp_02_Arie.PNG")
#img2 = cv.imread("dataset/Arie/lamp_01_Arie.PNG")
img1 = cv.imread("dataset/example_image/APAP-railtracks/1.JPG")
img2 = cv.imread("dataset/example_image/APAP-railtracks/2.JPG")
img1 = cv.imread(args.img1)
img2 = cv.imread(args.img2)
# img1 = cv.imread("dataset/Arie/lamp_02_Arie.PNG")
# img2 = cv.imread("dataset/Arie/lamp_01_Arie.PNG")
#img1 = cv.imread("dataset/example_image/APAP-railtracks/1.JPG")
#img2 = cv.imread("dataset/example_image/APAP-railtracks/2.JPG")
#img1 = cv.imread("dataset/example_image/NISwGSP-denny/denny02.jpg")
#img2 = cv.imread("dataset/example_image/NISwGSP-denny/denny03.jpg")

#img1 = np.rot90(img1,1)
#img2 = np.rot90(img2,1)
if args.rotate:
img1 = np.rot90(img1,1)
img2 = np.rot90(img2,1)

# Initialize the Stitch Class
Img1 = Image(img1)
Expand All @@ -39,9 +53,8 @@
matches_sift_knn = utils.featureMatch(des1_filter, des2_filter, 'sift', knn=True)


img_sift = cv.drawMatches(Img1.img,kps1_filter,Img2.img,kps2_filter,matches_sift[:300],None,**draw_params)
img_sift_knn = cv.drawMatches(Img1.img,kps1_filter,Img2.img,kps2_filter,matches_sift_knn[:300],None,**draw_params)

img_sift = cv.drawMatches(Img1.img, kps1_filter, Img2.img, kps2_filter, matches_sift[:300],None,**draw_params)
img_sift_knn = cv.drawMatches(Img1.img, kps1_filter, Img2.img, kps2_filter, matches_sift_knn[:300],None,**draw_params)

'''BRISK Features Matching Comparison'''
# Extract the BRISK features
Expand Down
2 changes: 1 addition & 1 deletion stitch/ImageStitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init__(self, img, nfeatures=0, method = 'sift'):

# Extract the features from image and update the feature property
kps, des = self.findFeatures(method)
print("\nInitial Successfullys")
print("\nInitial Successfully!")

def equalizeHist(self):
self.img = utils.equalizeHist(self.img)
Expand Down

0 comments on commit 5598a99

Please sign in to comment.