Example Code

Controlling a webcam thanks sdk (without Ni_Vision package)

Code and Documents

Attachment

Download All

Overview

Capturing images from a usb webcam without using Ni_Vision package (Ni_Imaq, Ni_ImaqDx, Ni_Imaq I/O). The code is based on Windows SDK functions.

Description

The file 'lrvcam.c' (written in C under LabWindows cvi) enables the capture of images coming from a webcam connected to an usb port. It is provided as an example. Here the program records images with a predefined periodicity such enabling to survey a process (chemical for instance).

Improvement of the code (may 16th 2014): In order to avoid recording redundant images, a threshold (between 0 and 100) is used to decide whether two images are different or not. The threshold can be adjusted by the user according to the lightness and the kinetics of what he observes.

A typical ini file 'lrvcam.ini' and the user interface 'lrvcam.uir' are provided as well.

Documentation

You can refer to:

for further information.

Steps to Implement and Execute Code

Static Functions

  • GetIsoDate()  provides time as an integer in the form HHMMSS used in the image file names.
  • ReadIni() and WriteIni() manage the ini file. You must implement these functions (I used my own fp for that - see https://decibel.ni.com/content/docs/DOC-36797).
  • BitmapDiff() evalutates the difference beween two bitmaps.
  • MakeImage() records a cam frame (bmp format).
  • CheckCreateFile() checks if it is possible to write files in the directory you choose.
  • AvailableDevices() scans the list of cams connected to your computer.
  • CloseCamera() ends a capture session.
  • OpenCamera() starts a capture session with the chosen camera.
  • main() acts as usual.

Callbacks

  • QuitCallback() ends the program.
  • DeviceCallback() choses the camera among the connected devices.
  • RecordCallback() starts/stops the recording of the image sequence.
  • SnashotCallback() records an image file now.
  • RecordTimerCallback() callback of the timer which periodically records images.
  • BlinkTimerCallback() blinks the 'record' LED.
  • DirectoryCallback() enables you to choose de destination directory.
  • BasenameCallback() enables you to define the base name od the files. Files name structure is "BASENAME_FRAMENUMBER_ISOTIME.bmp"
  • PopupParamCallback() displays the sdk video parameter menu.
  • PopupSizeCallback() displays the sdk dimension image menu.

Controls

lrvcam.png

  • Choose your device with the ring [DEVRING] --> the capture popup must appear.
  • Select the periodicity.
  • Select a threshold (so that identical images are not recorded)
  • Select both the destination directory and the basename.
  • Launch or stop  the recording with the button [RECORDBUTTON]

NOTE : if the device list remains void, check if the cam driver is properly installed.

Requirements

Software

     LabWindows CVI + Windows SDK + Drivers of usb webcam(s).

     Do not forget to link to vfw32 and gdi32 sdk libraries (in C:\program files\national instruments\cviXX\sdk\lib\msvc, for instance).

Hardware

     usb webcam(s) connected to usb port(s).

Additional Images or Video

lrvcam2.pnglrvcam3.png


Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
AlePan
Member
Member
on

Hi, where is the .h file?

Additionally. What the tagfile.h is and where can I find it?

tuliodapper
Member
Member
on
AlePan
Member
Member
on

Hi,

still lrvcam.h is missing. Can you provide it?

AlePan
Member
Member
on

not working on windows 8, CVI2013, do you know why?

erickringot
Member
Member
on


erickringot
Member
Member
on

AlePan,

I have'nt try lrvcam under Windows8.

Suggestion: check for the usbcam driver and the sdk version.

Cheking that and coming back asap

erickringot
Member
Member
on

AlePan,

The code has been updated (May 18th, 2015).

ottelo
Member
Member
on

How can I put the preview video into a canvas or any other cvi gui objects? I dont want to have a popup preview window and I want to draw something over the preview. Is there any solution for it?

erickringot
Member
Member
on

I did'nt perform what you plan to do but I suggest you study the following cvi functions :

- RegisterWinMsgCallback

- GetCVIWindowHandle

you should also write a callback to copy the images coming from the camera to your own canvas.

ottelo
Member
Member
on

Thanks, I got help from the community:

Get the handle from the mainpanel and put it into the CreateCaptureWindow function!!!

HANDLE handle;

GetPanelAttribute (panelHandle, ATTR_SYSTEM_WINDOW_HANDLE, &handle);

http://forums.ni.com/t5/LabWindows-CVI/vfw32-video-for-windows-put-capture-window-into-a-panel/m-p/3...

Hungshin
Member
Member
on

What is tagfile.h and where can I find it?
I cannot find it on the NI site because I do not have permission.

Contributors