Luxand FaceSDK – Working with Cameras

The library offers a set of functions to work with DirectShow/v4l2-compatible web cameras and IP cameras with an MJPEG interface. The functions allow single frames to be retrieved from a camera one-by-one; they are stored in HImage descriptors. The application usually grabs frames in a loop, displaying each frame in its window and performing manipulations with images (such as face detection).

Web camera functions are available only for Windows and Linux platforms. IP camera functions are available for all platforms.

Android and iOS samples include platform-specific code working with cameras on phones and tablets.

    Data Types

There are data types to store the information about video formats. Note that the names of video cameras are stored in wide char format (each char occupies two bytes).

C++ Declaration:

typedef struct {
    int Width;
    int Height;
    int BPP;
} FSDK_VideoFormatInfo;

typedef enum {
    FSDK_MJPEG
} FSDK_VIDEOCOMPRESSIONTYPE;

Delphi Declaration:

FSDK_VideoFormatInfo = record
   Width: integer;
   Height: integer;
   BPP: integer;
end;

PFSDK_VideoFormatInfo = ^FSDK_VideoFormatInfo;
FSDK_VideoFormatInfoArray = array[0..255] of FSDK_VideoFormatInfo;
PFSDK_VideoFormatInfoArray = ^FSDK_VideoFormatInfoArray;
FSDK_CameraList = array[0..255] of PWideChar;
PFSDK_CameraList = ^FSDK_CameraList;
FSDK_VIDEOCOMPRESSIONTYPE = ( FSDK_MJPEG );

VB Declaration:

Type FSDK_VideoFormatInfo
   Width As Long
   Height As Long
   BPP As Long
End Type

Enum FSDK_VIDEOCOMPRESSIONTYPE
   FSDK_MJPEG
End Enum

Java Declaration:

The class FSDK_VideoFormatInfo has the following properties:

   public int Width, Height, BPP;

class FSDK_VideoFormats {
   public FSDK_VideoFormatInfo.ByValue formats[];
}

class TCameras {
   public String cameras[];
}

Java and Android Declaration:

class HCamera {
   protected int hcamera;
}

class FSDK_VIDEOCOMPRESSIONTYPE {
   public static final int FSDK_MJPEG = 0;
}

Python Declaration:

class Camera(ctypes.Structure):
    fields_ = ("handle", c_int), # FSDK camera handle
    def __init__(self, cameraName=None): # cameraName is for windows only
    def Open(self, cameraName);
    def Close(self)
    def GrabFrame(self)

# for windows and linux only
class VideoFormatInfo(ctypes.Structure):
    fields = ("Width", c_int), ("Height", c_int), ("FormatIndex", c_int)

  FSDK_InitializeCapturing Function

This function initializes the capturing process (but does not open a camera). This function should be called in a certain thread that works with cameras. Note that on Windows platforms this function initializes COM in the thread; if you already initialized COM, you must not call this function, and you must not call FSDK_FinalizeCapturing.

C++ Syntax:

int FSDK_InitializeCapturing(void);

Delphi Syntax:

function FSDK_InitializeCapturing: integer;

C# Syntax:

int FSDKCam.InitializeCapturing();

VB Syntax:

Function FSDKVB_InitializeCapturing() As Long

Java Syntax:

int FSDKCam.InitializeCapturing();

Android Syntax:

int FSDK.InitializeCapturing();

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.InitializeCapturing();

Return Value:

None

  FSDK_FinalizeCapturing Function

This function finalizes the capturing process, initialized by the FSDK_InitializeCapturing function (and finalizes COM on Windows platforms). If you already finalized COM, you must not call this function.

C++ Syntax:

int FSDK_FinalizeCapturing(void);

Delphi Syntax:

function FSDK_FinalizeCapturing: integer;

C# Syntax:

int FSDKCam.FinalizeCapturing();

VB Syntax:

Function FSDKVB_FinalizeCapturing() As Long

Java Syntax:

int FSDKCam.FinalizeCapturing();

