Capturing Webcam through VB6.0



Similar documents
Visual Basic Programming. An Introduction

Creating Datalogging Applications in Microsoft Excel

A Microsoft Access Based System, Using SAS as a Background Number Cruncher David Kiasi, Applications Alternatives, Upper Marlboro, MD

Using the Remote Access Library

Visual Basic and OPC All versions of Kepware OPC Servers 10/23/03

UniFinger Engine SDK Manual (sample) Version 3.0.0

MS Active Sync: Sync with External Memory Files

User Manual Microsoft Dynamics AX Add-on LabAX Label Printing

1 Intel Smart Connect Technology Installation Guide:

Introduction to Visual Basic

Practice Fusion API Client Installation Guide for Windows

E-Map Application CHAPTER. The E-Map Editor

Using Intel Visual Fortran to Create and Build Windows*-Based Applications

EWF Management Software Windows driver software for Classembly Devices /Industrial Controller

USER MANUAL SlimComputer

APPLICATION NOTE. Getting Started with pylon and OpenCV

ICS Technology. PADS Viewer Manual. ICS Technology Inc PO Box 4063 Middletown, NJ

7-1. This chapter explains how to set and use Event Log Overview Event Log Management Creating a New Event Log...

Remote Access Server - Dial-Out User s Guide

S7 for Windows S7-300/400

Contents. Introduction. Chapter 1 Some Hot Tips to Get You Started. Chapter 2 Tips on Working with Strings and Arrays..

NETWRIX CHANGE NOTIFIER

Analatom, Inc., 3210 Scott Blvd., Santa Clara, CA Phone: (408) Fax: (408)

Unleashing Hidden Powers of Inventor with the API Part 1. Getting Started with Inventor VBA Hello Inventor!

ClientAce WPF Project Example


How-To Guide. Crystal Report Demo. Copyright Topaz Systems Inc. All rights reserved.

SafeGuard PrivateCrypto 2.40 help

Viewing and Troubleshooting Perfmon Logs

13 Managing Devices. Your computer is an assembly of many components from different manufacturers. LESSON OBJECTIVES

Database Automation using VBA

Visual Basic and Databases

Event Log. Chapter 7 Event Log Event Log Management Excel Editing Create a New Event Log... 9

Chapter 16. Using Dynamic Data Exchange (DDE)

The VB development environment

Web Portal User Guide. Version 6.0

Importing and Exporting With SPSS for Windows 17 TUT 117

Lab 8: ASP.NET 2.0 Configuration API and Health Monitoring

How to test and debug an ASP.NET application

Using Process Monitor

Application Power Management for Mobility

MONITORING PERFORMANCE IN WINDOWS 7

First Steps with CoDeSys. Last update:

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Outline: Operating Systems

Freescale Semiconductor, I

Changing the Display Frequency During Scanning Within an ImageControls 3 Application

PowerPoint Interface Menu Bars Work Area Slide and Outline View TASK PANE Drawing Tools

Visual Basic 2010 Essentials

DiskPulse DISK CHANGE MONITOR

Installation guidance ProjectWise Explorer

While Loops and Animations

Apache Logs Viewer Manual

Many applications consist of one or more classes, each containing one or more methods. If you become part of a development team in industry, you may

Python for Series 60 Platform

Click Here -> El poder de la Programación de Excel y Visual Basic - Scam or Work?

Communicate with Test Instruments Over LAN Using Visual Basic

"SQL Database Professional " module PRINTED MANUAL

Deploying Microsoft Operations Manager with the BIG-IP system and icontrol

CUSTOM APPLICATION INTERFACE LIBRARY MANUAL (PROGRAMMING SECTION) BNP-B2197 (ENG)

Hands-On Lab. Client Workflow. Lab version: Last updated: 2/23/2011

Chapter 11 Compound Documents in Windows 3.1

Introduction to the TI Connect 4.0 software...1. Using TI DeviceExplorer...7. Compatibility with graphing calculators...9

Call Recorder Quick CD Access System

UNICORN 7.0. Administration and Technical Manual

The Real-Time Operating System ucos-ii

Preparing to Install SQL Server 2005

CamGuard Security System CamGuard Security System Manual

Section 8 Scheduler. Alcatel-Lucent OmniVista 4760 Network Management System

Loading pictures with ActiveX and VBScript Copyright InduSoft Systems LLC 2006

Data Tool Platform SQL Development Tools

Event Log. Chapter 7 Event Log Event Log Management Excel Editing Create a New Event Log... 10

