Starshootg API Manual


1. Version & Platform



2. Introduction


Starshootg cameras support various kinds of APIs (Application Program Interface), namely Native C/C++, .NET/C#/VB.NET, Python, Java, DirectShow, Twain, LabView, MabLab 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:

starshootg.h, C/C++ head file


3. Concepts and terminology


a. Modes for accessing image data: "Pull Mode" vs "Push Mode"

Starshootg 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 Starshootg_StartPullModeWithWndMsg. When event occurs, starshootg will post message (PostMessage) to the specified window. Parameter WPARAM is the event type, refer to the definition of STARSHOOTG_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 macOS.)

b) Use Callback function: Start pull mode by using the function Starshootg_StartPullModeWithCallback. When event occurs, starshootg will callback the function PSTARSHOOTG_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:

STARSHOOTG_EVENT_EXPOSURE exposure time changed
STARSHOOTG_EVENT_TEMPTINT white balance changed. Temp/Tint Mode, please see here.
STARSHOOTG_EVENT_WBGAIN white balance changed. RGB Gain Mode, please see here.
STARSHOOTG_EVENT_IMAGE Video image data arrives. Use Starshootg_PullImage(V2) to 'pull' the image data
STARSHOOTG_EVENT_STILLIMAGE Still image which is triggered by function Starshootg_Snap or Starshootg_SnapN arrives. Use Starshootg_PullStillImage(V2) to 'pull' the image data
STARSHOOTG_EVENT_ERROR Generic error, data acquisition cannot continue
STARSHOOTG_EVENT_DISCONNECTED Camera disconnected, maybe has been pulled out
STARSHOOTG_EVENT_NOFRAMETIMEOUT Grab image no frame timeout error, data acquisition cannot continue
STARSHOOTG_EVENT_NOPACKETIMEOUT Grab image no packet timeout
STARSHOOTG_EVENT_TRIGGERFAIL trigger failed (for example, bad frame data or timeout)
STARSHOOTG_EVENT_BLACK black balance changed
STARSHOOTG_EVENT_FFC flat field correction status changed
STARSHOOTG_EVENT_DFC dark field correction status changed
STARSHOOTG_EVENT_ROI roi changed
STARSHOOTG_EVENT_LEVELRANGE level range changed
STARSHOOTG_EVENT_EXPO_START hardware event: exposure start
STARSHOOTG_EVENT_EXPO_STOP hardware event: exposure stop
STARSHOOTG_EVENT_TRIGGER_ALLOW hardware event: next trigger allow
STARSHOOTG_EVENT_HEARTBEAT hardware event: heartbeat, can be used to monitor whether the camera is alive
STARSHOOTG_EVENT_FACTORY restore factory settings. Please note that restoring factory settings may cause resolution changes.

b. Still Capture (Still Image)

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 Starshootg_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, STARSHOOTG_EVENT_STILLIMAGE will be sent out for external acknowledgement. The external application should call Starshootg_PullStillImage(V2) to get the still captured image.
b) In push mode operation, after the still capture, the callback function PSTARSHOOTG_DATA_CALLBACK_V3 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 Starshootg_get_StillResolutionNumber function or check the still field of the struct StarshootgModelV2.

c. Data format: RGB vs RAW

Starshootg supports two data formats: RGB format (default) and RAW format. RAW format could be enabled by assigning STARSHOOTG_OPTION_RAW parameter to 1 when calling Starshootg_put_Option function.

Users could switch these two format by calling Starshootg_put_Option function with different value setting to STARSHOOTG_OPTION_RAW. You must call this function BEFORE the camera start function (Starshootg_StartPullModeWithWndMsg or Starshootg_StartPullModeWithCallback or Starshootg_StartPushMode).

d. White Balance and Auto White Balance: Temp/Tint mode vs RGB Gain mode