Android Syntax:

int FSDK.FinalizeCapturing();

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.FinalizeCapturing();

Return Value:

None.

  FSDK_SetCameraNaming Function

Sets the retrieval format for the FSDK_GetCameraList function. Depending on the value of the argument, either web camera names (by default) or their unique IDs (Device Path) are returned. Device Path may be necessary if the system has several web cameras from the same manufacturer that have the same name. This function does not support IP cameras.

C++ Syntax:

int FSDK_SetCameraNaming(bool UseDevicePathAsName);

Delphi Syntax:

function FSDK_SetCameraNaming(UseDevicePathAsName: boolean): integer;

C# Syntax:

int FSDKCam.SetCameraNaming(bool UseDevicePathAsName)

VB Syntax:

Function FSDKVB_SetCameraNaming(ByVal UseDevicePathAsName As Boolean) As Long

Java Syntax:

int FSDKCam.SetCameraNaming (boolean UseDevicePathAsName);

Parameters:

UseDevicePathAsName – sets a retrieval format for the FSDK_GetCameraList function.

FALSE: FSDK_GetCameraList returns the list of names for cameras installed in the system;

TRUE: FSDK_GetCameraList returns the list of unique device paths of these cameras.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.SetCameraNaming(useDevicePathAsName: bool):

Return Value:

None.

  FSDK_GetCameraList Function

This function retrieves the list of web cameras available in the system. The name of each camera is stored in wide char format (each character occupies two bytes). The function does not support IP cameras. The camera list must be destroyed by calling the FSDK_FreeCameraList function after the list is no longer needed.

C++ Syntax:

int FSDK_GetCameraList(wchar_t*** CameraList, int* CameraCount);

Delphi Syntax:

function FSDK_GetCameraList(CameraList: PWideChar; CameraCount: Pinteger): integer;

C# Syntax:

int FSDKCam.GetCameraList(out string[] CameraList, out int CameraCount)

VB Syntax:

Function FSDKVB_GetCameraList(ByRef CameraList As Variant, ByRef CameraCount As Long) As Long

Java Syntax:

int FSDKCam.GetCameraList(TCameras CameraList, int CameraCount[]);

Parameters:

CameraList – pointer to wchar_t** variable to store the camera list.

CameraCount – pointer to integer variable to store the count of cameras in the system.

Return Value:

Returns FSDKE_OK if successful.

Example

wchar_t** CameraList;
int CameraCount;

FSDK_InitializeCapturing();
if (FSDK_GetCameraList(&CameraList, &CameraCount)!=FSDKE_OK)
    for (int i=0; i<CameraCount; i++)
        wprintf(L"camera: %s\n", CameraList[i]);
printf("%d camera(s) found.\n", CameraCount);
FSDK_FinalizeCapturing();

Python Syntax:

class CameraName(str);

def FSDK.ListCameraNames() -> List[CameraName];

Return Value:

The list of CameraName objects.

Note:

The CameraName class is a string with an extra field devicePath.

  FSDK_GetCameraListEx Function

This function retrieves the list of names and the device paths of the web cameras available in the system. The name and the device path of each camera are stored in wide char format (each character occupies two bytes) at the same indices at the corresponding arrays. The function does not support IP cameras. Both lists must be destroyed by calling the FSDK_FreeCameraList function after they are no longer needed.

C++ Syntax:

int FSDK_GetCameraListEx(wchar_t*** CameraNameList, wchar_t*** CameraDevicePathList, int* CameraCount);

Delphi Syntax:

function FSDK_GetCameraListEx(CameraNameList: PWideChar; CameraDevicePathList: PWideChar; CameraCount: PInteger): integer;

C# Syntax:

int FSDKCam.GetCameraList(out string[] CameraNameList, out string[] CameraDevicePathList, out int CameraCount)

VB Syntax:

Function FSDKVB_GetCameraListEx(ByRef VCameraNameList As Variant, ByRef VCameraDevicePathList As Variant, ByRef CameraCount As Long) As Long

