Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Automatically Record Webcam Video
1. P Chodon, Devi Maya Adhikari , G C Nepal, R Biswa, S Gyeltshen, Chencho| Webcam Driver to
Automatically Record and Save Video Captured when the Webcam is connected
IFRSA’s International Journal Of Computing |Vol 3|issue 3|July 2013 200
Webcam Driver to Automatically Record and Save Video
Captured when the Webcam is connected
Pema Chodon1, 2
, Devi Maya Adhikari1, 3
, Gopal Chandra Nepal1, 4
, Rajen Biswa1, 5
, Sangay Gyeltshen1,6
,
Chencho1,7
1
Department of Electronics and Communication, College of Science and Technology, Royal University of
Bhutan, Phuentsholing, Bhutan
ABSTRACT
This paper presents software developed to be used with
a webcam. It was developed using Microsoft Visual
C++ 2010 and OpenCV 2.4.4 library files. It can be
used to record and save video automatically when the
webcam is connected to the computer. The program is
installed and made to run. It will keep checking if the
webcam is connected or not. When the webcam is
connected to the computer, the system detects it and
starts to record video captured by webcam. Once the
webcam is disconnected from the computer, the
program saves the previous recorded video and again, it
will check for webcam connection. The developed
software program can be used to automatically record
and save video captured when the webcam is connected
to the computer.
Keywords— Webcam, Algorithm, Visual C++,
OpenCV
1. INTRODUCTION TO MICROSOFT
VISUAL C++ AND OPENCV
The software program has been developed using
Microsoft Visual C++ 2010 integrating with OpenCV
2.4.4 library files. OpenCV library files allows generic
image/video loading, saving, and acquisition [1]. C++ is
regarded as a middle-level language, as it comprises a
combination of both high-level and low-level language
features. Thus OpenCV library files have been
integrated in Microsoft Visual C++ 2010 for capturing,
recording and video acquisition.
Microsoft Visual Studio is an integrated development
environment (IDE) from Microsoft. It is used to
develop console and graphical applications along with
Windows Form applications, web sites, web
applications, and web services for all platforms
supported by Microsoft Windows, Windows
Mobile, .NET Framework and .NET Compact
Framework [2]. Visual Studio supports
different programming languages by means of language
services, which allow the code editor and debugger to
support (to varying degrees) nearly any programming
language, provided a language-specific service exists.
From these supported languages we use Microsoft
Visual C++ 2010 express edition for writing our
program [3].
OpenCV (Free Open Source Computer Vision) is a
library of programming functions mainly aimed at real
time computer vision. It has a BSD license (free for
commercial or research use). OpenCV was originally
written in C but now has a full C++ interface and all
new development is in C++. There is also a full Python
interface to the library [4].
The OpenCV was selected due to following features:
Open source computer vision library in
C/C++.
Optimized and intended for real-time
applications.
OS/hardware/window-manager independent.
Generic image/video loading, saving, and
acquisition.
Both low and high level API.
Easy integration of its library files with MS
visual C++
As to let the software developed to run successfully,
integration of Microsoft Visual C++ with the OpenCV
library files was done. The library files included are [5]:
opencv_core244.lib: This is the basic building
block of the library for understanding how to
manipulate the images on a pixel level.
International journal of Computing
Journal homepage: www.ifrsa.org
2. P Chodon, Devi Maya Adhikari , G C Nepal, R Biswa, S Gyeltshen, Chencho| Webcam Driver to
Automatically Record and Save Video Captured when the Webcam is connected
IFRSA’s International Journal Of Computing |Vol 3|issue 3|July 2013 201
opencv_imgproc244.lib: This is for the image
processing (manipulation) functions inside
OpenCV
opencv_highgui244.lib: How to read/save your
image/video files and how to use the built-in
graphical user interface of the library.
opencv_ml244.lib: Use the powerful machine
learning classes for statistical classification,
regression and clustering of data.
opencv_video244.lib: Use on your video
stream algorithms like: motion extraction,
feature tracking and foreground extractions.
opencv_features2d244.lib: This is to use the
feature point detectors, descriptors and
matching framework found inside OpenCV.
opencv_calib3d244.lib: Although most of our
images are in a 2D format they do come from
a 3D world. This is use to find out from the 2D
images information about the 3D world.
opencv_objdetect244.lib: Detects peoples and
faces
opencv_contrib244.lib: How to process images
and video streams with a model of retina filter
for details enhancement, spatio-temporal noise
removal, luminance correction and spatio-
temporal events detection.
opencv_flann244.lib: It is used in Clustering
and Search in Multi-Dimensional Spaces. This
section documents OpenCV’s interface to the
FLANN library. FLANN (Fast Library for
Approximate Nearest Neighbours) is a library
that contains a collection of
algorithms optimized for fast nearest neighbour
search in large datasets and for high
dimensional features.
2. WORKING OF PROGRAM
The objective of this software is to automatically save
the video captured by the webcam when it is connected
to the computer. The system need not have to open the
webcam application and click on the button to record.
The program is made run in the system. As soon as
webcam is connected, it will automatically detect the
webcam and recording will take place.
A. Algorithm
The proposed program should follow the following steps
of algorithm:
1. Start the program: Gets date and current local
time in the format date_month_year hr_min.
2. Check whether the webcam is connected or not.
If the webcam is connected, start saving the
video until the webcam is disconnected. It uses
the following functions to record and save the
video captured by webcam:
i. cvCapture
ii. cvCreateCameraCapture
iii. cvQueryFrame(capture),
iv. cvGetCaptureProperty,
v. cvNamedWindow,
vi. CvVideoWriter,
vii. cvWriteFrame
viii. cvWaitKey
ix. cvReleaseVideoWriter
x. cvReleaseCapture
3. Save the video
4. Continue to check if the webcam is connected
and step 2 and 3 are repeated.
Int main( int argc, char** argv )
{
startcam:
time_t now = time(0);
struct tm tstruct;
char buf[80];
tstruct = *localtime(&now);
strftime(buf,sizeof(buf)," %d_ %m_ %Y
%H_ %M", &tstruct);
string GetTime=buf;
string TimeinString=
GetTime.append(".avi");
char* p = new
char[TimeinString.length() + 1];
strcpy(p,
TimeinString.c_str());
cout<<"n Finishd Saving Video n";
cvDestroyWindow("Webcam");
goto startcam;
3. P Chodon, Devi Maya Adhikari , G C Nepal, R Biswa, S Gyeltshen, Chencho| Webcam Driver to
Automatically Record and Save Video Captured when the Webcam is connected
IFRSA’s International Journal Of Computing |Vol 3|issue 3|July 2013 202
B. Flow Chart
Start
Check if webcam is
connected
Start Recording the video
Save the Recorded the video
YES
NO
Figure 1: Flow Chart
C. Video streaming and saving
The program automatically captures and records the live
video when the webcam is connected to the computer.
The captured video is saved in the computer.
For the naming purpose of the saved video file a
function to call the computer’s system time with year,
month, date, hour and minute is used. The complete
name looks like “31_05_2013 15_16.avi”. This file
name is converted from string to character type and
passed to the video writer function of OpenCV library
file. As no path is given, the recorded video file is saved
in same directory as the program file.
3. TESTING THE PROGRAM
For testing the working of the program it was first
converted to the executable file so that it can be used
from any computer system independent of the MS
Visual C++ and OpenCV software.
Figure 2: When webcam is not connected
The program was kept running. When the program was
started, it immediately checks if the webcam is
connected to the system or not. The program will keep
on looping until it finds the webcam is being connected
to the system as shown in Figure 2.
When the webcam was connected to the system, the
program detects the webcam connection. The recording
of captured video by the webcam takes place shown in
Figure 3 [6].
Figure 3: When the webcam is connected and
recording
When the webcam is removed from the computer, the
software will finish saving video and the program again
proceed to check the status of webcam as shown in
Figure 4.
4. P Chodon, Devi Maya Adhikari , G C Nepal, R Biswa, S Gyeltshen, Chencho| Webcam Driver to
Automatically Record and Save Video Captured when the Webcam is connected
IFRSA’s International Journal Of Computing |Vol 3|issue 3|July 2013 203
Figure 4: After recording and webcam is removed
So every time when the webcam is connected to the
computer, the recording and saving takes place
automatically.
4. ANALYSIS
When the webcam is connected to the system, there was
time delay for the program to detect that the webcam
and to start recording the video. This is because the
program needs to check the computer’s hardware for the
availability of the webcam and if it is connected to the
system; the computer in turn has to load the drivers
when the webcam gets connected. The delay is
approximately 15 seconds.
5. FUTURE WORKS
There was certain delay in recording the video captured
by webcam. Also the executable software is not very
user friendly as the screen appears quite plain and user
may not prefer it. Considering above points, following
two future works are set to improve the performance of
the software:
Work on software to reduce the delay time in
recording the video captured by webcam.
Make the software more users friendly using
Graphical User Interface (GUI).
6. CONCLUSION
In this paper we have proposed a software program used
to record the video captured by a webcam automatically
when it is connected to a computer. The software
developed was tested and found to be working with
some time delay to start recording. Software will be
more efficient if this delay time could be minimized.
This software was actually developed for a PIR sensor
based security system where the webcam gets actuated
when PIR sensor detects an object in its detection range.
When the webcam is actuated, the software detects the
webcam is ON and starts to record video captured by the
webcam.
REFERENCES
[1] Anonymus, “OpenCV documentation,”
[Online] http://docs.opencv.org/index.html,
April 2013.
[2] Anonymous, “Tutorials Point,” [Online].
http://www.tutorialspoint.com/cplusplus/cpp_o
verview.htm
[3] Anonymous, “Mathematics and Computer
Science,” South Dakota School of Mines and
Technology. [Online].
http://www.mcs.sdsmt.edu/csc150/Handouts/V
isual%20C++%202010%20Tutorial.pdf, Jan.
2012
[4] Gady Agam, “Department of Computer
Science,” [Online].
http://www.cs.iit.edu/~agam/cs512/lect-
notes/opencv-intro/, Jan. 2007.
[5] Anonymous, “highgui. High-level GUI and
Media I/O,” [Online].
http://docs.opencv.org/modules/highgui/doc/hi
ghgui.html, April, 2013.
[6] P. Chodon, D. M. Adhikari, G. C. Nepal, R.
Biswa, S. Gyeltshen and Chencho, "Passive
Infrared (PIR) Sensor Based Security System,"
(IJEECS) International Journal of Electrical,
Electronics ad Computer Systems, vol. 14, no.
2, 2013.