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:

Output:
