Virtual Canvas for Interactive Learning Using OpenCV
Virtual Canvas for Interactive Learning Using OpenCV
Dipti Jadhav
Computer Engineering
Don Bosco Institute of Technology
Mumbai, India
[email protected]
2022 IEEE 3rd Global Conference for Advancement in Technology (GCAT) | 978-1-6654-6855-8/22/$31.00 ©2022 IEEE | DOI: 10.1109/GCAT55367.2022.9971903
2
Authorized licensed use limited to: HKBK College of Engineering. Downloaded on December 06,2024 at 07:47:29 UTC from IEEE Xplore. Restrictions apply.
Describing the flowchart, the first step for the user is to have one particular colored object available with the user so
select the color of the object. The range of the color selected restricting the user to have just one colored object is not a
is passed, the live video is captured and then the captured good idea. So, the model allows user to select four different
frame is flipped since it is a mirror image. The captured colors (Blue, Green, Red and Yellow) for the object color
video is then converted into HSV color range. Once the live selection.
frame appears on the screen all the color buttons and clear
button is displayed on the live frame along with the keyboard Initially when the Frame is captured it is captured in Blue
shortcuts. For the user to write in the air through their (255, 0, 0), Green (0, 255, 0), Red (0, 0, 255) that is BGR
gesture, the model will detect the object using the spacebar color space to detect the colored object easily and quickly
key. If the object is not detected a display message appears into Hue saturation value color space [2]. Various function
saying “object not within the camera range" so the user will like cv2.cvtCOLOR(), cv2.inRange(), Cv2.dilate() were used
have to bring the object within the camera range and will to converts the color-space, and create binary segmentation
have to press the space bar key again. Once the object is and to increase segmentation respectively [8]. After this the
detected color masking is done followed by the background upper Hue saturation value and lower Hue saturation value
subtraction. Next step is to find the contour. Contour is an of four different colors (Blue, Green, Red and Yellow) are
object with same color intensity and then the centre is found stored in NumPy arrays (np.array).
on the object. If contour is not detected the centre is set to C. Frame Reading
zero else the centre is found on the contour. Followed by this To capture the video in real time cv2.VideoCapture is
the user can see the output on both the screen that is the live used. This is a module of the OpenCV library. It creates a
frame and the white board. If the user wants to exit Virtual video object that would help stream or display the video. The
canvas then they will need to press esc key and the system video captured is mirror video which is then flipped by the
closes or stops running. model using cv2.flip. Also, the captured frame is in BGR
IV. SYSTEM METHODOLOGY color space which is then converted into HSV color frame
[8].
This section gives details about the different parts of the
model. Starting from IV-1 which is the Graphical User
Interface needed for selecting the object color with the help
of arrays followed by Image Segmentation that includes
frame reading and background subtraction [3], Image
Processing which is detecting the contour [4] for object
detection and finally the output which is draw on canvas that
makes use of keyboard keys. Fig.2. is the architecture of the
model
3
Authorized licensed use limited to: HKBK College of Engineering. Downloaded on December 06,2024 at 07:47:29 UTC from IEEE Xplore. Restrictions apply.
easily switch between the five colors (Blue, Green, Red, H. Keyboard Keys
Yellow, and Pink) according to the users needs. Selected Filling the canvas (live window) with least used buttons
color appears slightly bigger than the unselect color. will occupy a lot of space which leaves with less writing
To store and handle the color points of the five colors space. So, for better user interactivity shortcuts keys were
(Blue, Green, Red, Yellow, Pink) five different arrays were provided. In total there are 6 shortcut keys, they are – (z) to
created along with color index (initially set to 0) which is undo changes, (+) to increase brush thickness,(-) to decrease
used to mark points of a specific array of that particular color brush thickness, (numbers 1 to 5) to change brush color,
[10]. The Maximum length of the color point of the colors is (s/clt s) to save and (q/esc) to quit the program. These
set as 1024. features work with the help of the keyboard module in
python. Whiteboard is in sync with the canvas (live window)
At the top left-corner of the Canvas Window (live frame) so the delay time is 0.
clear button is placed for easy access. Clear button clears all
the writing in both the screen (canvas and whiteboard) before To start writing in the air and for the model to detect the
or after saving the writing (depends on the user). object and draw points at each and every position on the
canvas and the whiteboard, user needs to press the spacebar
The five different arrays that were created to store and key. The gestures will be detected and then the output would
handle the color points of the five colors (Blue, Green, Red, be displayed.
Yellow, Pink) are all dequeued and the color index of the
five colors (Blue, Green, Red, Yellow, Pink) are initialized to
0
E. Color Masking
Color masking process creates mask of the object using
the function cv2.erode which creates a boundary of the
object detected and fills it with white [3] and then Fig.6. Three saving modes
background subtraction is performed simultaneously where
the background is changed to black using the function Fig.6. shows the save shortcut key and its 3 modes –
bgModel.apply [8]. Canvas, whiteboard, blackboard. The user can save in any of
the 3 modes. The images saved will be in PNG format at the
F. Contour Detection user’s desired location.
The model then detects the contours which is the shape of
the object found with similar HSV color intensity. This is V. EXPERIMENTS
done using cv2.findContours. As there is a possibility of A. Experiment Details
finding many contours the model will find the biggest
The model was tested in different backgrounds with
contour among all the contours found [4].
different light settings. The backgrounds included indoor and
outdoor environments. In indoor environments the model
was tested with a plain white background and with cluttered
background that included multiple colors in the background.
Three types of lighting was considered that is very bright
(brightness intensity 80%), normal (brightness intensity
40%) and very dark (brightness intensity 5%). The accuracy
rate is generated by testing the model for 5 minutes by using
all the features and different color objects.
For outdoor environments the backgrounds were a train
platform where people were moving constantly and a still
Fig.5. Contour Detection background that is in a garden with less movement in the
background. The lightings considered are very bright and
This helps in reducing the errors regarding same very dark. This is because in outdoor environments lighting
background and object color. Then with the help of cannot be adjusted. Two cameras with different Megapixels
cv2.circle a circle is formed over the object and then the are used to indentify best accuracy.
center (C) of the object is calculated as seen in Fig.5. using
the formula (1) B. Results and Discussion
The movement of the object is detected and is visible on
ଵ ଵ the video screen with five different colors buttons, a clear all
ܥൌ ǡ (1) button and display message of the selected color at the top of
Here, C = mass center the screen. Also, the whiteboard is in sync with the canvas.
m10, m01, m00 = spatial moments There are a number of options to pick from which include
various system modes that serve various functionalities.
G. Draw on Canvas Basic Functionality of the model include
After completing the above steps, the user can finally draw
x Virtual Canvas -The system will trace the
and write in the air easily and the model will track the object
movement of the object and display them in real
and will form points at each position for the air canvas
time.
effect. Then the model will display the video frame by
x Whiteboard - The system will trace the movement
frame. The function used here is imshow().
of the object and display them in whiteboard
4
Authorized licensed use limited to: HKBK College of Engineering. Downloaded on December 06,2024 at 07:47:29 UTC from IEEE Xplore. Restrictions apply.
x Color options - The user can select a different color From the experiments conducted we can conclude that
for the text from the available options. the model gives accurate results in plain background whether
x Clear all – Clear all clears the characters on the that is in indoor or outdoor environments. The quality of the
screen and provides a clean space to write on. camera plays a very important role for accuracy when
background is cluttered. For outdoor environments with
The model gives different accuracy rates when placed in crowded background the accuracy can be increased if the
different backgrounds. Tables 1 and 2 give a view of the camera quality is increased.
accuracy rates in different environments. VI. CONCLUSION
TABLE I. ACCURACY RATES FOR INDOOR ENVIRONMENTS The user is able to draw and write on the screen with ease
on a virtual canvas, allowing them to effectively interact with
Test Camera Back- Lighting Accuracy others. This technology has the ability to put standard writing
No. Quality ground (%) methods to the test. We covered various types of
1 1.3 MP Plain Very 94%
technologies that could be employed to construct this system.
White Bright
Virtual canvas works well with a good quality camera as
2 1.3 MP Plain Normal 98%
well as a clear background. Few challenges were faced if the
White
room is exposed to too much sunlight or in cluttered
3 1.3 MP Plain Very 91%
White Dark background which results in weak object color detection .
4 1.3 MP Cluttered Very 90% Excluding these challenges Virtual canvas strikes to be an
(many Bright excellent software for interacting with the digital
objects) environment. This model can now produce the output that
5 1.3 MP Cluttered Normal 98% our group had envisioned, and it will be enhanced in the
(many future to include new features and improve efficiency.
objects)
6 1.3 MP Cluttered Very 86% REFERENCES
(many Dark [1] Rajesh D, Yamini C “A Review on Object Detection using OpenCV”
objects) in International Journal of Innovative Technology and Exploring
Engineering (IJITEE)
7 5 MP Cluttered Very 94%
(many Bright [2] Suraj S, Shende, Vikas S, Bharti P “Real Time Object Detection
using Deep-Learning and OpenCV” in International Research Journal
objects) of Engineering and Technology (IRJET)
8 5 MP Cluttered Very 92%
[3] Mohamed, Shahrizat Shaik, Nooritawati Md Tahir, and Ramli Adnan.
(many Dark “Background modelling and background subtraction performance for
objects) object detection.” 2010 6th International Colloquium on Signal
Processing & its Applications. IEEE, 2010.
TABLE II. ACCURACY RATES FOR OUTDOOR ENVIRONMENTS [4] Raghav P, ArchitG , Manas S, in “Contour, Shape & Color Detection
using OpenCV-Python” in International Journal of Advances in
Test Camera Back- Lighting Accuracy Electronics and Computer Science
No. Quality ground (%) [5] Mitra, Sushmita. Senior Member, IEEE, and Tinku Acharya, Senior
1 1.3 MP Crowded Very 81% Member, IEEE,“Gesture Recognition: A Survey”. IEEE Transactions
(People Bright On Systems, Man, And Cybernetics—part C: Applications And
walking) Reviews 37.3 (2007): 311.
2 1.3 MP Crowded Very 84% [6] Chen, Mingyu, Ghassan AlRegib, and Biing-Hwang Juang. “Air-
(People dark writing recognition—Part I: Modeling and recognition of characters,
walking) words, and connecting motions.” IEEE Transactions on Human-
Machine Systems 46.3 (2015): 403-413.
3 5 MP Crowded Very 89%
(People Bright [7] Chen, Mingyu, Ghassan AlRegib, and Biing-Hwang Juang. “Air-
writing recognition—Part II: Detection and recognition of writing
walking)
activity in continuous stream of motion data.” IEEE Transactions on
4 5 MP Crowded Very 91% Human-Machine Systems 46.3 (2015): 436-444.
(People dark [8] Vandit G “Real Time Color Segmentations and Color Filtration” in
walking) IJSRD National Conference on Advances in Computer Science
5 1.3 MP Plain Very 94% Engineering & Technology May 2017
Bright [9] D. U. Lakshmi and B. Harish, "A novel air writing recognition system
6 1.3 MP Plain Very 91% using Raspberry Pi for the control and interaction of digital systems,"
Dark 2017 International Conference on Energy, Communication, Data
7 5 MP Plain Very 94% Analytics and Soft Computing (ICECDS), 2017
Bright [10] S.U. Saoji, Nishtha D, Akash C, B Phogat “Air canvas application
8 5 MP Plain Very 92% using Open CV and numpy in python” in (IRJET) Volume: 08 Issue:
08 | Aug 2021
dark
5
Authorized licensed use limited to: HKBK College of Engineering. Downloaded on December 06,2024 at 07:47:29 UTC from IEEE Xplore. Restrictions apply.