ApBase API Development Guide

ApBase API Development Guide

Current as of Release 5.0.37

 

Introduction

The ApBase API provides an easy to use interface for controlling Aptina demo kit cameras.
ApBase performs these primary functions:

  •  

    • Enumerate all of the demo kit cameras that are connected to the host PC.

    • Run initialization scripts start the camera or change modes.

    • Provide read/write access to sensor/SOC/ISP registers. Further, ApBase understands what register settings on the sensor do, keeps track of all relevant sensor modes, and automatically updates the demo kit hardware when the sensor mode changes. For example, if a register write enables MIPI output from the sensor, ApBase will automatically enable the MIPI receiver on the demo kit hardware.

    • Receive images from the camera device.

    • Convert the image received from the demo kit into RGB for saving to a file or displaying on the screen.

Additional Information can be found in the following documents

  • State Variables; as used in INI files with "STATE=", see "ap_GetState" and "ap_SetState" for usage.

  • Modes; there are a few modes setings from INI files, see "ap_GetMode" and "ap_SetMode" for usage.

  • "apbase.h"; many other calls are available and found by searching for "ap_".

ApBase API is available in 64-bit only.

Quick Start

To use ApBase in C or C++, include the apbase.h header file, and link to apbase.lib.

When running the application, be sure that the following folders supplied with the DevWare installer are present;

    • apps_data, board_data, and sensor_data

Sample programs can be found here:

    • C:\Aptina Imaging\samples\SimpleQt

    • C:\Aptina Imaging\samples\SimpleCapture

 

Here is a minimal procedure to open a demo kit camera, initialize the Aptina device, grab an image and convert it to RGB.

#include "apbase.h"

AP_HANDLE hApBase = ap_Create(0);
if (hApBase == NULL)
    return;

ap_LoadIniPreset(hApBase, NULL, NULL);   // initialize the sensor with the default from "Demo Initialization" preset

       // Read all sensor registers and configure the Demo3 and software according to the sensor settings.
       ap_CheckSensorState(apbase, 0);

size_t bufSize = ap_GrabFrame(hApBase, NULL, 0);
unsigned char *pBuffer = new unsigned char [bufSize];
ap_GrabFrame(hApBase, pBuffer, bufSize);

unsigned char *pRGB = NULL;
ap_u32 rgbWidth = 0, rgbHeight = 0, rgbBitDepth = 0;
if (ap_GetLastError() == MI_CAMERA_SUCCESS)
    pRGB = ap_ColorPipe(hApBase, pBuffer, bufSize, &rgbWidth, &rgbHeight, &rgbBitDepth);

delete [] pBuffer;
ap_Destroy(hApBase);
ap_Finalize();

Note: The call to ap_LoadIniPreset() with NULL parameters is only applicable in situations where the default initialization is sufficient. For demo kits with multiple possible configurations, such as ISP + sensor combinations or different connection options, you will need to specify the particular initialization preset for the configuration.

Note: when using a Demo3, it is recommended to perform a single call to ap_GrabFrame() after the call to ap_LoadIniPreset() to ensure that the Demo3 FIFO doesn't have a partial frame.

Please check out our YouTube video on ApBase for a quick overview.

Functions for Enumerating and Opening Devices

If using a specific verison of Python, set the path first using ap_SetPythonEnvPath().

To access the camera, first create a device handle using a Create call, or a Probe call followed by a Create call.

void ap_SetPythonEnvPath(const char *szPythonDir)

Parameters

Python install path; for example, "\\Users\\acecoder\\AppData\\Local\\Programs\\Python\\Python39".

Remarks

Must be called before device creation - recommended to make it the first ApBase call.

ap_s32 ap_DeviceProbe(const char *szSensorDataDirOrFile)

Parameters

A pointer to a file name or directory name. Can be NULL.

Return Value

Error code.

Remarks

Search the system for Aptina demo kit devices or other compatible camera devices, identify the type of sensor or ISP, and build a set of internal data structures for each device. Use ap_Create() to create the handle used by the other API functions to access the device.

If the parameter is NULL, the default installation directory is searched for a sensor data file matching each device. Otherwise the parameter can be a specific sensor data file (.xsdat file) to be used with the device, or a directory to be searched for compatible sensor data files.

ApBase will keep track of the modes and state of all of the devices. When the application is done using the ApBase API, call ap_Finalize() to close all drivers and free all memory associated with the devices.

ap_s32 ap_DeviceProbeDll(const char *szSensorDataDirOrFile, const char *szTransportDll)

Parameters

szSensorDataDirOrFile: a pointer to a file name or directory name. Can be NULL.

szTransportDll: a pointer to the location of the replacement Transport DLL. Can be NULL.

Return Value

Error code.

Remarks

Like ap_DeviceProbe(), except an alternative Transport DLL can be defined.  See ap_DeviceProbe() for additional information.

void ap_CancelProbe()

Cancel a device probe in progress in another thread.

int ap_NumCameras()

Return Value

Number of cameras.

Remarks

Return the number of cameras discovered by the device probe function.

void ap_Finalize()

Close all drivers and free all memory associated with the devices. Any existing AP_HANDLEs become invalid, so destroy all handles first.

ap_s32 ap_GetLastError()

Comments