HomeSupportAPIsXiAPINET → NET Sample code

NET Sample code

Look up table (LUT) example


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Drawing;
using xiApi.NET;
namespace xiApi.NET_example
{
class Program
{
  static void Main(string[] args)
  {
    xiCam myCam = new xiCam();

    try
    {
      // Initialize first camera
      myCam.OpenDevice(0);

      // Set device exposure to 2 milliseconds
      int exposure_us = 2000;
      myCam.SetParam(PRM.EXPOSURE, exposure_us);

      // Set device gain to 5 decibels
      float gain_db = 5;
      myCam.SetParam(PRM.GAIN, gain_db);

      // Set image output format to monochrome 8 bit
      myCam.SetParam(PRM.IMAGE_DATA_FORMAT, IMG_FORMAT.MONO8);

      // Setting LUT parameters - inverse example, 
      // which inverts pixel values (min -> max, max -> min).
      int maxIndex, minIndex;
      int maxValue, minValue;
      maxIndex = myCam.GetParamInt(PRM.LUT_INDEX_MAX);
      minIndex = myCam.GetParamInt(PRM.LUT_INDEX_MIN);
      maxValue = myCam.GetParamInt(PRM.LUT_VALUE_MAX);
      minValue = myCam.GetParamInt(PRM.LUT_VALUE_MIN);

      Console.WriteLine("max index {0} \n", maxIndex);
      Console.WriteLine("max value {0} \n", maxValue);

      for (int i = 0; i < maxIndex; i++)
      {
          myCam.SetParam(PRM.LUT_INDEX, i);
          myCam.SetParam(PRM.LUT_VALUE, maxValue - i);

      }

      myCam.SetParam(PRM.LUT_EN, 1);

      //Start acquisition
      myCam.StartAcquisition();

      // Capture images
      Bitmap myImage;
      int timeout = 1000;
      for (int i = 0; i < 10; i++)
      {
        myCam.GetImage(out myImage, timeout );
        string fName = string.Format("image{0}.bmp", i);
        myImage.Save(fName);
      }
      // Stop acquisition
      myCam.StopAcquisition();
    }

    catch (System.ApplicationException appExc)
    {
      // Show handled error
      Console.WriteLine(appExc.Message);
      System.Console.ReadLine();
      myCam.CloseDevice();
    }

    finally
    {
      myCam.CloseDevice();
    }
  }
} // end of Program
} // end of namespace xiApi.NET_example