1. Starshootg 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. Starshootg_get_TempTint function is used to acquire the temp and tint values and Starshootg_put_TempTint is used to set the temp and tint values. Function Starshootg_AwbOnce is used to execute the auto white balance. When the white balance parameters change, STARSHOOTG_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. Starshootg_get_WhiteBalanceGain is used to acquire the parameters and Starshootg_put_WhiteBalanceGain is used to set the white balance parameters. Starshootg_AwbInit is used to execute the execute the auto white balance. When the white balance parameters change, STARSHOOTG_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 Starshootg_get_TempTint and Starshootg_put_TempTint and Starshootg_AwbOnce. Starshootg_get_WhiteBalanceGain and Starshootg_put_WhiteBalanceGain and Starshootg_AwbInit cannot be used, they always return E_NOTIMPL.
b) In RGB Gain mode, please use Starshootg_get_WhiteBalanceGain and Starshootg_put_WhiteBalanceGain and Starshootg_AwbInit. Starshootg_get_TempTint and Starshootg_put_TempTint and Starshootg_AwbOnce cannot be used, they always return E_NOTIMPL

When calling Starshootg_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 Starshootg_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 "once" auto white balance. The white balance parameters will be always calculated and updated for the continuous auto white balance mechanism. For "once" auto white balance mechanism, the white balance parameters will be calculated and updated only when triggered. Starshootg cameras support "once" 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.

e. Trigger Mode

1. What is Trigger Mode

Starshootg camera has two working modes: video mode and trigger mode. When in trigger mode, no images will be available until the trigger conditions are met. Cameras have 2 types for triggering according to the types of trigger source, including software trigger mode, external trigger mode and simulated trigger mode.

2. The Difference between Trigger and Snap

Trigger mode is designed for accurate control of the camera and images would be acquired only when the conditions are met. Users could get the images by controlling the trigger conditions. Trigger mode must be pre-specified. Once the trigger mode is entered, no images will come out from the camera until the trigger conditions are met. The triggered images will stay the same property as the pre-specified resolution. Snap is designed to acquire the images from the camera in video mode. The resolution of the snapped image could be the same resolution as the video or could be different.

3. Software Trigger Mode

Camera could be triggered by software. In software trigger mode, images burst out only when users trigger the camera from the software. Numbers of the images of the triggering could also be controlled by software.

4. External Trigger Mode

Camera could be triggered by external trigger signal. By now Starshootg camera only supports positive-edge trigger mode.

5. Mix Trigger Mode

Both external and software trigger are enabled.

6. Simulated Trigger Mode

For cameras that do not support software trigger and external trigger, simulated trigger mode could be available. When in simulated trigger mode, the camera hardware actually works in the same mode as the video mode. But the up-level software will not obtain any images from the camera. The software buffer will stay empty until the user set the trigger conditions by software.

7. How to Enter the Trigger Mode

After the numeration of the connected camera, you can check the flag and find out what trigger mode does the camera support according to the following definition.
#define STARSHOOTG_FLAG_TRIGGER_SOFTWARE   0x00080000  /* support software trigger */
#define STARSHOOTG_FLAG_TRIGGER_EXTERNAL   0x00100000  /* support external trigger */
#define STARSHOOTG_FLAG_TRIGGER_SINGLE     0x00200000  /* only support trigger single: one trigger, one image */
Function Starshootg_put_Option(HStarshootg h, unsigned iOption, int iValue) could be used to set the camera to trigger mode when assign STARSHOOTG_OPTION_TRIGGER to the iOption parameter. iValue is used to specify the types of the trigger modes. Please see the following for reference.
#define STARSHOOTG_OPTION_TRIGGER   0x0b    /* 0 = video mode, 1 = software or simulated trigger mode, 2 = external trigger mode, 3 = external + software trigger, default value = 0 */
Function Starshootg_get_Option(HStarshootg h, unsigned iOption, int* piValue) could be used to get what type of trigger mode the camera is in.

8. How to Trigger the camera

Function Starshootg_Trigger(HStarshootg h, unsigned short nNumber) could be used to trigger the camera. Assigning different value to nNumber means different:
nNumber = 0 means stop the trigger.
nNumber = 0xFFFF means trigger continuously, the same as video mode;
nNumber = other valid values means nNumber images will come out from the camera.
If the STARSHOOTG_FLAG_TRIGGER_SINGLE flag is checked, the nNumber parameter must be assigned to 1 and 1 image will come out from the camera when Starshootg_Trigger is called.
Enter the trigger mode first and then call Starshootg_Trigger function to trigger the camera.

9. Trigger timeout

The timeout is recommended for not less than (Exposure Time * 102% + 4 Seconds).

4. Functions



5. .NET and C# and VB.NET


