Skip to content

Instantly share code, notes, and snippets.

@OhadRubin
Created January 9, 2023 11:39
Show Gist options
  • Save OhadRubin/7435ba794439ef67d723f07eebea2ea2 to your computer and use it in GitHub Desktop.
Save OhadRubin/7435ba794439ef67d723f07eebea2ea2 to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
# Load the input image
image = cv2.imread('input.jpg')
# Convert the image to grayscale
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Apply gaussian blur to the image
blur = cv2.GaussianBlur(gray, (5,5), 0)
# Use canny edge detection to detect the edges in the image
edges = cv2.Canny(blur, 50, 150)
# Use Hough transform to detect lines in the image
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 100, minLineLength=100, maxLineGap=10)
# Iterate through the detected lines and separate out each line in the image
for line in lines:
x1, y1, x2, y2 = line[0]
cv2.line(image, (x1, y1), (x2, y2), (0, 255, 0), 3)
# Save the separated lines to an output image
cv2.imwrite('output.jpg', image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment