Acquire A Still Image from Video Stream

The LEADTOOLS WIA driver is available in LEADTOOLS version 16 or higher.

This tutorial is to provides you with a quick and easy way to generate a WIA program. For more in depth WIA programming, refer to the WIA demo.

Take the following steps to create and run a program that implement LEADTOOLS WIA features.

1.

Start Microsoft Visual Studio 2005

2.

Select the File->New menu option, click the "Project" menu.

3.

From "Project Types" select "Other Languages" to expand it, then select "Visual C++" to expand it, then select "MFC". From the right window select "MFC Application".

4.

In the Project Name dialog box, enter "WiaStillImageTutor".

5.

In the Location dialog box, use the "Examples\ClassLibrary\MSVC" directory of your LEAD installation. For example, if you installed LEADTOOLS in "C:\Program Files\LEAD Technologies\LEADTOOLS 17\", enter "C:\Program Files\LEAD Technologies\LEADTOOLS 17\ Examples\ClassLibrary\MSVC", then Click OK. Then click "Next".

6.

Choose "Dialog based" and click "Finish".

7.

Click on the "Solution Explorer" tab, and then click on the "WiaStillImageTutor" project to expand it. Click on the Header files, then Open "WiaStillImageTutor.h".

8.

Add the following line immediately before the class CWiaStillImageTutorApp declaration, (keep in mind, you may have to change the path to where the header files reside):

 

#include "..\..\..\..\include\ClassLib\ltwrappr.h"

9.

Click on the "Class View" tab.

10.

Click to open the "WiaStillImageTutor" classes branch.

11.

Click "CWiaStillImageTutorApp", and then double click the CWiaStillImageTutorApp(void) constructor.

12.

Add the following lines after //TODO: add construction code here:

LBase::LoadLibraries(LT_ALL_LEADLIB); 
LSettings::UnlockSupport(L_SUPPORT_DOCUMENT, L_KEY_DOCUMENT); 

13.

Create a new file called Imports.cpp in place it beside your project files.

 

a.

In the Project Workspace, click the Solution Explorer tab.

 

b.

Double-click the WiaStillImageTutor folder to open it.

 

c.

Right-click the Source files folder and select Add à New item.

 

d.

Expand Visual C++ tree, if it is not already expanded.

 

e.

Select Code from the sub tree.

 

f.

Select C++ File (.cpp) from the right window.

 

g.

In the name text box, specify Imports.cpp

 

h.

Click the Add button.

 

i.

Double-click the imports.cpp in the solution Explorer and add the following lines:

#include "StdAfx.h"

#if defined(WIN64) 
   #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\x64\\Ltwvc_x.lib")
#else
   #pragma comment(lib, "..\\..\\..\\..\\Lib\\CDLL\\Win32\\Ltwvc_u.lib")
#endif // #if defined(WIN64) 

14.

Click on the "Class View" tab.

15.

Double-click the "WiaStillImageTutor" folder to open it.

16.

Right click "CWiaStillImageTutorDlg" and select Add à "Add Variable..."

17.

For Variable Type enter LWia, and for Variable Declaration put m_MyWia. Leave Access as "Public" and click OK.

18.

Click to open the CWiaStillImageTutorDlg branch. Double click the OnInitDialog() function and add the following code after line:

 

// TODO: Add extra initialization here

m_MyWia.InitSession(WiaVersion1);

19.

Right click the CWiaStillImageTutorDlg branch, and choose "Properties".

20.

From the "Properties" window toolbar, click on the Messages icon. Then click on the empty area beside the item "WM_DESTROY" and choose OnDestroy.

21.

Add the following code after the opening bracket {:

 

m_MyWia.EndSession();
LBase::UnloadLibraries(LT_ALL_LEADLIB);

22.

Click on the "Solution Explorer" tab.

23.

Double-click the "WiaStillImageTutor" folder to open it.

24.

Double-click the "Resource Files" folder to open it. Then double click "WiaStillImageTutor.rc" file to open it, then double click "Dialog", and then double click "IDD_WIASTILLIMAGETUTOR_DIALOG"

25.

Now, drag and drop 4 buttons and 1 custom control (to render the video preview in it), and change their properties as follows:

 

 

ID

Caption

 

Button1

IDC_SELECT_VIDEO_SRC

Select Video Source

 

Button2

IDC_START_VIDEO_PREVIEW

Start Video Preview

 

Button3

IDC_ACQUIRE_STILL_IMAGE

Acquire Still Image

 

Button4

IDC_STOP_VIDEO_PREVIEW

Stop Video Preview

 

CustomControl1

IDC_PREVIEW_CONTROL

 

26.

From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_WIASTILLIMAGETUTOR_DIALOG"

27.

Double click on "Select Video Source" button, and add the following code:

 

m_MyWia.SelectDeviceDlg(WiaDeviceTypeStreamingVideo, L_WIA_SELECT_DEVICE_NODEFAULT);

28

From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_WIASTILLIMAGETUTOR_DIALOG".

29.

Double click on "Start Video Preview" button, and add the following code:

 

m_MyWia.SetWindow(GetDlgItem(IDC_PREVIEW_CONTROL)->m_hWnd);
m_MyWia.StartVideoPreview(FALSE);

30.

From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_WIASTILLIMAGETUTOR_DIALOG".

31.

Double click on "Acquire Still Image " button, and add the following code:

 

L_TCHAR szTakenImageFileName[MAX_PATH] = TEXT("");
L_SIZE_T uLength = MAX_PATH;
L_INT nRet = WIA_SUCCESS;

if(m_MyWia.IsVideoPreviewAvailable())
   {
      nRet = m_MyWia.AcquireImageFromVideo(szTakenImageFileName, &uLength);
      if(nRet == WIA_SUCCESS)
      {
            MessageBox(szTakenImageFileName, TEXT("Saved file path..."), MB_OK);
      }
}

32.

From View menu, select "Other Windows" menu, then select "Resource View" menu, then select Dialog, and select "IDD_WIASTILLIMAGETUTOR_DIALOG".

33.

Double click on "Stop Video Preview" button, and add the following code:

 

if(m_MyWia.IsVideoPreviewAvailable())
   {
      m_MyWia.EndVideoPreview();
    }

34.

Compile and test the program.