Java Syntax:

int FSDKCam.GetCameraListEx(TCameras CameraNameList, TCameras CameraDevicePathList, int CameraCount[]);

Parameters:

CameraNameList – pointer to wchar_t** variable to store the camera name list.

CameraDevicePathList – pointer to wchar_t** variable to store the camera device path list.

CameraCount – pointer to integer variable to store the count of cameras in the system.

Return Value:

Returns FSDKE_OK if successful.

  FSDK_FreeCameraList Function

This function frees the list of web cameras obtained from the FSDK_GetCameraList or FSDK_GetCameraListEx function. The call of the function is not required in .NET, VB and Java.

C++ Syntax:

int FSDK_FreeCameraList(wchar_t*** CameraList, int CameraCount);

Delphi Syntax:

function FSDK_FreeCameraList(CameraList: Pointer; CameraCount: integer): integer;

Parameters:

CameraList – pointer to wchar_t** variable where the camera list is stored.

CameraCount – the count of cameras in the system, obtained from the FSDK_GetCameraList or FSDK_GetCameraListEx function.

Note:

You must call FSDK_FreeCameraList for CameraNameList and CameraDevicePathList, if you were using FSDK_GetCameraListEx.

Return Value:

Returns FSDKE_OK if successful.

  FSDK_GetVideoFormatList Function

This function returns the list of video formats supported by a given camera. This function does not support IP cameras.

C++ Syntax:

int FSDK_GetVideoFormatList(wchar_t* CameraName, FSDK_VideoFormatInfo** VideoFormatList, int* VideoFormatCount);

Delphi Syntax:

function FSDK_GetVideoFormatList(CameraName: PWideChar; VideoFormatList: PFSDK_VideoFormatInfo; VideoFormatCount: Pinteger): integer;

C# Syntax:

int FSDKCam.GetVideoFormatList(string CameraName, out FSDKcam.VideoFormatInfo[] VideoFormatList, out int VideoFormatCount)

VB Syntax:

Function FSDKVB_GetVideoFormatList(ByVal CameraName As String, ByRef VideoFormatList As Variant, ByRef VideoFormatCount As Long) As Long

Java Syntax:

int FSDKCam.GetVideoFormatList(String CameraName, FSDK_VideoFormats VideoFormatList, int VideoFormatCount[]);

Parameters:

CameraName – pointer to name of desired video camera.

VideoFormatList – pointer to FSDK_VideoFormatInfo* variable to store the list of video formats.

VideoFormatCount – pointer to integer variable to store the count of video formats.

Return Value:

Returns FSDKE_OK if successful.

  FSDK_FreeVideoFormatList Function

This function frees the list of video formats obtained from FSDK_GetVideoFormatList. Calling this function is not required in .NET, VB and Java.

C++ Syntax:

int FSDK_FreeVideoFormatList(FSDK_VideoFormatInfo * VideoFormatList);

Delphi Syntax:

function FSDK_FreeVideoFormatList(VideoFormatList: Pointer): integer;

Parameters:

VideoFormatList – pointer to FSDK_VideoFormatInfo* variable where the list of video formats is stored.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.ListVideoFormats(cameraName: str) -> List[VideoFormatInfo];

Return Value:

The list of VideoFormatInfo objects.

  FSDK_SetVideoFormat Function

The function sets the format of camera output. The function does not support IP cameras.

C++ Syntax:

int FSDK_SetVideoFormat(wchar_t* CameraName, FSDK_VideoFormatInfo VideoFormat);

Delphi Syntax:

function FSDK_SetVideoFormat(CameraName: PWideChar; VideoFormat: FSDK_VideoFormatInfo): integer;

C# Syntax:

int FSDKCam.SetVideoFormat(ref string CameraName, FSDKcam.VideoFormatInfo VideoFormat);

VB Syntax:

Function FSDKVB_SetVideoFormat(ByVal CameraName As String, ByRef VideoFormat As FSDK_VideoFormatInfo) As Long

