Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

K. J.

Somaiya College of Engineering, Mumbai-77


(A Constituent College of Somaiya Vidyavihar University)
Department of Electronics Engineering

Course Name: AR and MDS

Semester: VI

Experiment No: Five

Title: Scale the AR object using Camera

Date of Performance: 02 / 03 / 2023

Faculty Name:
Dr. Ninad Mehendale

Name and Roll No.:


Satbir Singh Sohal, 16010320105
AR and MDS 2022-23
Contents
1 Aim and Objective of the Experiment: 3

2 Theory: 3

3 Code: 4
3.1 Tool Used/language: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.2 Programs: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Output: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

4 Post Lab Question: 7

5 Conclusion 8
AR and MDS 2022-23

Experiment: Five
Scale the AR object using Camera
Satbir Singh Sohal, 16010320105

April 29, 2023

1 Aim and Objective of the Experiment:


Aim:
To investigate the ability to scale an AR object using a webcam feed in real-time using MATLAB.
Objectives:
1. To develop a MATLAB program that captures and displays the camera feed from a webcam.
2. To incorporate an AR object into the program that can be overlaid on top of the camera feed.
3. To implement scaling functionality within the MATLAB program that allows the AR object
to be scaled up or down in real-time.
4. To evaluate the accuracy and precision of the scaling functionality by comparing the size of the
AR object on the camera feed to its actual size.
5. To explore potential applications of this technology, such as in the fields of education, entertainment,
and advertising.

2 Theory:
Augmented Reality (AR) is a technology that blends virtual and real-world environments, enabling
users to interact with virtual objects as if they exist in the real world. AR applications can be created
using various programming languages and software development tools. In this case, MATLAB,
a widely-used programming language for technical computing and visualization, has been used to
insert an AR object into a webcam feed.
Scaling an inserted AR object involves modifying the dimensions of the object image before overlaying
it on the camera feed. This can be done using various image processing techniques such as scaling,
AR and MDS 2022-23
rotating, translating or shearing.
To scale an AR object inserted in a webcam image using MATLAB, we need to modify the dimensions
of the object image before overlaying it on the webcam feed. This can be achieved by using the
imresize function in MATLAB, which resizes an image to a specified size.
To implement scaling functionality in the MATLAB program, we can first read in the object image
using the imread function. Then, we can calculate the current size of the object image using the size
function. After that, we can define a new size for the object image and use the imresize function to
resize the object image to the new size.
To change the size of the object image in real-time, we can use a slider or any other user input
method to adjust the new size of the object image. Whenever the user changes the size of the object
image, we can update the size of the resized object image using the imresize function and overlay it
on top of the webcam feed.
The accuracy and precision of the scaling functionality can be evaluated by comparing the size of the
AR object on the webcam feed to its actual size. This can be done by placing an object of known
size next to the AR object in the webcam feed and comparing their sizes.
After resizing the object image, we can overlay it onto the camera feed using techniques such as
alpha blending or simple addition. The overlay process involves defining a region of interest on the
camera feed where the object image should be placed, and then blending the object image with the
pixels in that region.
It is important to note that scaling an inserted AR object can be challenging, especially in real-time
applications where processing time is limited. To achieve real-time performance, we may need to
optimize the code and use efficient algorithms to resize and overlay the AR object on the camera
feed.

3 Code:
3.1 Tool Used/language:
Using AR (Augmented Reality) with MATLAB provides a powerful platform for developing AR
applications. MATLAB provides various toolboxes and functions for computer vision, image processing,
and machine learning, which can be used to develop AR applications. These toolboxes and functions
enable MATLAB users to develop AR applications that can detect markers, track objects, and overlay
virtual content on real-world scenes.
In MATLAB, AR applications can be developed using the Image Processing Toolbox, Computer
Vision Toolbox, and the Robotics System Toolbox. These toolboxes provide functions for image
acquisition, feature extraction, feature detection, image registration, and projection, which are
AR and MDS 2022-23
essential for AR applications. MATLAB’s Simulink also provides blocks that can be used for AR
application development.
To develop an AR application in MATLAB, the following steps can be followed:
1. Capture video frames: Capture video frames from a camera or a video file using MATLAB’s
video capture functions.
2. Detect markers or features: Use MATLAB’s computer vision functions to detect markers or
features in the video frames that can be used to anchor virtual objects in the real world.
3. Track objects: Use MATLAB’s tracking algorithms to track the detected markers or features
across multiple video frames.
4. Render virtual objects: Use MATLAB’s 3D graphics capabilities to render virtual objects and
overlay them onto the real-world scene.
5. Project virtual objects: Use MATLAB’s projection functions to project the virtual objects onto
the real-world scene based on the position and orientation of the markers or features detected
in the video frames.
6. Display the augmented video: Display the augmented video on the screen or export it to a
video file.

