Skip to content

Commit 949d71b

Browse files
style: format code with autopep8
Format code with autopep8 This commit fixes the style issues introduced in 0058f1c according to the output from Autopep8. Details: https://app.deepsource.com/gh/avinashkranjan/Amazing-Python-Scripts/transform/4f52e706-06d2-4607-bbd1-47a38a3ec5f7/
1 parent 0058f1c commit 949d71b

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

Line_Detection_HoughLine/HoughLine.py

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,65 @@
33
from tkinter.filedialog import *
44
import tkinter as tk
55

6-
window=tk.Tk()
6+
window = tk.Tk()
77
window.title("Line detection using Hough transform")
88
window.geometry('380x100')
9-
label = tk.Label(window, text="Choose an option").grid(row=0,column=0)
9+
label = tk.Label(window, text="Choose an option").grid(row=0, column=0)
1010
# displaying a menu window for choosing transforms
1111

12+
1213
def hough():
1314
photo = askopenfilename()
1415
img = cv2.imread(photo)
15-
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
16-
edges = cv2.Canny(gray,50,150,apertureSize=3)
17-
18-
lines = cv2.HoughLines(edges,1,np.pi/180,500)
16+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
17+
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
18+
19+
lines = cv2.HoughLines(edges, 1, np.pi/180, 500)
1920
for line in lines:
20-
rho,theta = line[0]
21-
# defining lines with the parameters returned by HoughLines()
22-
a=np.cos(theta)
23-
b=np.sin(theta)
21+
rho, theta = line[0]
22+
# defining lines with the parameters returned by HoughLines()
23+
a = np.cos(theta)
24+
b = np.sin(theta)
2425
x0 = a*rho
2526
y0 = b*rho
2627
x1 = int(x0 + 1000*(-b))
2728
y1 = int(y0 + 1000*(a))
2829
x2 = int(x0 - 1000*(-b))
2930
y2 = int(y0 - 1000*(a))
30-
cv2.line(img,(x1,y1),(x2,y2),(0,0,255),4) # drawing lines on image to mark
31-
cv2.imwrite('houghlines.jpg',img)
32-
cv2.imshow("houghlines",img)
31+
# drawing lines on image to mark
32+
cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 4)
33+
cv2.imwrite('houghlines.jpg', img)
34+
cv2.imshow("houghlines", img)
3335
cv2.waitKey(5000)
3436
cv2.destroyAllWindows()
3537

38+
3639
def houghP():
3740
photo = askopenfilename()
3841
img = cv2.imread(photo)
39-
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
40-
edges = cv2.Canny(gray,50,150,apertureSize=3)
42+
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
43+
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
4144

42-
lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength=100,maxLineGap=10)
45+
lines = cv2.HoughLinesP(edges, 1, np.pi/180, 100,
46+
minLineLength=100, maxLineGap=10)
4347
for line in lines:
44-
x1,y1,x2,y2 = line[0] # endpoints are returned by HoughLinesP()
45-
cv2.line(img,(x1,y1),(x2,y2),(0,0,255),4) #drawing lines by joining those
46-
cv2.imwrite('houghlinesP.jpg',img)
47-
cv2.imshow("houghlinesP",img)
48+
x1, y1, x2, y2 = line[0] # endpoints are returned by HoughLinesP()
49+
# drawing lines by joining those
50+
cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 4)
51+
cv2.imwrite('houghlinesP.jpg', img)
52+
cv2.imshow("houghlinesP", img)
4853
cv2.waitKey(5000)
49-
cv2.destroyAllWindows()
54+
cv2.destroyAllWindows()
5055

5156

52-
rad1 = tk.Radiobutton(window,text='Hough Transform', value=1, command=hough)
53-
rad2 = tk.Radiobutton(window,text='Probabilistic Hough Transform', value=2, command=houghP)
57+
rad1 = tk.Radiobutton(window, text='Hough Transform', value=1, command=hough)
58+
rad2 = tk.Radiobutton(
59+
window, text='Probabilistic Hough Transform', value=2, command=houghP)
5460

55-
rad1.grid(row=1,column=0)
56-
rad2.grid(row=2,column=0)
61+
rad1.grid(row=1, column=0)
62+
rad2.grid(row=2, column=0)
5763

58-
label = tk.Label(window, text="Check the output image in this folder you are working in").grid(row=3,column=0)
64+
label = tk.Label(window, text="Check the output image in this folder you are working in").grid(
65+
row=3, column=0)
5966

60-
window.mainloop()
67+
window.mainloop()

0 commit comments

Comments
 (0)