How I learned Lane Detection Using Asphalt 8 Airborne

How I learned Lane Detection Using Asphalt 8 Airborne

5 simple steps to implement lane detection using Python. Lane detection and control has become a common feature in many vehicles today. Additionally it is a basic starting point for anyone going in the direction of Autonomous Driving.

Lane detection and control has become a common feature in many vehicles today. Additionally it is a basic starting point for anyone going in the direction of Autonomous Driving. But for most people who are not working on autonomous driving or computer vision, starting with it might appear much more of a daunting task than it actually is.

There is a lot of technical research involved in doing actual lane detection. In this case, we see a practical perspective so that anyone interested can try it out without much hassle. The detailed links to the theory are still there in the relevant sections for the curious ones: those of you who do not get satiated with just practical applications and like to get their teeth to sink deeper into the subject matter.

Here is everything you need to start:

  1. Asphalt 8 Airborne: If you are a Windows 10 user, you can download it free from the Windows Store: https://www.microsoft.com/en-us/p/asphalt-8-airborne/9wzdncrfj12h?activetab=pivot:overviewtab
  2. Python 3.7: You could install the latest version of Anaconda, most of the required package will be already bundled and ready to use. Here is the link to download the latest version: https://www.anaconda.com/products/individual
  3. OpenCV: It is a library mainly aimed at real time computer vision. You can find the documentation about how to install and use it here: https://www.learnopencv.com/install-opencv3-on-windows/

Now that we have all we need, let’s cut to the chase!


Step 1: Find a way to access the game screen

This one is easy enough. I did a quick google search to check out python codes that can be used to access the screen. Here is a really great tutorial, from which I used the basic code and adapted it for this case:

How to Capture Your Screen with Python - HolyPython.com

This Python tutorial explains the basic fundamentals of digital images. You will learn how pixels are represented as…

holypython.com

If we run the code directly, you would see a similar result as seen below in a random game level. You will notice that the colors are a bit different, and the screen rate results in some lag (which is OK for our purpose).

Image for post

Let’s correct the color part with some help from the OpenCV documentation. There is a argument in cv2 that makes the screen recording look like the actual color (or at least as far as my vision allows) which is COLOR_BGR2RGB, that is what I used for the correction here. Also, the time function is used to get the screen rate, which comes to around 10 fps, not bad at all! The modified code looks as follows:

## import libraries
from PIL import ImageGrab
import cv2
import numpy as np
import time
## for timing
last_time = time.time()
## screen capture loop
while True:

    screen = np.array(ImageGrab.grab(bbox=(0,40,800,700)))

    print(f'the screen rate is {(1/(time.time()-last_time))}')
    last_time = time.time()

    cv2.imshow('Python Window', cv2.cvtColor(screen, \
               cv2.COLOR_BGR2RGB))
    if cv2.waitKey(25) & 0xFF == ord('q'):
        cv2.destroyAllWindows()
        break

For the above code to correctly capture screen, I have minimized the game window to the top left corner of my primary monitor, with the dimensions as 800 x 700. You could adjust it appropriately in your code (by changing bbox in the ImageGrab above), especially if you are using multiple monitors.

learning python data-science programming computer-vision

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Data Science With Python Training | Python Data Science Course | Intellipaat

🔵 Intellipaat Data Science with Python course: https://intellipaat.com/python-for-data-science-training/In this Data Science With Python Training video, you...

Python for Data Science | Data Science With Python | Python Data Science Tutorial

🔥Intellipaat Python for Data Science Course: https://intellipaat.com/python-for-data-science-training/In this python for data science video you will learn e...

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.

Data Science Projects | Data Science | Machine Learning | Python

Practice your skills in Data Science with Python, by learning and then trying all these hands-on, interactive projects, that I have posted for you.