Skip to content

Commit

Permalink
added roi for finding lane
Browse files Browse the repository at this point in the history
  • Loading branch information
Gautam-J committed Mar 29, 2020
1 parent 3b21076 commit 96795ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 7 deletions.
17 changes: 14 additions & 3 deletions find_lanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
'''


def roi(img, vertices):
mask = np.zeros_like(img)
cv2.fillPoly(mask, vertices, 255)
masked = cv2.bitwise_and(img, mask)

return masked


def straight():
print('straight')
PressKey(W)
Expand Down Expand Up @@ -144,9 +152,12 @@ def preprocess_img(image):
image = cv2.GaussianBlur(image, (3, 3), 0)
# edge detection
image = auto_canny(image)
# Masking Region of Interest
vertices = np.array([[0, 201], [0, 50], [381, 50], [381, 201]], np.int32)
image = roi(image, [vertices])
# probabilistic hough transform
lines = cv2.HoughLinesP(image, rho=1, theta=(np.pi / 180),
threshold=5, minLineLength=50, maxLineGap=15)
threshold=5, minLineLength=20, maxLineGap=5)
m1 = 0
m2 = 0
# drawing lines
Expand All @@ -171,9 +182,9 @@ def preprocess_img(image):

CountDown(5)
while True:
screen = grab_screen(region=(270, 280, 650, 450))
screen = grab_screen(region=(270, 250, 650, 450))
new_screen, original_image, m1, m2 = preprocess_img(screen)
cv2.imshow('window', new_screen)
# cv2.imshow('window', new_screen)
cv2.imshow('window2', cv2.cvtColor(original_image, cv2.COLOR_BGR2RGB))

if m1 < 0 and m2 < 0:
Expand Down
20 changes: 16 additions & 4 deletions visualize_screen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import cv2
import numpy as np
from grabscreen import grab_screen

'''
Expand All @@ -7,14 +8,25 @@
Make sure that your game window is seen by cv2.
'''


def roi(img, vertices):
mask = np.zeros_like(img)
cv2.fillPoly(mask, vertices, 255)
masked = cv2.bitwise_and(img, mask)
return masked


while True:
# change the region=(x, y, width, height) according to your game window.
screen = grab_screen(region=(270, 250, 650, 450))
org_image = grab_screen(region=(270, 250, 650, 450))
image = cv2.cvtColor(org_image, cv2.COLOR_BGR2GRAY)
vertices = np.array([[0, 201], [0, 50], [381, 50], [381, 201]], np.int32)
image = roi(image, [vertices])

# uncomment the next line to see the resized image to be inputed.
screen = cv2.resize(screen, (200, 80))
screen = cv2.cvtColor(screen, cv2.COLOR_BGR2RGB)
# org_image = cv2.resize(org_image, (200, 80))
screen = cv2.cvtColor(org_image, cv2.COLOR_BGR2RGB)
cv2.imshow('window', screen)
cv2.imshow('Region_of_interest', image)

if cv2.waitKey(25) == ord('q'):
cv2.destroyAllWindows()
Expand Down

0 comments on commit 96795ff

Please sign in to comment.