Starshootg does support .NET development environment (C# and VB.NET).

starshootg.cs use P/Invoke to call into starshootg.dll. Copy starshootg.cs to your C# project, please reference demowinformcs1, demowinformcs2 and demowinformcs3 in the samples directory.

Please pay attation to that the object of the C# class Starshootg. Starshootg must be obtained by static mothod Open or OpenByIndex, it cannot be obtained by obj = new Starshootg (The constructor is private on purpose).

Most properties and methods of the Starshootg class P/Invoke into the corresponding Starshootg_xxxx functions of starshootg.dll/so. So, the descriptions of the Starshootg_xxxx function are also applicable for the corresponding C# properties or methods. For example, the C# Snap method call the function Starshootg_Snap, the descriptions of the Starshootg_Snap function is applicable for C# Snap method:

[DllImport("starshootg.dll", ExactSpelling = true, CallingConvention = CallingConvention.StdCall)]
private static extern int Starshootg_Snap(SafeHStarshootgHandle h, uint nResolutionIndex);

public bool Snap(uint nResolutionIndex)
{
    if (_handle == null || _handle.IsInvalid || _handle.IsClosed)
        return false;
    return (Starshootg_Snap(_handle, nResolutionIndex) >= 0);
}

VB.NET is similar with C#, not otherwise specified.


6. Python


Starshootg does support Python (version 3.0 or above), please import starshootg to use starshootg.py and reference the sample code simplest.py and qt.py.

Please pay attation to that the object of the python class starshootg.Starshootg must be obtained by classmethod Open or OpenByIndex, it cannot be obtained by obj = starshootg.Starshootg()

Most methods of the Starshootg class use ctypes to call into the corresponding Starshootg_xxxx functions of starshootg.dll/so/dylib. So, the descriptions of the Starshootg_xxxx function are also applicable for the corresponding python methods.

Please reference __errcheck in starshootg.py, the original HRESULT return code is mapped to HRESULTException exception (in win32 it's inherited from OSError).

Please make sure the starshootg dll/so/dylib library file is in the same directory with starshootg.py.


7. Java


Starshootg does support Java, starshootg.java use JNA (https://github.com/java-native-access/jna) to call into starshootg.dll/so/dylib. Copy starshootg.java to your java project, please reference the sample code simplest.java (Console), javafx.java, swing.java.

Please pay attation to that the object of the java class starshootg must be obtained by static method Open or OpenByIndex, it cannot be obtained by obj = new starshootg()(The constructor is private on purpose).

Most methods of the starshootg class use JNA to call into the corresponding Starshootg_xxxx functions of starshootg.dll/so/dylib. So, the descriptions of the Starshootg_xxxx function are also applicable for the corresponding java methods.

Please reference errcheck in starshootg.java, the original HRESULT return code is mapped to HRESULTException exception.

Remark: (1) Download jna-*.jar from github; (2) Make sure starshootg.dll/so/dylib is placed in the correct directory.


8. Samples


Name Platform Language Dependency UI Description
demosimplest Win32, Linux, macOS, Android C++   console simplest sample, about 60 lines of code
demoraw raw data and snap still image, about 120 lines of code
demoqt Win32, Linux, macOS Qt GUI Qt sample
democpp Win32 ATL/WTL demonstrates to enumerate device, open device, video preview, image capture, set the preview resolution, trigger, multi-format image saving (.bmp, .jpg, .png, etc), wmv format video recording, trigger mode, IO control 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
democallback use Pull Mode, StartPullModeWithCallback
demopush use Push Mode, StartPushModeV3
demomono demonstrates to use mono camera with 8 or 16 bits
demomfc MFC 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
AutoTestTool auto test tool used to automatically test, such as open/close the camera, change the resolution, snap, ROI, bitdepth, etc
demowinformcs1 .NET C#   winform sample. This sample use Pull Mode, StartPullModeWithWndMsg
demowinformcs2 winform sample. This sample use Pull Mode, StartPullModeWithCallback
demowinformcs3 winform sample. This sample use Push Mode, StartPushModeV3
demowinformvb VB.NET winform sample. This sample use Pull Mode
demouwp WinRT C# Universal Windows Platform simple demo, before build and run this demo, please change the value of vidpid in file Package.appxmanifest
demoandroid Android C++, Java Android sample
demojava simplest Win32, Linux, macOS Java jna console simplest java sample
javafx GUI javafx sample
swing swing sample
demopython simplest Python   console simplest python sample
qt PyQt GUI PyQt sample
demodshow Win32 DirectShow C++ MFC DirectShow sample
amcap   copy from Microsoft DirectShow SDK

9. Changelog


v50: SIMD optimize in Windows(x86/x64), Linux(x64) and Android(x64)
       frontend and backend deque length: STARSHOOTG_OPTION_FRONTEND_DEQUE_LENGTH, STARSHOOTG_OPTION_BACKEND_DEQUE_LENGTH

v49: Add support to save & load configuration. Please see here

v48: hardware event. Please see here, here and here

v47: hardware level range. Please see here and here

v46: Add support denose. Please see here

v45: Add sequencer trigger, UART, mix trigger (external and software trigger both are enabled)

v44: Extend the realtime mode, Please see here
       Add STARSHOOTG_OPTION_CALLBACK_THREAD and STARSHOOTG_OPTION_FRAME_DEQUE_LENGTH

v43: Reload the last frame in the trigger mode. Please see STARSHOOTG_OPTION_RELOAD

v42: Precise frame rate and bandwidth. Please see here and STARSHOOTG_FLAG_PRECISE_FRAMERATE

v41: no packet timeout. Please see here

v40: Auto test tool, see samples\AutoTestTool

v39: Update C#/VB.NET/Java/Python

v38: Add support to byte order, change BGR/RGB. Please see here

v37: Add Android support
       Add Starshootg_StartPushModeV3 (Starshootg_StartPushModeV2 and Starshootg_StartPushMode are obsoleted)

v36: Add Java support. Please see here

v35: Add Python support. Please see here

v34: Auto Focus and Focus Motor

v33: extend STARSHOOTG_OPTION_AGAIN to STARSHOOTG_OPTION_AUTOEXP_POLICY, support more options. Please see here

v32: Addd support to Windows 10 on ARM and ARM64, both desktop and WinRT

v31: Add Starshootg_deBayerV2, support RGB48 and RGB64

v30: Add STARSHOOTG_FLAG_CGHDR

v29: Add StarshootgFrameInfoV2, a group of functions (PullImageV2 and StartPushModeV2), some cameras support frame sequence number and timestamp. Please see here

v28: Add Starshootg_read_Pipe, Starshootg_write_Pipe, Starshootg_feed_Pipe

v27: Add Starshootg_SnapN, support to snap multiple images, please see here and democpp

v26: Add support to restore factory settings, STARSHOOTG_OPTION_FACTORY

v25: Add sharpening, STARSHOOTG_OPTION_SHARPENING

v24: Add support to Exposure time with the 50/60 HZ constraint

v23: Add support to Linux armhf, armel and arm64
       Add FFC and DFC, please see here and here

v22: Add STARSHOOTG_OPTION_DDR_DEPTH, please see here

v21: Add Starshootg_IoControl

v20: Add Starshootg_EnumV2, StarshootgModelV2, StarshootgDeviceV2; (Starshootg_Enum, StarshootgModel and StarshootgDevice are obsoleted)
       Add Pixel Format, see STARSHOOTG_OPTION_PIXEL_FORMAT; (STARSHOOTG_OPTION_PIXEL_FORMAT is the super set of STARSHOOTG_OPTION_BITDEPTH)
       Add Flat Field Correction

v19: Add Black Balance: please see here

v18: Add Starshootg_get_Revision

v17: Add STARSHOOTG_OPTION_ROTATE

v16: Add STARSHOOTG_FLAG_DDR, use very large capacity DDR (Double Data Rate SDRAM) for frame buffer

v15: Add STARSHOOTG_OPTION_BINNING

v14: Add support to WinRT / UWP (Universal Windows Platform) / Windows Store App

v13: support row pitch, please see Starshootg_PullImageWithRowPitch and Starshootg_PullStillImageWithRowPitch

v12: support RGB32, 8 bits Gray, 16 bits Gray, please see here

v11: black level: please see here

v10: demosaic method: please see here

v9: change the histogram data type from double to float

v8: support simulated trigger, please see here

v7: support RGB48 when bit depth > 8, please see here

v6: support trigger mode, please see here

v5: White Balance: Temp/Tint Mode vs RGB Gain Mode, please see here

v4: ROI (Region Of Interest) supported: please see here

v3: more bit depth supported: 10bits, 12bits, 14bits, 16bits

v2: support RAW format, please see here and here; support Linux and macOS

v1: initial release