-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCompVision.py
More file actions
36 lines (30 loc) · 1.15 KB
/
CompVision.py
File metadata and controls
36 lines (30 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import cv2
# OpenCV library for computer vision.
import matplotlib.pyplot as plt # For plotting images using matplotlib.
# Load a sample image from disk.
# Replace 'sample.jpg' with the path to an actual image file.
image = cv2.imread('AVALANCHE2.jpg')
# imread loads the image in BGR (Blue, Green, Red) format.
# Check if the image was correctly loaded.
if image is None:
print("Error: Unable to load image file.")
else:
# Convert image to grayscale.
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# cvtColor converts the image from BGR to Grayscale.
# Apply Canny edge detection.
edges = cv2.Canny(gray_image, threshold1=100, threshold2=200)
# Canny detects edges by finding areas of strong intensity gradients.
# Display the original and edge-detected images side by side.
plt.figure(figsize=(10, 5))
plt.subplot(1, 2, 1)
plt.imshow(
cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
) # Convert BGR to RGB for correct color display.
plt.title('Original Image')
plt.axis('off')
plt.subplot(1, 2, 2)
plt.imshow(edges, cmap='gray')
plt.title('Edge Detection')
plt.axis('off')
plt.show()