0% found this document useful (0 votes)
5 views

image_edge_detection_command-code

The document provides a series of commands for edge detection using Python and OpenCV. It includes steps to mount a USB drive, read a grayscale image, and apply the Sobel filter for edge detection. Finally, it visualizes the results using Matplotlib.

Uploaded by

nilewriddle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

image_edge_detection_command-code

The document provides a series of commands for edge detection using Python and OpenCV. It includes steps to mount a USB drive, read a grayscale image, and apply the Sobel filter for edge detection. Finally, it visualizes the results using Matplotlib.

Uploaded by

nilewriddle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Edge detection c0mmand code

1. ! lsblk

2. ! sudo mount /dev/mmcblk0p1 /mnt/sdcard

3. import os
usb_path = "/mnt/sdcard"
files = os.listdir(usb_path)
print ("Files on USB:", files)

4. import cv2
import numpy as np
import matplotlib.pyplot as plt
import os

usb_path = "/mnt/sdcard"
img_filename = "lena_gray.bmp"

img_path = os.path.join(usb_path, img_filename)

img = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)

if img is None:
print ("Error: Image not found. Check the file name and USB path.")
else:
# Display the grayscale image
plt.imshow(img, cmap="gray")
plt.axis("off")
plt.show()

5. import cv2
import numpy as np

img = cv2.imread("/mnt/sdcard/lena_gray.bmp", cv2.IMREAD_GRAYSCALE)

# Apply Sobel filter


sobel_x = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=3)
sobel_y = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=3)
sobel_combined = cv2.magnitude(sobel_x, sobel_y)

plt.imshow(sobel_combined, cmap='gray')
plt.title("Sobel Edge Detection")
plt.axis("off")
plt.show()

You might also like