Java Syntax:

int FSDKCam.SetVideoFormat(String CameraName, FSDK_VideoFormatInfo.ByValue VideoFormat);

Parameters:

CameraName – pointer to name of desired video camera.

VideoFormat – desired video format.

Return Value:

Returns FSDKE_OK if successful.

Example

wchar_t** CameraList;
int CameraCount;
FSDK_VideoFormatInfo* VideoFormatList;
int VideoFormatCount;

FSDK_GetCameraList(&CameraList, &CameraCount);

FSDK_GetVideoFormatList(CameraList[0], &VideoFormatList, &VideoFormatCount);
FSDK_SetVideoFormat(CameraList[0], VideoFormatList[0]);

Python Syntax:

def FSDK.SetVideoFormat(cameraName: str, videoFormat: VideoFormatInfo);

Return Value:

None.

  FSDK_OpenVideoCamera Function

The function opens the web camera of a given name and returns its handle.

C++ Syntax:

int FSDK_OpenVideoCamera(wchar_t* CameraName, int* CameraHandle);

Delphi Syntax:

function FSDK_OpenVideoCamera(CameraName: PWideChar; CameraHandle: Pinteger): integer;

C# Syntax:

int FSDKCam.OpenVideoCamera(ref string CameraName, ref int CameraHandle);

VB Syntax:

Function FSDKVB_OpenVideoCamera(ByVal CameraName As String, ByRef CameraHandle As Long) As Long

Java Syntax:

int FSDKCam.OpenVideoCamera (String CameraName, HCamera CameraHandle);

Parameters:

CameraName – pointer to name of video camera to open.

CameraHandle – pointer to integer variable to store the opened camera handle.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.OpenVideoCamera(cameraName: str) -> Camera;

Return Value:

New Camera object.

  FSDK_OpenIPVideoCamera Function

This function opens the IP camera at a given URL and returns its handle. You may call the FSDK_SetHTTPProxy function to set an HTTP proxy for accessing the camera.

C++ Syntax:

int FSDK_OpenIPVideoCamera(FSDK_VIDEOCOMPRESSIONTYPE CompressionType, char * URL, char * Username, char * Password, int TimeoutSeconds, int * CameraHandle);

Delphi Syntax:

function FSDK_OpenIPVideoCamera(CompressionType: FSDK_VIDEOCOMPRESSIONTYPE; URL: PAnsiChar; Username: PAnsiChar; Password: PAnsiChar; TimeoutSeconds: integer; CameraHandle: PInteger): integer;

C# Syntax:

int FSDKCam.OpenIPVideoCamera(FSDK_VIDEOCOMPRESSIONTYPE CompressionType, string URL, string Username, string Password, int TimeoutSeconds, ref int CameraHandle);

VB Syntax:

Function FSDKVB_OpenIPVideoCamera(ByVal CompressionType As FSDK_VIDEOCOMPRESSIONTYPE, ByVal URL As String, ByVal Username As String, ByVal Password As String, ByVal TimeoutSeconds As Long, ByRef cameraHandle As Long) As Long

Java Syntax:

int FSDKCam.OpenIPVideoCamera(int CompressionType, String URL, String Username, String Password, int TimeoutSeconds, HCamera CameraHandle);

Android Syntax:

int FSDK.OpenIPVideoCamera(FSDK_VIDEOCOMPRESSIONTYPE CompressionType, String URL, String Username, String Password, int TimeoutSeconds, HCamera CameraHandle);

Parameters:

CompressionType – the type of video stream (MJPEG by default).

URL – URL of the IP camera to be opened.

Username – IP camera access username.

Password – IP camera access password.

TimeoutSeconds – connection timeout in seconds.

CameraHandle – pointer to integer variable to store the opened camera handle.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.OpenIPVideoCamera(compression: int, URL: str, userName: str, password: str, timeoutSeconds: int) -> Camera;

Return Value:

New Camera object.

  FSDK_SetHTTPProxy Function

