I am trying to detect horizon line in python. In order to achieve my goal, firstly I used canny edge detection algorithm. sea.jpg
import cv2
import numpy as np
gray = cv2.imread('images/sea.jpg')
edges = cv2.Canny(gray,50,150,apertureSize = 3)
After edge detection, I applied hough transform to image.
minLineLength=100
lines = cv2.HoughLinesP(image=edges,rho=10,theta=np.pi/180,
threshold=1,lines=np.array([]), minLineLength=minLineLength,maxLineGap=80)
a,b,c = lines.shape
for i in range(a):
cv2.line(gray, (lines[i][0][0], lines[i][0][1]), (lines[i][0][2], lines[i][0][3]), (0, 0, 255), 3, cv2.LINE_AA)
cv2.imwrite('images/output.jpg',gray)
cv2.imshow('output',gray)
cv2.waitKey(0)
cv2.destroyAllWindows()
But at the end, I output.jpg like this.
What am I doing wrong?
No comments:
Post a Comment