3.2 Programs:
clc;
clear all;
close all;
cam = webcam(1);
objectImg = imread(’images.png’);
objectImg = imresize(objectImg, [480, 640]);
videoPlayer = vision.VideoPlayer(’Position’, [100, 100, 640, 480]);

[objectHeight, objectWidth, numChannels] = size(objectImg);

while true
frame = snapshot(cam);
frame = rgb2gray(frame);
[frameHeight, frameWidth, numChannels] = size(frame);
if objectHeight = frameHeight —∥ objectW idth = f rameW idth
objectImg = imresize(objectImg, [f rameHeight, f rameW idth]);
end
AR and MDS 2022-23
scaleFactor = 0.5;
scaledHeight = round(objectHeight * scaleFactor);
scaledWidth = round(objectWidth * scaleFactor);
scaledObjectImg = imresize(objectImg, [scaledHeight, scaledWidth]);

overlayFrame = imadd(frame, scaledObjectImg);

step(videoPlayer, overlayFrame);
end

3.3 Output:
Scale = 1:

Scale = 0.5:
AR and MDS 2022-23

4 Post Lab Question:


1. How can the ability to scale AR objects in real-time be useful in different applications?
The ability to scale AR objects in real-time can be useful in many different applications. Some
examples include:
(a) Education: AR technology can be used to create interactive learning experiences for
students. For example, an AR object of a human heart can be scaled up or down to
show different parts of the organ and explain their functions.
(b) Architecture and design: AR technology can be used to create scaled 3D models of
buildings or products. This allows architects and designers to visualize their projects
in real-time and make necessary changes.
(c) Gaming: AR technology can be used to create immersive gaming experiences. For
example, players can interact with AR objects that are scaled to their real-world environment.
(d) Retail: AR technology can be used to create virtual try-on experiences for customers. For
example, customers can use their smartphone cameras to view AR objects of clothing or
accessories scaled to their size and try them on virtually.
(e) Healthcare: AR technology can be used to create interactive medical simulations. For
AR and MDS 2022-23
example, an AR object of a patient’s body can be scaled to show different organs or
systems and explain their functions.
2. Can you think of any other computer vision techniques that could be used in conjunction with
AR object scaling to create more advanced AR experiences?
There are several computer vision techniques that can be used in conjunction with AR object
scaling to create more advanced AR experiences. Here are a few examples:
(a) Object tracking: Object tracking is a computer vision technique that allows AR objects to
follow a real-world object as it moves around. This can be used to create more immersive
AR experiences, such as virtual pet games where the pet can follow the user around the
room.
(b) Image recognition: Image recognition is a computer vision technique that allows AR
objects to be triggered by specific images. For example, an AR object of a car could be
triggered when the user points their camera at a picture of a car.
(c) Gesture recognition: Gesture recognition is a computer vision technique that allows AR
objects to be controlled using hand gestures. This can be used to create more interactive
AR experiences, such as virtual music instruments that can be played by moving your
hands in specific ways.
(d) 3D reconstruction: 3D reconstruction is a computer vision technique that allows AR
objects to be placed in a 3D environment. This can be used to create more immersive AR
experiences, such as virtual tours of historic sites or museums.
(e) Real-time object detection: Real-time object detection is a computer vision technique
that allows AR objects to be placed on real-world objects in real-time. This can be used
to create more interactive AR experiences, such as virtual games where the user has to
catch AR objects as they fly around the room.

5 Conclusion
1. We successfully inserted an AR object in webcam feed and scaled in real-time using MATLAB.
2. We explored the various applications of scaling AR objects in webcam feed as well as the
computer vision techniques that can be used in conjunction with AR object scaling.

References
[1] Anónimo, A. (2008). Blog del año 2002 con un formato horrible. http://www.blogfeo.
blogspot.com.
AR and MDS 2022-23
[2] Mendoza, S. and Duende, J. (2022). Libro apantallante que probablemente no leı́ste y solo lo
pusiste por poner algo. Ediciones Tepito, 1st edition.

[3] Pérez, J. (2008). Artı́culo de dudosa calidad de una página web patito. Recuperado de: https:
//XD.com. Fecha de consulta: 03/11/2021.

You might also like