1.6.5660.20150520
ToupCam cameras (model series: UCMOS, WCMOS, LCMOS, U3CMOS, L3CMOS, E3CMOS, ICMOS, GCMOS, UHCCD, EXCCD, SCCCD) support various kinds of APIs (Application Program Interface), namely Native C/C++, .NET/C#/VB.NET, DirectShow, Twain, LabView and so on. Compared with other APIs, Native C/C++ API, as a low level API, don't depend any other runtime libraries. Besides, this interface is simple, flexible and easy to be integrated into the customized applications. The SDK zip file contains all of the necessary resources and information:
toupcam.h, C/C++ head file
toupcam.cs, for C#. The toupcam.cs use P/Invoke to call into toupcam.dll. Please copy toupcam.cs to your C# project to use it.
toupcam.vb, for VB.NET. The toupcam.vb use P/Invoke to call into toupcam.dll. Please copy toupcam.vb to your VB.NET project to use it.
toupcam.lib, lib file for x86.
toupcam.dll, dll file for x86.
toupcamdemocpp.exe, x86 C++ demo exe file.
toupcam.lib, lib file for x64.
toupcam.dll, dll file for x64.
toupcamdemocpp.exe, x64 C++ demo exe file.
x86 folder contains the kernel mode drivers for x86, including toupcam.cat, toupcam.inf and toupcam.sys.
x64 folder contains the kennel mode driver for x64, including toupcam.cat, toupcam.inf and toupcam.sys.
a). toupcamdemocpp, C++ sample. It demonstrates to enumerate device, open device, video preview, image capture, set the preview resolution, multi-format image saving (.bmp, .jpg, .png, etc), wmv format video recording and so on. This sample use Pull Mode. To keep the code clean, this sample uses the WTL library which can be downloaded from http://sourceforge.net/projects/wtl
b). toupcamdemomfc, a simple C++ sample. It use MFC as the GUI library. It demonstrates to open device, video preview, image capture, set the preview resolution, multi-format image saving (.bmp, .jpg, .png, etc). This sample use Pull Mode.
c). toupcamdemowinformcs1, C# winform sample. This sample use Pull Mode, StartPullModeWithWndMsg.
d). toupcamdemowinformcs2, C# winform sample. This sample use Pull Mode, StartPullModeWithCallback.
e). toupcamdemowinformvb, VB.NET winform sample. This sample use Pull Mode.
a). directshow: DirectShow SDK and demo.
b). twain: TWAIN SDK and demo.
c). labview: Labview SDK and demo.
Toupcam offers two modes to obtain image data: Pull Mode and Push Mode. The former is recommended since it's simpler and the application seldom gets stuck in multithreading conditions, especially when using windows message to notify the events.
There are to ways to notify applications:
a) Use Windows message: Start pull mode by using the function Toupcam_StartPullModeWithWndMsg. When event occurs, toupcam will post message (PostMessage) to the specified window. Parameter WPARAM is the event type, refer to the definition of TOUPCAM_EVENT_xxxx. This model avoids the multithreading issues, so it's the most simple way. (Obviously, this is only supported in Windows systems, and not supported in Linux and MacOSX.)
b) Use Callback function: Start pull mode by using the function Toupcam_StartPullModeWithCallback. When event occurs, toupcam will callback the function PTOUPCAM_EVENT_CALLBACK.
In Pull Mode, the SDK could not only notify the application that the image data or still image are available for 'PULL', but also inform you of the other events, such as:
TOUPCAM_EVENT_EXPOSURE exposure time changes TOUPCAM_EVENT_TEMPTINT white balance parameters changes. Temp/Tint Mode, please see here. TOUPCAM_EVENT_TEMPTINT white balance parameters changes. RGB Gain Mode, please see here. TOUPCAM_EVENT_IMAGE Video image data arrives. Use Toupcam_PullImage to 'pull' the image data TOUPCAM_EVENT_STILLIMAGE Still image which is triggered by function Toupcam_Snap arrives. Use Toupcam_PullStillImage to 'pull' the image data TOUPCAM_EVENT_ERROR Error occurs, data acquisition cannot continue TOUPCAM_EVENT_DISCONNECTED Camera disconnected, maybe has been pulled out
Most cameras support the so-called still capture capability. This function switches the camera to another resolution temporarily when the camera is in preview mode, after a "still" image in the new resolution is captured and then switch back to the original resolution and resume preview mode.
For example, UCMOS05100KPA support 3 resolutions and the current one in preview mode is 1280 * 960. Call Toupcam_Snap(h, 0) to "still capture" an image in 2592 * 1944 resolution. To realize this function, the camera will temporarily switch to 2592 * 1944 firstly, get an image in 2592 * 1944 resolution and then switch back to 1280 * 960 and resume preview.
a) In pull mode operation, after the still capture, TOUPCAM_EVENT_STILLIMAGE will be sent out for external acknowledgement. The external application should call Toupcam_PullStillImage to get the still captured image.
b) In push mode operation, after the still capture, the callback function PTOUPCAM_DATA_CALLBACK will be called with bSnap parameter setting TRUE. The image information including the resolution information will be obtained via the parameter pHeader.
To check whether the camera have the still capture capability, call Toupcam_get_StillResolutionNumber function or check the still field of the struct ToupcamModel.
Toupcam supports two data formats: RGB format (default) and RAW format. RAW format could be enabled by assigning TOUPCAM_OPTION_RAW parameter to 1 when calling Toupcam_put_Option function.
Users could switch these two format by calling Toupcam_put_Option function with different value setting to TOUPCAM_OPTION_RAW. You must call this function BEFORE the camera start function (Toupcam_StartPullModeWithWndMsg or Toupcam_StartPullModeWithCallback or Toupcam_StartPushMode).
1. Toupcam sdk supports two independent modes for white balance: a) Temp/Tint Mode; b) RGB Gain Mode
a) Temp/Tint mode is the default white balance mode. In this mode, temp and tint are the parameters that could be used to control the white balance. Toupcam_get_TempTint function is used to acquire the temp and tint values and Toupcam_put_TempTint is used to set the temp and tint values. Function Toupcam_AwbOnePush is used to execute the auto white balance. When the white balance parameters change, TOUPCAM_EVENT_TEMPTINT event will be notified for external use.
b) In RGB Gain mode, the while balace is controled by the gain values of the R,G,B channels. Toupcam_get_WhiteBalanceGain is used to acquire the parameters and Toupcam_put_WhiteBalanceGain is used to set the white balance parameters. Toupcam_AwbInit is used to execute the execute the auto white balance. When the white balance parameters change, TOUPCAM_EVENT_WBGAIN event will be notified for external use.
The functions for these two modes cannot be misused:
a) In Temp/Tint mode, please use Toupcam_get_TempTint and Toupcam_put_TempTint and Toupcam_AwbOnePush. Toupcam_get_WhiteBalanceGain and Toupcam_put_WhiteBalanceGain and Toupcam_AwbInit cannot be used, they always return E_NOTIMPL.
b) In RGB Gain mode, please use Toupcam_get_WhiteBalanceGain and Toupcam_put_WhiteBalanceGain and Toupcam_AwbInit. Toupcam_get_TempTint and Toupcam_put_TempTint and Toupcam_AwbOnePush cannot be used, they always return E_NOTIMPL
When calling Toupcam_Open function, whether to add a '@' character at the beginning of the id parameter will determine the white balance mode. Add a '@' character at the beginning of the id parameter means the RGB gain mode. If you want to use the RGB Gain mode, for example, if the id parameter is "abcdef", please call the Toupcam_Open function with the id parameter "@abcdef".
2. There are two auto white balance mechanisms available in this field: one is continuous auto white balance and the other is a "one push" auto white balance. The white balance parameters will be always calculated and updated for the continuous auto white balance mechanism. For "one push" auto white balance mechanism, the white balance parameters will be calculated and updated only when triggered. Toupcam cameras support "one push" auto white balance mechanism since it is more accurate and propriate for the microscope application, especially when the background is in pure color. Continuous white balance mechanism will encounter some problem in some cases.
3. Monochromatic camera does not support white balance. The functions metioned above always return E_NOTIMPL.
HRESULT is not uncommon on the Windows platform. It's borrowed to OSX and Linux, see the table:
Name | Description | Value |
S_OK | Operation successful | 0x00000000 |
S_FALSE | Operation successful | 0x00000001 |
E_FAIL | Unspecified failure | 0x80004005 |
E_INVALIDARG | One or more arguments are not valid | 0x80070057 |
E_NOTIMPL | Not supported or not implemented | 0x80004001 |
E_POINTER | Pointer that is not valid | 0x80004003 |
E_UNEXPECTED | Unexpected failure | 0x8000FFFF |
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0) #define FAILED(hr) (((HRESULT)(hr)) < 0) |
Return value: non-negative integer, enumerated camera number
Parameters:
ToupcamInst pti[TOUPCAM_MAX]: ToupcamInst buffer
Remarks: call this function to enumerate ToupCam cameras that are currently connected to computer and when it is returned, ToupcamInst buffer contains the information of each camera instance enumerated.If we don't care about that multiple cameras connect to the computer simultaneously, it's optional to call this function to enumerate the camera instances.
The code snippet shows as below:
ToupcamInst arr[TOUPCAM_MAX]; unsigned cnt = Toupcam_Enum(arr); for (unsigned i = 0; i < cnt; ++i) ...... |
typedef struct{ #ifdef _WIN32 const wchar_t* name; /* model name */ #else const char* name; #endif unsigned flag; /* TOUPCAM_FLAG_xxx */ unsigned maxspeed; /* maximum speed level, Toupcam_get_MaxSpeed, the speed range = [0, maxspeed], closed interval */ unsigned preview; /* number of preview resolution, Toupcam_get_ResolutionNumber */ unsigned still; /* number of still resolution, Toupcam_get_StillResolutionNumber */ ToupcamResolution res[TOUPCAM_MAX]; }ToupcamModel; |
name | The name of this model | |
flag | Bitwise flag | |
TOUPCAM_FLAG_CMOS | cmos sensor | |
TOUPCAM_FLAG_CCD_PROGRESSIVE | progressive ccd sensor | |
TOUPCAM_FLAG_CCD_INTERLACED | interlaced ccd sensor | |
TOUPCAM_FLAG_ROI_HARDWARE | support hardware ROI. Hardware ROI means only the ROI part of image is output from the sensor and the software cropping operation is not required. Higher frame rate is achieved when using hardware ROI method. Software ROI means the image with the complete field of view of the sensor will be output and software cropping operation is required to obtain the ROI image. | |
TOUPCAM_FLAG_MONO | monochromatic sensor | |
TOUPCAM_FLAG_BINSKIP_SUPPORTED | support bin/skip mode, see Toupcam_put_Mode and Toupcam_get_Mode | |
TOUPCAM_FLAG_USB30 | USB 3.0 | |
TOUPCAM_FLAG_COOLED | Cooled | |
TOUPCAM_FLAG_USB30_OVER_USB20 | usb3.0 camera connected to usb2.0 port | |
TOUPCAM_FLAG_ST4 | ST4 port | |
TOUPCAM_FLAG_GETTEMPERATURE | support to get the temperature of sensor, Toupcam_get_Temperature | |
TOUPCAM_FLAG_PUTTEMPERATURE | support to put the temperature of sensor, Toupcam_put_Temperature | |
TOUPCAM_FLAG_BITDEPTH10 | Maximum Bit Depth = 10 bits | |
TOUPCAM_FLAG_BITDEPTH12 | Maximum Bit Depth = 12 bits | |
TOUPCAM_FLAG_BITDEPTH14 | Maximum Bit Depth = 14 bits | |
TOUPCAM_FLAG_BITDEPTH16 | Maximum Bit Depth = 16 bits | |
TOUPCAM_FLAG_FAN | cooling fan | |
TOUPCAM_FLAG_COOLERONOFF | cooler can be turn on or off | |
TOUPCAM_FLAG_ISP | image signal processing supported | |
TOUPCAM_FLAG_TRIGGER | support the trigger mode | |
maxspeed | Maximum speed level, same with Toupcam_get_MaxSpeed. The speed range is [0, maxspeed]. see Toupcam_put_Speed and Toupcam_get_Speed | |
preview | Number of preview resolution. Same with Toupcam_get_ResolutionNumber | |
still | Number of still resolution, zero means still capture is not supported. Same with Toupcam_get_StillResolutionNumber | |
res | Resolution, width and height |
Return value: NA
Parameters:
PTOUPCAM_HOTPLUG pHotPlugCallback: callback function
typedef void (*PTOUPCAM_HOTPLUG)(void* pCallbackCtx);void* pCallbackCtx: callback context
Remarks:
This function is only available on OSX and Linux, it's unnecessary on Windows.
To process the device plug in / pull out in Windows, please refer to the MSDN(Device Management, Detecting Media Insertion or Removal).
To process the device plug in / pull out in Linux / OSX, please call this function to register the callback function. When the device is inserted or pulled out, you will be notified by the callback funcion, and then call Toupcam_Enum(...) again to enum the cameras.
Return value: HToupCam handle. Return NULL when fails (Such as the device has been pulled out).
Parameters:
id: ToupCam camera instance, enumerated by Toupcam_Enum. If id is NULL, Toupcam_Open will open the first camera which connects to the computer. So, if we don't care about that multiple cameras connect to the computer simultaneously, Toupcam_Enum is optional, we can simply use NULL as the parameter.
Remarks: open the camera instance.
Return value: void
Parameters:
HToupCam h: camera instance handle
Remarks: close the camera instance. After it is closed, never use the HToupCam handle any more. Do not call Toupcam_Close in the PTOUPCAM_EVENT_CALLBACK and PTOUPCAM_DATA_CALLBACK callback function, otherwise, deadlock occurs.
Return value: HRESULT type means "success/ failure"
Parameters:
HToupCam h: instance handle opened by Toupcam_Open
HWND hWnd: event occurs, message will be posted in this window
UINT nMsg: Windows custom message type. Its WPARAM parameter means event type TOUPCAM_EVENT_xxxx, LPARAM is useless (always zero)
PTOUPCAM_EVENT_CALLBACK pEventCallback, void* pCallbackContext: callback function specified by user's application and callback context parameter. This callback function is called back from the internal thread in toupcam.dll, so great attention should be paid to multithread issue. Do not call Toupcam_Stop and Toupcam_Close in this callback function, otherwise, deadlock occurs.
typedef void (__stdcall* PTOUPCAM_EVENT_CALLBACK)(unsigned nEvent, void* pCallbackCtx);
Remarks: Obviously, Toupcam_StartPullModeWithWndMsg is only supported in Windows OS.
Return value: HRESULT type means "success/ failure". Return E_FAIL when there isn't image ready for pull.
Parameters:
HToupCam h: instance handle opened by Toupcam_Open
void* pImageData: Data buffer. Users have to make sure that the data buffer capacity is enough to save the image data.
int bits: 24, 32, 48 or 8, means RGB24, RGB32, RGB48 or 8 bits grey images. This parameter is ignored in RAW mode.
unsigned* pnWidth, unsigned* pnHeight: out parameter. width and height of image.
Remarks: when pImageData is NULL, while pnWidth and pnHeight are not NULL, you can "peek" the width and height of images.
Please ensure that the pImageData buffer is large enough to hold the entire frame data, see the table below:
Format Buffer Size RGB RGB24 DIBWIDTHBYTES(24 * Width) * Height RGB32 Width * Height * 4 RGB48 DIBWIDTHBYTES(48 * Width) * Height RGB8 grey image DIBWIDTHBYTES(8 * Width) * Height RAW 8bits Mode Width * Height 10bits, 12bits, 14bits, 16bits Mode Width * Height * 2
#ifndef DIBWIDTHBYTES
#define DIBWIDTHBYTES(bits) ((unsigned)(((bits) + 31) & (~31)) / 8)
#endif
Return value: HRESULT type means "success / failure"
Parameters:
HToupCam h: instance handle opened by Toupcam.
Open PTOUPCAM_DATA_CALLBACK pDataCallback, void* pCallbackCtx: the callback function and callback context parameters that are specified by the user's program. Toupcam.dll gets image data from the camera, then calls back this function.
typedef void (*PTOUPCAM_DATA_CALLBACK)(const void* pData, const BITMAPINFOHEADER* pHeader, BOOL bSnap, void* pCallbackCtx);
when calls back, if Parameter pData == NULL, then internal error occurs (eg: the camera pulled out suddenly).
For parameter BOOL bSnap, TRUE means still image snap by Toupcam_Snap function, FALSE means ordinary previewed pictures/ videos.
Attention: this callback function is called back from the internal thread in toupcam.dll, so great attention should be paid to multithread issue. Do not call Toupcam_Stop and Toupcam_Close in this callback function, otherwise, deadlock occurs.
Remarks: start camera instance.
Return value: HRESULT type means success / failure
Parameters:
HToupCam handle
Remarks: stop the camera instance. Do not call Toupcam_Stop in the PTOUPCAM_EVENT_CALLBACK and PTOUPCAM_DATA_CALLBACK callback function, otherwise, deadlock occurs. After stopped, it can be restart again. For example, switching the video resolution:
Step 1: call Toupcam_Stop to stop
Step 2: call Toupcam_put_Size or Toupcam_put_eSize to set the new resolution
Step 3: call Toupcam_StartPullModeWithWndMsg or Toupcam_StartPullModeWithCallback or Toupcam_StartPushMode to restart
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
Remarks: pause/continue camera instance.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned nResolutionIndex: resolution index wanted.
Remarks: snap 'still' image. When snap successfully:
a) If we use Pull Mode, it will be notified by TOUPCAM_EVENT_STILLIMAGE.
b) If we use Push Mode, the image will be returned by callback function PTOUPCAM_DATA_CALLBACK with the parameter BOOL bSnap is TRUE.
Most cameras can snap still image with different resolutions under continuous preview. For example, UCMOS03100KPA's previewed resolution is 1024*768, if we call Toupcam_Snap(h, 0), we get so called "still image" with 2048*1536 resolution.
Some cameras hasn't this ability, so nResolutionIndex must be equal the preview resolution which is set by Toupcam_put_Size, or Toupcam_put_eSize.
Whether it supports "still snap" or not, see "still" domain in ToupcamModel.
Return value: HRESULT type means success / failure. If trigger mode is not supported, the return value is E_NOTIMPL.
Parameters:
HToupCam h: camera instance handle
Remarks: in trigger mode, call this function to trigger an image:
a) If we use Pull Mode, it will be notified by TOUPCAM_EVENT_IMAGE.
b) If we use Push Mode, the image will be returned by callback function PTOUPCAM_DATA_CALLBACK with the parameter BOOL bSnap is FALSE.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned nResolutionIndex: current/present resolution index
int nWidth, int nHeight: width and height of current resolution index
Remarks: set/get current resolution
Set resolution before running Toupcam_StartPullModeWithWndMsg or Toupcam_StartPullModeWithCallback or Toupcam_StartPushMode
There are two ways to set current resolution: one is by resolution index, the other by width/height. Both ways are equivalent. For example, UCMOS03100KPA supports the following three kinds of resolution:
Index 0: 2048, 1536
Index 1: 1024, 768
Index 2: 680, 510
So Toupcam_put_Size(h, 1024, 768) is as effective as Toupcam_put_eSize(h, 1)
Return value: HRESULT type means success / failure.
Parameters:
HToupCam h: camera instance handle
unsigned xOffset: x offset, must be even number
unsigned yOffset: y offset, must be even number
unsigned xWidth: width, must be even number and must not be less than 16
unsigned yHeight: height, must be even number and must not be less than 16
Remarks: set/get the ROI. Toupcam_put_Roi(h, 0, 0, 0, 0) means to clear the ROI and restore the original size.
The second resolution of UHCCD03100KPB, UHCCD05000KPA, UHCCD05100KPA don't support ROI, so the return value is E_NOTIMPL.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned nIndex: resolution index
int* pWidth, int* pHeight: width/height
Remarks: Toupcam_get_ResolutionNumber means the number of resolution supported. Take UCMOS03100KPA as an example, if we call the function Toupcam_get_ResolutionNumber and get "3", which means it can support three kinds of resolution. Toupcam_get_Resolution obtains the width/height of each kind of resolution.
These parameters have also been contained in ToupcamModel.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned* nFourCC: raw format, see the table below
unsigned* bitdepth: Bit Depth, such as 8, 12, 14, 16
#ifndef MAKEFOURCC
#define MAKEFOURCC(a, b, c, d) ((uint32_t)(uint8_t)(a) | ((uint32_t)(uint8_t)(b) << 8) | ((uint32_t)(uint8_t)(c) << 16) | ((uint32_t)(uint8_t)(d) << 24))
#endif
MAKEFOURCC('G', 'B', 'R', 'G') GBGBGB...
RGRGRG...
GBGBGB...
RGRGRG...
...MAKEFOURCC('R', 'G', 'G', 'B') RGRGRG...
GBGBGB...
RGRGRG...
GBGBGB...
...MAKEFOURCC('B', 'G', 'G', 'R') BGBGBG...
GRGRGR...
BGBGBG...
GRGRGR...
...MAKEFOURCC('G', 'R', 'B', 'G') GRGRGR...
BGBGBG...
GRGRGR...
BGBGBG...
...MAKEFOURCC('Y', 'U', 'Y', 'V') YUV4:2:2, please see: http://www.fourcc.org MAKEFOURCC('Y', 'Y', 'Y', 'Y') Black / White camera
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned iOption: see the table
unsigned iValue: see the table
Option Description Default The value can be changed after Toupcam_StartPullModeWithWndMsg or Toupcam_StartPullModeWithCallback or Toupcam_StartPushMode? TOUPCAM_OPTION_NOFRAME_TIMEOUT Report error if cannot grab frame in a certain time.
1 = enable this feature;
0 = disable this feature.1 Yes TOUPCAM_OPTION_THREAD_PRIORITY set the priority of the internal thread which grab data from the usb device.
0 = THREAD_PRIORITY_NORMAL;
1 = THREAD_PRIORITY_ABOVE_NORMAL;
2 = THREAD_PRIORITY_HIGHEST;
Please refer to SetThreadPriority
This option is not available at Linux and OSX.0 Yes TOUPCAM_OPTION_PROCESSMODE 0 = better image quality, more cpu usage.
1 = lower image quality, less cpu usage.0 Yes TOUPCAM_OPTION_RAW 0 means RGB mode.
1 means RAW mode, read the CMOS or CCD raw data.0 No
(The return value is E_UNEXPECTED when set this option after the camera is started)TOUPCAM_OPTION_BITDEPTH Some cameras support the bit depth which is more than 8 such as 10, 12, 14, 16.
0 = use 8 bits depth.
1 = use the maximum bits depth of this camera.NA Yes TOUPCAM_OPTION_FAN Some cameras support the cooling fan.
0 = turn off the cooling fan
1 = turn on the cooling fan1 Yes TOUPCAM_OPTION_COOLER Some cameras support to turn on or off the cooler.
0 = turn off cooler
1 = turn on cooler1 Yes TOUPCAM_OPTION_LINEAR 0 = turn off linear tone mapping
1 = turn on linear tone mapping1 Yes TOUPCAM_OPTION_CURVE 0 = turn off curve tone mapping
1 = turn on curve tone mapping1 Yes TOUPCAM_OPTION_TRIGGER 0 = continuous mode
1 = trigger mode0 No
(The return value is E_UNEXPECTED when set this option after the camera is started)TOUPCAM_OPTION_RGB48 enable RGB48 format when bitdepth > 8 0 No
(The return value is E_UNEXPECTED when set this option after the camera is started)
In general, you do not need to set the value of these options. If you do want to set these options, please ensure that you understand their specific meanings.
The second resolution of UHCCD03100KPB, UHCCD05000KPA, UHCCD05100KPA don't support RAW mode.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
BOOL bEnable: TRUE or FALSE
Remarks: If you set RealTime mode as TRUE, then you get shorter frame delay but lower frame rate which damages fluency. The default value is FALSE.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
BOOL bAutoExposure: TRUE or FALSE
unsigned short Target: auto-exposure target
unsigned maxTime, unsigned short maxAGain: the maximum time and maximum analog gain of auto-exposure
Remarks: If auto exposure is enabled, the exposure time and analog gain are controlled by software to make the average brightness of the target rectangle as close as possible to the auto exposure target. The auto exposure target value is the target brightness of the target rectangle (see Toupcam_put_AEAuxRect, Toupcam_get_AEAuxRect).
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned Time: exposure time, unit: microsecond
unsigned* nMin, unsigned* nMax, unsigned* nDef: the minimum, maximum and default value of exposure time.
Remarks: exposure time related.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned short AGain: analog gain, shown in percentage, eg, 200 means the analog gain is 200%
unsigned short* nMin, unsigned short* nMax, unsigned short* nDef: the minimum, maximum and default value of analog gain.
Remarks: analog gain related.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
Remarks: set or obtain hue, saturation, brightness, contrast and gamma.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
BOOL bChrome: TRUE or FALSE
Remarks: color or gray mode
Return value: HRESULT type means success / failure
Parameters: HToupCam h: camera instance handle
Remarks: vertical/horizontal flip.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned short nSpeed: frame rate level
Remarks: the minimum frame rate level is "0", the maximum one can be achieved through Function "Toupcam_get_MaxSpeed" which equals to maxspeed in ToupcamModel.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
int nHZ: 0: 60Hz alternating current, 1: 50Hz alternating current, 2: direct current
Remarks: set the light source power frequency
Return value: HRESULT type means success / failure, E_NOTIMPL means not supporting get / set the temperature
Parameters:
HToupCam h: camera instance handle
short nTemperature: in 0.1 degrees Celsius (32 means 3.2 degrees Celsius).
Remarks: get / set the temperature of sensor. see TOUPCAM_FLAG_GETTEMPERATURE and TOUPCAM_FLAG_PUTTEMPERATURE.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
BOOL bSkip: Bin mode or Skip mode.
Remarks: set Bin mode or Skip mode. Cameras with higher resolution can support two sampling modes, one is Bin mode (Neighborhood averaging), the other is Skip (sampling extraction). In comparison, the former is with better image effect but decreasing frame rate while the latter is just the reverse.
Return value: HRESULT type means success / failure. Works int Temp/Tint mode. Does not work int RGB Gain mode, E_NOTIMPL will be return.
Parameters:
HToupCam h: camera instance handle
int nTemp, int nTint: color temperature and Tint
Remarks: set/obtain the color temperature and Tint parameters of white balance (Temp/Tint Mode, please see here).
Return value: HRESULT type means success / failure. Works int Temp/Tint mode. Does not work int RGB Gain mode, E_NOTIMPL will be return.
Parameters:
HToupCam h: camera instance handle
PITOUPCAM_TEMPTINT_CALLBACK fnTTProc, void* pTTCtx: callback function and callback context when the automatic white balance completes.
Remarks: Call this function to perform one "auto white balance" in Temp/Tint Mode. When the "auto white balance" completes, TOUPCAM_EVENT_TEMPTINT event notify the application (In Pull Mode) and callback happens. In pull mode, this callback is useless, set it to NULL.
Return value: HRESULT type means success / failure. Works int RGB Gain mode. Does not work int Temp/Tint Gain mode, E_NOTIMPL will be return.
Parameters:
HToupCam h: camera instance handle
int aGain[3]: RGB Gain
Remarks: set/obtain the RGB gain parameters of white balance (RGB Gain Mode, please see here).
Return value: HRESULT type means success / failure. Works int RGB Gain mode. Does not work int Temp/Tint mode, E_NOTIMPL will be return.
Parameters:
HToupCam h: camera instance handle
PITOUPCAM_WHITEBALANCE_CALLBACK fnWBProc, void* pWBCtx: callback function and callback context when the automatic white balance completes.
Remarks: Call this function to perform one "auto white balance" in RGB Gain Mode. When the "auto white balance" completes, TOUPCAM_EVENT_WBGAIN event notify the application (In Pull Mode) and callback happens. In pull mode, this callback is useless, set it to NULL.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
Remarks: set/obtain the ROI (Rectangle of Interest) of automatic white balance and auto-exposure. The default ROI is in the center of the image, its width is 20% image with, its height is 20% image height.
Return value: S_OK means mono mode, S_FALSE means color mode
Parameters:
ToupCam h: camera instance handle
Remarks: gray camera or not, find the flag in ToupCamModel: TOUPCAM_FLAG_MONO
Return value: the maximum bit depth this camera supports.
Parameters:
HToupCam h: camera instance handle
Remarks: Some cameras support the bit depth which is more than 8 such as 10, 12, 14, 16.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned nIndex: resolution index
int* pWidth, int* pHeight: width/height
Remarks: Toupcam_get_StillResolutionNumber means the number of supported still resolution. Take UCMOS03100KPA as an example, if we call the function Toupcam_get_StillResolutionNumber and get "3", which means it can support three kinds of resolution. If it doesn't support "still snap", then we get "0". Toupcam_get_Resolution obtains the width/height of each kind of resolution.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
char sn[32]: buffer to the serial number, such as: TP110826145730ABCD1234FEDC56787
char fwver[16]: buffer to the firmware version, such as: 3.2.1.20140922
char hwver[16]: buffer to the hardware version, such as: 3.2.1.20140922
char pdate[10]: buffer to the production date, such as: 20150327
Remarks: each camera has a unique serial number with 31 letters, eg,"TP110826145730ABCD1234FEDC56787"
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned short iLed: the index of LED light
unsigned short iState: LED status, 1 -> Ever bright; 2 -> Flashing; other -> Off
unsigned short iPeriod: Flashing Period (>= 500ms)
Remarks: One or more LED lights installed on some camera. This function controls the status of these lights.
Return value: HRESULT type means failure or byte(s) transferred
Parameters:
HToupCam h: camera instance handle
unsigned addr: EEPROM address
const unsigned char* pData: data to be written
unsigned char* pBuffer: read EEPROM to buffer
unsigned nDataLen: data length to be written
unsigned nBufferLen: buffer length to read
Remarks: In some cameras, EEPROM is available for read and write. If failed to read or write, a negative HRESULT error code will be return, when success, the bytes number has been read or written will be return.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
PITOUPCAM_EXPOSURE_CALLBACK fnExpoProc, void* pExpoCtx: exposure callback function and callback context. If we set fnExpoProc as NULL, then it means stop calling back.
Remarks: Once we set non-NULL callback function, then callback happens whenever the exposure time changes.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
PITOUPCAM_CHROME_CALLBACK fnChromeProc, void* pChromeCtx: color/gray switches callback function and callback context. If we set fnChromeProc as NULL, then it means stop calling back.
Remarks: once we set non-NULL callback function, then callback happens whenever the color/gray switches, eg, call Toupcam_put_Chrome
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
Remarks: auto Level Range.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
unsigned short aLow[4], unsigned short aHigh[4]: Level Range of R, G, B, and Gray. RGB is only available for color image, and gray is only available for gray image.
Remarks: level range related.
Return value: HRESULT type means success / failure
Parameters:
HToupCam h: camera instance handle
PITOUPCAM_HISTOGRAM_CALLBACK fnHistogramProc, void* pHistogramCtx: callback function and callback context of histogram data.
Remarks: obtain histogram data.
Toupcam does support .NET development environment (C# and VB.NET).
toupcam.cs in the 'inc' directory use P/Invoke call into toupcam.dll. Copy toupcam.cs to your C# project, please reference toupcamdemowinformcs1 and toupcamdemowinformcs2 in the samples directory.
The C# class ToupTek.ToupCam is a thin wrapper class of the native C/C++ API of toupcam.dll, it's properties and methods P/Invoke into the corresponding Toupcam_xxxx functions of toupcam.dll. So, the descriptions of the Toupcam_xxxx function are also applicable for the corresponding C# properties or methods. For example, the C# Snap method call the function Toupcam_Snap, the descriptions of the Toupcam_Snap function is applicable for C# Snap method:
[DllImport("toupcam.dll", ExactSpelling = true, CallingConvention = CallingConvention.StdCall)] private static extern int Toupcam_Snap(SafeHToupCamHandle h, uint nResolutionIndex); public bool Snap(uint nResolutionIndex) { if (_handle == null || _handle.IsInvalid || _handle.IsClosed) return false; return (Toupcam_Snap(_handle, nResolutionIndex) >= 0); } |
VB.NET is similar with C#, not otherwise specified.
Windows: BGR
OSX, Linux: RGB
Parameters Range Default value Get Set Auto Auto Exposure Target 16~235 120 Toupcam_get_AutoExpoTarget Toupcam_put_AutoExpoTarget White Balance Temp/Tint Mode Color Temperature 2000~15000 6503 Toupcam_get_TempTint Toupcam_put_TempTint Toupcam_AwbOnePush Tint 200~2500 1000 RGB Gain Mode Red Gain -128~128 0 Toupcam_get_WhiteBalanceGain Toupcam_put_WhiteBalanceGain Toupcam_AwbInit Green Gain Blue Gain LevelRange 0~255 Low = 0
High = 255Toupcam_get_LevelRange Toupcam_put_LevelRange Toupcam_LevelRangeAuto Contrast -100~100 0 Toupcam_get_Contrast Toupcam_put_Contrast Hue -180~180 0 Toupcam_get_Hue Toupcam_put_Hue Saturation 0~255 128 Toupcam_get_Saturation Toupcam_put_Saturation Brightness -64~64 0 Toupcam_get_Brightness Toupcam_put_Brightness Gamma 20~180 100 Toupcam_get_Gamma Toupcam_put_Gamma
x86: XP SP3 or above
x64: Win7 or above
x86: GLIBC 2.9 or above. (GLIBC 2.9 is released in November 2008)
x64: GLIBC 2.14 or above. (GLIBC 2.14 is released in June 2011)
v1.6: support RGB48 when bit depth > 8, please see here
v1.5: support trigger mode
v1.4: White Balance: Temp/Tint Mode vs RGB Gain Mode, please see here
v1.3: ROI (Region Of Interest) supported: please see here
v1.2: more bit depth supported: 10bits, 12bits, 14bits, 16bits
v1.1: support RAW format, please see here and here; support Linux and OSX
v1.0: initial release
If you have any problems in using this SDK, please use the following information to contact us.
www: www.touptek.com
email: support@touptek.com