-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetect_lig.py
More file actions
49 lines (32 loc) · 1.12 KB
/
detect_lig.py
File metadata and controls
49 lines (32 loc) · 1.12 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
37
38
39
40
41
42
43
44
45
46
47
48
49
import cv2
import numpy as np
def display_lines(img, lines):
for line in lines:
x1,y1,x2,y2=line
cv2.line(img, (x1,y1),(x2, y2),(0, 255, 0), 2)
cv2.circle(img,(x1,y1), 1,(255,0,0),2)
cv2.circle(img, (x2,y2), 1,(255, 0,0),2)
cv2.imshow('image avec ligne', img)
cv2.waitKey(0)
'''def filter_by_cordinates(lines, box):
xmin,ymin,xmax, ymax=box
lines_filtered=list()
for line in lines:
x1,y1,x2,y2=line
if min(x1,x2) < xmin or min(y1, y2) < ymin or max(x1, x2) > xmax or max(y1, y2) > ymax:
pass
else:
lines_filtered.append(line)
return lines_filtered
'''
img=cv2.imread("images/te1.jpg")
#img=cv2.resize(img,(img.shape[1] // 3, img.shape[0] //3))
gray=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray=cv2.threshold(gray, 180, 255, cv2.THRESH_BINARY)[1]
lines=cv2.HoughLinesP(gray,1, np.pi /180, 50, minLineLength=80,maxLineGap=20)
lines=np.squeeze(lines)
#lines=filter_by_cordinates(lines,(100, 100, gray.shape[1] -50, gray.shape[0]-50))
display_lines(img,lines)
cv2.imshow('image',gray)
cv2.waitKey(0)
cv2.destroyAllWindows()