Untitled

 avatar
unknown
plain_text
a year ago
865 B
6
Indexable
1. Install OpenCV: If you haven't installed OpenCV yet, you can do so via pip:
pip install opencv-python


------------------------------
2.Sample Code for Edge Detection with Red Highlighting:



import cv2
import numpy as np

# Read the image
image = cv2.imread('your_image.jpg', cv2.IMREAD_COLOR)

# Convert to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Apply Canny edge detection
edges = cv2.Canny(gray, threshold1=50, threshold2=150)

# Create a copy of the original image to draw on
edge_highlight = image.copy()

# Draw red lines where the edges are detected
edge_highlight[edges != 0] = [0, 0, 255]

# Save or display the result
cv2.imshow('Edges with Red Highlight', edge_highlight)
cv2.waitKey(0)
cv2.destroyAllWindows()

# Optionally save the output
cv2.imwrite('edges_highlighted.jpg', edge_highlight)
Editor is loading...
Leave a Comment