×

Augmented reality in python

In this article, we shall learn about augmented reality in python.

Augmented reality is a technology that captures the world around you and adds virtual content or objects on top of it, such that it looks as if those virtual objects are present in the real world. The word ‘augment‘ itself means to add something. So, we add computer-generated 2-D or 3-D content or object in the real world.

In order to view these computer-generated graphics, we require a hand-held device like a smartphone, headgear (like a hollow lens – it is a Microsoft product which puts the augmented reality object in front of you) etc.

The famous game ‘Pokemon Go‘ is based on augmented reality. In this game, the user first needs to move to a location where a particular pokemon is located, and once he/she reaches there, they can then see a pokemon image on your smartphone. The game extends in chasing the instructions following the pokemon.

In order to use augmented reality on your mobile phone, your mobile phone should contain a camera, an accelerometer, a compass and a GPS sensor. Along with these, it should also have a good memory and processing power.

Applications of Augmented Reality

The majority of people think that AR (Augmented Reality) is essentially an entertainment technology. But that’s not totally true. Many larger brands have already identified various applications of this advanced technology, and hence, they are using it for certain user-friendly mobile applications.

These days, it is used by companies to create demos for their products like apparel or jewellery etc. We also have some other applications of augmented reality, like providing some real-time information, creating virtual sticking notes, as well as for some interactive advertising. Augmented reality is helpful in business as it is proved that people are more likely to buy a product if they can interact with it.

Augmented reality is also being used these days in health care, education, aerospace and defence and also in the e-commerce sector. Due to demand in these as well as other sectors, the global AR market (Augmented reality market) is expected to reach 85 billion dollars by 2025, indeed resulting in demand for developers expertized in this advanced technology of augmented reality-based applications.

Opportunities:

In terms of job prospects, several sources highlight that the starting average salary for augmented reality developers in the US is in the range of 95,000 dollars to 110,000 dollars, and the top end is around 200,000 dollars. And according to the sources, in India, a good augmented reality developer with an experience in the range of 3 to 5 years can easily get an average salary in the range of 5 lakh per annum to 8 lakh per annum.

Python program example for augmented reality:

test.py

import cv2 as cv
import numpy as np


img = cv.imread( " ima.jpg " ) # mention the image address in the peranthesis
print( img.shape )
cv.putText(
    img = img,
    text = f" opencv version : { cv.__version } ",
    org = ( 30, 40 ),
    fontFace = ( cv.FONT_HERSHEY_PLAIN ),
    fontScale = 1.5,
    color = ( 0, 255, 0 ),
    thickness = 2,
    lineType = cv.LINE_AA,
)
cv.imshow( " img ", img )
cv.waitKey( 0 )
cv.destroyAllWindows()

Generate_markers.py

import cv2 as cv
from cv2 import aruco
marker_dict = aruco.Dictionary_get( aruco.DICT_4*4_50 )
MARKER_SIZE = 400  # pixels
for id in range( 20 ):
    marker_image = aruco.drawMarker( marker_image, id, MARKER_SIZE)
    # cv.imshow( " img ", marker_image )
    cv.imwrite( f " markers / markder_{ id }.png ", marker_image )
    # cv.waitKey( 0 )
    # break


Detect_markers.py

import cv2 as cv
from cv2 import aruco
marker_dict = aruco.Dictionary_get( aruco.DICT_4*4_50 )
param_markers = aruco.DetectorParameters_create( )
cap = cv.VideoCapture( 0 )
while True:
    ret, frame = cap.read( )
    if not ret:
        break
    gray_frame = cv.cvtColor( frame, cv.COLOR_BGR2GRAY )
    marker_corners, marker_IDs, reject = aruco.detectMarkers(
        gray_frame, marker_dict, parameters = param_markers
    )
    for ids, corners in zip( marker_IDs, marker_corners ):
        cv.polylines( frame, [ corners.astype( np.int32 ) ], True, ( 0, 255, 255 ) )
        corners = corners.reshape( 4, 2 )
        corners = corners.astype( int )
        top_right = corners[ 0 ].ravel( )
        cv.putText(
            frame,
            f" id : {ids[ 0 ] } ",
            top_right,
            cv.FONT_HERSHEY_PLAIN,
            1.3,
            ( 200, 100,0 ),
            2,
            cv.LINE_AA,
        )
        # print( ids, " ", corners )
    cv.imshow( " frame ", frame )
    key = cv.waitKey( 1 )
    if key == ord( " q "):
        break
    cap.release( )
    cv.destroyAllWindows( )

