Creating a PyCharm Project - marios2019/MAI644-Computer-Vision-Fall-2023-2024 GitHub Wiki
Follow these steps to create a new PyCharm project for your MAI644 Computer Vision course:
-
Launch PyCharm:
- Open PyCharm from your applications or program list.
-
Create a New Project:
- Click on "File" in the top menu.
- Select "New Project."
-
Project Location:
- Choose a location on your computer where you want to create the project folder. You can click the "..." button to browse and select a location.
-
Select Project Interpreter:
- In the "Python Interpreter" section, select the Conda environment you created earlier (e.g.,
mai644
) as the project interpreter (Previously configured interpreter). This environment should have Python 3.11 and the required packages.
- In the "Python Interpreter" section, select the Conda environment you created earlier (e.g.,
-
Specify Project Details:
- Enter the name of your project in the "Project name" field.
-
Project Template:
- Select the appropriate project template based on your project type. For most Python projects, you can choose the "Pure Python" template.
-
Create Project:
- Click the "Create" button to create your project.
-
Verify:
- Download the following images
building_right.jpg
building_left.jpg
- Run the following piece of code in order to verify that the newly created project is using the correct Python interpreter:
import numpy as np
import cv2
from matplotlib import pyplot as plt
def main():
# Load images
img1 = cv2.imread('building_left.jpg', cv2.IMREAD_UNCHANGED)
img2 = cv2.imread('building_right.jpg', cv2.IMREAD_UNCHANGED)
# Convert to gray scale
img1GRAY = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
img2GRAY = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)
# Initiate SIFT detector
sift = cv2.SIFT.create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(img1GRAY, None)
kp2, des2 = sift.detectAndCompute(img2GRAY, None)
# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1, des2, k=2)
# Apply ratio test
good = []
for m, n in matches:
if m.distance < 0.75 * n.distance:
good.append([m])
# cv2.drawMatchesKnn expects list of lists as matches.
img3 = np.empty((max(img1.shape[0], img2.shape[0]), img1.shape[1] + img2.shape[1], 3), dtype=np.uint8)
cv2.drawMatchesKnn(img1, kp1, img2, kp2, outImg=img3, matches1to2=good, flags=2)
# Plot images
plt.figure("Feature Matching")
ax1 = plt.subplot(2, 2, 1)
ax1.axis("off") # Remove axes
ax1.imshow(cv2.cvtColor(img1, cv2.COLOR_BGR2RGB)) # Convert BGR to RGB
ax1.set_title("Left Image")
ax2 = plt.subplot(2, 2, 2)
ax2.axis("off")
ax2.imshow(cv2.cvtColor(img2, cv2.COLOR_BGR2RGB))
ax2.set_title("Right Image")
ax3 = plt.subplot2grid((2, 2), (1, 0), colspan=2)
ax3.axis("off")
ax3.imshow(cv2.cvtColor(img3, cv2.COLOR_BGR2RGB))
ax3.set_title('Feature Correspondences')
plt.show()
if __name__ == '__main__':
main()
- If everything was set up correctly, you should be able to see the following figure:
Your PyCharm project is now set up and ready for you to start working on your MAI644 Computer Vision assignments. Happy coding!