Visual Studio 2008: Windows Presentation Foundation

Visual Studio 2008 Express Editions

HarePoint Workflow Scheduler Manual

TS2Mascot. Introduction. System Requirements. Installation. Interactive Use

Using Microsoft Word. Working With Objects

LDCDP GdW. L force Controls. Ä.GdWä. Software Manual. Industrial PC. WindowsR CE Thin Client. Operating system

How to start with 3DHOP

Ohio University Computer Services Center August, 2002 Crystal Reports Introduction Quick Reference Guide

by NetMedia, Inc. All rights reserved. Basic Express, BasicX, BX-01, BX-24 and BX-35 are trademarks of NetMedia, Inc. 2.

TSM Studio Server User Guide

Release Notes FlexPendant SDK

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Operating system Dr. Shroouq J.

Universal Simple Control, USC-1

HTML Code Generator V 1.0 For Simatic IT Modules CP IT, IT, IT

ProCAP Transfer with Omneon Interface

Fireworks 3 Animation and Rollovers

USER GUIDE Appointment Manager

ELFRING FONTS UPC BAR CODES

Tutorial for Avaya 4600 and 9600 Series IP Telephones Push and Browser Applications Setup

1 The Gigalog S board send regularly its data by ftp to the database. The board may also send information about the board, like the GPS position.

How to install and use the File Sharing Outlook Plugin

Sharing Presentations, Documents, and Whiteboards

EB8000 User Manual. Table of Contents

Capturing Network Traffic With Wireshark

Features - Microsoft Data Protection Manager

Transcription:

Capturing Webcam through VB6.0 Author: Punit Ganshani Email Address: punit@ganshani.com Downloaded from http://www.ganshani.com Published In: DeveloperIQ, September 2005, Asia While I write this article, I am referring to a real-time system that captures the images when needed through a web cam, placed in one corners of the library. The need of the hour was to keep a central monitoring system so that the librarian could have a sight over the people in the library and their behavior. And while I was designing this system, the first important step was to activate a webcam through my software that could show the frames capture the images when needed. These images could be stored on the hard disk and viewed through and picture editor. The user should have the facility to save the image in any of the three universal image formats i.e. Bitmap, GIF and JPG. After development phase of the same, the goal was to have automatic capturing of the images and storing it with file name of the format: c:\lbsystems\images\date\pb####.jpg The desired frequency of capturing an image was once in every 5 minutes. Thus in a day having 24 hours having 1440 minutes, 288 pictures can be captured. So the numbering could follow a pattern from 0000 to 0287 having filename pb0000.jpg to pb0287.jpg In this article, I am presenting a part of my software which concerns capturing a picture from webcam when the user intends to do the same. I leave the further programming part to the user which is application dependent. Using Dynamic Link Libraries Visual Basic can communicate directly to Windows Application Programming Interface (API) which are defined in dynamic link

libraries (abbreviated as DLL s) that are stored in \windows\system directory. Some of the core DLL files Windows supports are listed in the table 1. Table 1: DLL supported by Windows Sr. No DLL Applications it supports 1 user32 User Interface Routines 2 winmm Multimedia 3 advapi Security & Registry Calls 4 gdi32 Graphics Device Interface 5 kernel32 32-bit Windows applications 6 shell32 32-bit Shell applications However we need not remember the DLL and their function because they are directly being called by API. The functions of API can be viewed using API Viewer (a tool provided in Microsoft Visual Studio Package) and is shown in Figure 1. Figure 1: API Viewer - Win32api.txt

Let s see the Item : SendMessage which we shall in our program. The SendMessage is defined in API as under: Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wmsg As Long, ByVal wparam As Long, lparam As Any) As Long Let s understand the syntax of this function. Function Name: SendMessage Actual Windows Function Name: SendMessageA DLL: user32 Arguments & their types: hwnd handle Handle of the Window wmsg unsigned int Message to be sent wparam unsigned int Message-specific information lparam long Message-specific information The other API reference that we shall use is defined in AVICAP32.DLL and is called as capcreatecapturewindow. The function call is as under: Public Declare Function capcreatecapturewindow Lib "avicap32.dll" Alias "capcreatecapturewindowa" (ByVal lpszwindowname As String, ByVal dwstyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nwidth As Long, ByVal nheight As Long, ByVal hwndparent As Long, ByVal nid As Long) As Long Public mcaphwnd As Long Now let s see the core programming of webcam using these API calls. Designing Form & Coding The form designed can be considered to have following elements: Control Number of objects Name Picture Box 2 piccapture Timer 1 tmrmain Common Dialog 1 CommonDialog Command Buttons 5 cmdstart cmdstop