Example input:

Augmented reality in python

Output:

Augmented reality in python

Related Topics

Python Decorator

Python Decorator: A Decorator is an interesting feature of Python that helps the user design patterns and insert a new functionality to an existing object without making any modifications in...

6 minutes read.

Python Struct

Python Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way....

3 minutes read.

Python id() function

Python id() function The id() function in Python returns an id for the specified object where all the objects in has its own unique id. Syntax id(object) Parameter object: This parameter represents any object, String, Number, List,...

1 minute read.

apply() function in python

Pandas: Pandas is a library in python. It is an open source package in python. Pandas in python are used for data cleaning and data analysis. Data frame mainly consists of...

3 minutes read.

Traverse Dictionary in Python

Traversing a dictionary is visiting each and every step in the dictionary, which is also called iterating the dictionary In Python, dictionaries are a useful and commonly used data structure in...

3 minutes read.

Create First GUI Application using Tkinter in Python

GUI: A graphical interface (GUI) is a user interface that lets users interact with electronic devices like computers and smartphones by using menus, icons, and other visual cues (graphics). In contrast...

6 minutes read.

Math Module in Python

In this article, you are going to learn everything in detail about the “ math “ module in Python. We can normally work with general operations using python without importing or...

16 minutes read.

Excel to CSV in Python

Define MS Excel Microsoft Excel is an application provided by the Microsoft corporation which allows us to build graphs to build tables, and it is also used for the macro programming...

4 minutes read.

Python e-book free download

Python is a booming language these days. It has many applications for making code easier; it is also an open-source language. There are many sources to learn python. In this...

3 minutes read.

Kite Python

Kite in Python: The Kite is a package provided by the python programming language; it works with the help of artificial intelligence and helps us write code inside the visual studio....

3 minutes read.

End Parameter in python

print(): The python print() function prints the program’s output to the output screen. The output can be an integer value, string value or other value. Syntax: print(“hi”) Output: hi will be displayed on the output...

3 minutes read.

Python Random Module

The tutorial for the Python random module demonstrates how to produce pseudo-random integers in Python. Random Number Generator (RNG) The RNG (random number generator) generates a series of values with no discernible...

8 minutes read.

Python Program to Print Sum of all Elements in an Array

Python program to print sum of all elements in an array A set of objects stored in contiguous memory locations is referred to as an array. The concept is to keep...

2 minutes read.

How to Install Matplotlib in Python?

How to Install Matplotlib in Python The speed at which the enormous amount of data is generating has become a huge aid in understanding what's going on currently in the market....

4 minutes read.

Python Control Statements

Control statements are under the roof topic of loops and loops in python are defined as iteratively and repeatedly working on source code. Loop control statements are defined as they...

3 minutes read.

Screen Rotation app Using Tkinter in Python

Tkinter: The standard Python technique for building Graphical User Interfaces (GUIs) is Tkinter, which is included in all popular Python distributions. The only framework included in the Python standard library is...

3 minutes read.

Python Glob

Methods for matching files that include particular patterns in accordance with UNIX shell-related expansion rules are referred to as "glob" methods. Similar methods for finding, locating, and searching for all of...

12 minutes read.

Recursive Multiplication Python

Recursive Multiplication Python In this tutorial, we will learn how to write a Python program to get the multiplication of two numbers using the recursive approach. In the recursive multiplication approach, we...

2 minutes read.

Python Dictionary get() method

Python Dictionary get() method The dictionary.get() method returns the value of the item with the specified key. Syntax dictionary.get(keyname, value) Parameter keyname- This parameter represents the key to be searched in the dictionary. value- The parameter...

1 minute read.

Nested for Loop in Python

"Loop" is one of the foundation concepts to learn programming in any language. Nested loops are significant steps in solving many types of problems, ranging from basic to complex scenarios....

9 minutes read.