This example shows how to acquire data from a sensor using the perClass Mira Camera API. The sensor used is a Headwall MV.C VNIR. The example is generic and should work unchanged with other line-scan cameras when linked to their respective perClass acquisition plugin. If the camera is not a VNIR camera, then it may also be required to change the resampling wavelengths.


The example shows how to:

  • Query the version of the acquisition library (line 12-17)
  • Initialize the acquisition plugin (line 19-23)
  • Scan for available devices and print their names (line 25-31)
  • Open a device (line 33-35)
  • Test if a device is line-scan or snapshot (line 37-42)
  • Initialize acquisition (line 44-50)
  • Setup wavelength resampling to specific output wavelengths irrespective of a device (line 52-58)
  • Query frame geometry, data type, and layout (line 60-72)
  • Set exposure and frame rate (line 74-75)
  • Allocate a buffer for 100 frames (line 77-84)
  • Acquire 100 frames into the buffer (line 86-101)
  • Write the buffer contents to a file (line 106-116)


In order to compile this example, save it as example.c, and then use the command for the operating system to compile on:


On Windows using the Microsoft Visual C/C++ compiler:

> cl example.c -I "C:\Program Files\perClass Mira\include" "C:\Program Files\perClass Mira\lib\miraacq_ximea_1.13.1.lib"


On Linux using GCC:

> gcc example.c -o example -I"/opt/perClass/Mira/include" -L"/opt/perClass/Mira/lib" -lmiraacq_ximea_1.13.1


Note that we point to the lib sub-directory of the perClass Mira installation for includes and directly link with the acquisition plugin for the camera (XIMEA plugin for MV.C VNIR).

  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>

  4. #include "miraacq.h"

  5. int main(int argc, const charargv[])
  6. {
  7.    int res = MIRA_OK;
  8.    uint16_tpBuf = NULL;

  9.    int api, step, rev;
  10.    const char* pAPIVersionStr = miraacq_GetAPIVersion(&api, &step, &rev);
  11.    printf("Example of acquiring data using perClass Mira Acquisition Plugin\nVersion: %d.%d.%d (%s)\n", api, step, rev, pAPIVersionStr);

  12.    const charpVersionStr = miraacq_GetVersion();
  13.    printf("Version: '%s'\n", pVersionStr);

  14.    makernelpma = miraacq_Init(".");
  15.    printf("Init: %s"miraacq_GetErrorMsg(pma));
  16.    if (pma == NULL) {
  17.        goto Error;
  18.    }

  19.    MIRAACQ_CHECK(miraacq_ScanDevices(pma));

  20.    const int deviceCount = miraacq_GetDeviceCount(pma);
  21.    printf("\n%d devices:\n", deviceCount);
  22.    for (int i = 0; i < deviceCount; i++) {
  23.        printf(" %d : %s\n", imiraacq_GetDeviceName(pma, i));
  24.    }

  25.    int deviceInd = 0;
  26.    MIRAACQ_CHECK(miraacq_OpenDevice(pma, deviceInd));
  27.    printf("Device opened: %d '%s'\n", deviceInd, miraacq_GetDeviceName(pma, deviceInd));

  28.    int isSnapshot = miraacq_DeviceIsSnapshot(pma);
  29.    if (isSnapshot) {
  30.        printf("A line-scan device required by this example\n");
  31.        MIRAACQ_CHECK(miraacq_CloseDevice(pma, deviceInd));
  32.        goto Error;
  33.    }

  34.    printf("Initializing the acquisition...");
  35.    res = miraacq_InitializeAcquisition(pma);
  36.    printf("done res=%d\n", res);
  37.    if (res != MIRA_OK) {
  38.        MIRAACQ_CHECK(miraacq_CloseDevice(pma, deviceInd));
  39.        goto Error;
  40.    }

  41.    printf("Setting resampling from 400 to 1000, step 2\n");
  42.    int bands = ((1000 - 400) / 2) + 1;
  43.    MIRAACQ_CHECK(miraacq_SetResamplingWavelengthCount(pma, bands));
  44.    for (int i = 0; i < bands; i++) {
  45.        MIRAACQ_CHECK(miraacq_SetResamplingWavelength(pma, i, 400 + (2 * i)));
  46.    }
  47.    MIRAACQ_CHECK(miraacq_SetResampling(pma, 1));

  48.    printf("Geometry: width=%d bands=%d lines=%d dataType=%d dataLayout=%d frameSize=%d\n",
  49.           miraacq_GetFrameWidth(pma),
  50.           miraacq_GetFrameBands(pma),
  51.           miraacq_GetFrameHeight(pma),
  52.           miraacq_GetFrameDataType(pma),
  53.           miraacq_GetFrameDataLayout(pma),
  54.           miraacq_GetFrameSize(pma));

  55.    if (miraacq_GetFrameDataType(pma) != ACQ_DATATYPE_UINT16) {
  56.        printf("UINT16 data type expected by this example\n");
  57.        MIRAACQ_CHECK(miraacq_CloseDevice(pma, deviceInd));
  58.        goto Error;
  59.    }

  60.    MIRAACQ_CHECK(miraacq_SetExposure(pma, 4.0));
  61.    MIRAACQ_CHECK(miraacq_SetFrameRate(pma, 100.0));

  62.    const int frames = 100;
  63.    int frameSize = miraacq_GetFrameSize(pma);
  64.    pBuf = malloc(frames * frameSize);
  65.    if (pBuf == NULL) {
  66.        printf("Failed to allocate memory for %d frames\n", frames);
  67.        MIRAACQ_CHECK(miraacq_CloseDevice(pma, deviceInd));
  68.        goto Error;
  69.    }

  70.    MIRAACQ_CHECK(miraacq_StartAcquisition(pma));

  71.    uint16_tptr = pBuf;
  72.    size_t frameID = 0;

  73.    // offset to the next frame in uint16 units (a frame has width x bands units)
  74.    int nextFrameOffset miraacq_GetFrameWidth(pma) * miraacq_GetFrameBands(pma);

  75.    printf("Acquiring %d frames:\n", frames);
  76.    for (int i = 0; i < frames; i++) {
  77.        MIRAACQ_CHECK(miraacq_GetFrame(pma, ptr, &frameID, 1000));
  78.        ptr += nextFrameOffset;
  79.    }

  80.    printf("Stopping acquisition\n");
  81.    MIRAACQ_CHECK(miraacq_StopAcquisition(pma));

  82.    printf("Closing device\n");
  83.    MIRAACQ_CHECK(miraacq_CloseDevice(pma, deviceInd));

  84.    printf("Writing data to file: ");
  85.    FILEpFile = fopen("out.bin", "wb");
  86.    if (pFile == NULL) {
  87.        printf("Cannot open file for writing\n");
  88.        goto Error;
  89.    }

  90.    size_t countWritten = fwrite(pBuf, (size_t)frameSize, frames, pFile);
  91.    printf("%zu bytes written to file\n", countWritten * frameSize);

  92.    fclose(pFile);

  93. Error:
  94.    if (res != MIRA_OK) {
  95.        printf("Error %d: %s", miraacq_GetErrorCode(pma), miraacq_GetErrorMsg(pma));
  96.    }

  97.    miraacq_Release(pma);

  98.    if (pBuf != NULLfree(pBuf);

  99.    return 0;
  100. }