cmdsaveas cmdcopy cmdexit However to provide alignment, we can introduce frames or picture boxes. I have kept two additional picture boxes; one of it has the command buttons, the other one has the common dialog. We can avoid the Start button that is used to initialize web cam and start the webcam as soon as the form is loaded. Similarly Stop button can also be omitted as the picture can also be captured and saved by Save As button. Initially, Stop button is kept disabled. This Save As option can be later modified to capture images at a regular interval without requiring user interface and in that case, we can keep the form as small as an Exit button (the picture box can be kept invisible too!) The timer is used to refresh webcam images. Let us not analyze the code. Private Sub cmdstart_click() mcaphwnd = capcreatecapturewindow("webcamcap", 0, 0, 0, 320, 240, Me.hWnd, 0) 'Get hwnd for webcam so we can use it DoEvents: SendMessage mcaphwnd, 1034, 0, 0 'Capture from webcam tmrmain.enabled = True 'Enable timer to refresh webcam images cmdstop.enabled = True 'Make stop button enabled The first statement calls a API function and as per the syntax mentioned before, WebcamCap is the window name, the first 0 corresponds to the style, second and the third 0 indicate x and y co-ordinates of capturing window, 320 is the width of capture window and 240 is the height, me.hwnd is the handle of the current window and the last 0 is the Window Identifier. The style of the window can be set by CreateWindowEx(). The function capcreatecapturewindow returns a handle of the capture window if successful or NULL otherwise. We then send a specific message to a window. This message code is 1034. By the number 1034, the computer interprets connection of webcam.

The similar concept is used to stop the webcam. The code will appear as: Private Sub cmdstop_click() tmrmain.enabled = False 'Disable refreshing of webcam images DoEvents: SendMessage mcaphwnd, 1035, 0, 0 'Stop capturing of images from webcam cmdstart.enabled = True 'Make start enabled cmdstop.enabled = False We have used a common dialog control through which we can save the image file when clicked on Save As. So, the code for saving the image will be: Private Sub cmdsaveas_click() CommonDialog.Filter = "Jpeg (*.JPEG) *.JPG" 'Supported file-type is JPG since it is compressed format CommonDialog.ShowSave 'Show save dialog SavePicture piccapture.image, CommonDialog.FileName Save picture on any drive configured on PC this also includes established LAN drives The first line of the code for saving is used to define the default type of file that can the user can give. However, if the user wishes to save it by some other extension, he needs to type the same. Some applications require capturing the images and copying it to clipboard. To do this job, we need to first capture the frame where the image is being displayed and then copy it to clipboard. This two stage procedure can be summed up as: Private Sub cmdcopy_click() SendMessage mcaphwnd, 1084, 0, 0 'Capture frame from webcam DoEvents: SendMessage mcaphwnd, 1054, 0, 0 'Stop capturing of images from webcam

The programmer needs to take care that the co-ordinates of the frame are defined correctly. It should remain the same through-out the program and hence it is advisable to define these constants globally. Here 1084 is the code for getting the frame and 1054 for copying the image. The most important part which is refreshing the images captured by webcam so that it appears as if the stream is being captured continuously. This can be done by the use of timer tmrmain. Private Sub tmrmain_timer() On Error Resume Next cmdcopy_click piccapture.picture = Clipboard.GetData 'Paste captured frame from clipboard The algorithm for saving the file automatically can be implemented in this format. The interval of timer (in milliseconds) needs to be set when the form starts. Dim counter As Integer SavePicture piccapture.image, "c:\lbsystems\images\date" & Counter & ".jpg" Counter = Counter + 1 With this, one can easily capture any stream of data from webcam but when the form is unloaded or when the program is ended, the webcam is still in the process of connection. This should be terminated so that memory as well the processor is freed. Private Sub cmdexit_click() DoEvents: SendMessage mcaphwnd, 1035, 0, 0 'Stop webcam capturing Unload Me When an interrupted termination occurs, this program will again not be able to free the memory. So a piece of code needs to be written in Form_Unload Private Sub Form_Unload(Cancel As Integer) DoEvents: SendMessage mcaphwnd, 1035, 0, 0

'Stop webcam capturing With that, one module of capturing webcam is all set to be implemented in any project.