This function sets an HTTP proxy to be used with an IP camera. If a proxy is required, the function should be called before the FSDK_OpenIPVideoCamera function.

C++ Syntax:

int FSDK_SetHTTPProxy(char* ServerNameOrIPAddress, unsigned short Port, char* UserName, char* Password);

Delphi Syntax:

function FSDK_OpenIPVideoCamerafunction FSDK_SetHTTPProxy(ServerNameOrIPAddress: PAnsiChar; Port: Word; Username: PAnsiChar; Password: PAnsiChar): integer;

C# Syntax:

int FSDK.SetHTTPProxy(string ServerNameOrIPAddress, UInt16 Port, string UserName, string Password);

VB Syntax:

Function FSDKVB_ SetHTTPProxy(ByVal ServerNameOrIPAddress As String, ByVal Port As Long, ByVal Username As String, ByVal Password As String) As Long

Java Syntax:

int FSDKCam.SetHTTPProxy(String ServerNameOrIPAddress, int Port, String UserName, String Password);

Android Syntax:

int FSDK.SetHTTPProxy(String ServerNameOrIPAddress, int Port, String UserName, String Password);

Parameters:

ServerNameOrIPAddress – proxy address.

Port – proxy port.

UserName – proxy username.

Password – proxy password.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.SetHTTPProxy(serverNameOrIPAddress: str, port: int, userName: str, password: str);

Return Value:

None.

  FSDK_GrabFrame Function

Retrieves the current frame from a web camera or an IP camera and stores the frame in the created HImage handle. If a camera returns an image, mirrored horizontally (it depends on the camera settings), then you can mirror it by using FSDK_MirrorImage.

C++ Syntax:

int FSDK_GrabFrame(int CameraHandle, HImage* Image);

Delphi Syntax:

function FSDK_GrabFrame(CameraHandle: integer; var Image: PHImage): integer;

C# Syntax:

int FSDKCam.GrabFrame(int CameraHandle, ref int Image);

VB Syntax:

Function FSDKVB_GrabFrame(ByVal CameraHandle As Long, ByRef Image As Long) As Long

Java Syntax:

int FSDKCam.GrabFrame(HCamera CameraHandle, HImage Image);

Android Syntax:

int FSDK.GrabFrame(HCamera CameraHandle, HImage Image);

Parameters:

CameraHandle – handle of the opened camera to grab frame.

Image – pointer to HImage variable to store the frame. Note that the created HImage handle should be deleted once it is no longer needed using the FSDK_FreeImage function.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.GrabFrame(camera: Camera) -> Image;

def Camera.GrabFrame() -> Image;

Return Value:

A new image with grabbed frame.

  FSDK_CloseVideoCamera Function

The function closes the camera, opened by the FSDK_OpenVideoCamera or FSDK_OpenIPVideoCamera function.

C++ Syntax:

int FSDK_CloseVideoCamera(int CameraHandle);

Delphi Syntax:

function FSDK_CloseVideoCamera(CameraHandle: integer): integer;

C# Syntax:

int FSDKcam.CloseVideoCamera(int CameraHandle);

VB Syntax:

Function FSDKVB_CloseVideoCamera(ByVal CameraHandle As Long) As Long

Java Syntax:

int FSDKCam.CloseVideoCamera(HCamera CameraHandle);

Parameters:

CameraHandle – handle of opened video camera to close.

Return Value:

Returns FSDKE_OK if successful.

Python Syntax:

def FSDK.CloseVideoCamera(camera: Camera);

def Camera.Close();

Return Value:

None.

Note:

The camera is closed automatically by calling the destructor of Camera object.

 

Next chapterTracker API: Face Recognition and Tracking in Video Streams

Contents

Get in touch

Luxand, Inc.
815 N. Royal St. Suite 202
Alexandria, VA
22314
USA
Freephone:
+1 800 471 5636

Join our newsletter

And always stay informed of the latest company news and events!

Sign up >>

DMCA.com Protection Status