This example shows how to adjust exposure settings using the PST SDK. It shows how to change exposure settings based on frame rate and the available exposure range for a certain PST Tracker at a certain frame rate.
When compiling and running this example, please make sure that the required dependencies can be found by the executable (e.g. by copying the Redist
directory into the build directory. When the PST SDK has been installed through the PST Software Suite installer the Redist folder can be found in the Development folder.).
using System;
using System.Runtime.InteropServices;
using System.Threading;
namespace PsTech.Exposure
{
public class Exposure
{
[DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(ConsoleEventHandler handler, bool add);
private delegate bool ConsoleEventHandler(CtrlType sig);
static ConsoleEventHandler ConsoleCtrlEventHandler;
public enum CtrlType
{
CtrlCEvent = 0,
CtrlBreakEvent = 1,
CtrlCloseEvent = 2,
CtrlLogOffEvent = 5,
CtrlShutdownEvent = 6,
}
private static bool ConsoleHandler(CtrlType sig)
{
Exithandler((int)sig);
return true;
}
static bool Running = true;
static int NumberOfSamplesToGrab = 1000;
static int SamplesGrabbed = 0;
class MyTrackerListener : TrackerListener
{
public override void OnTrackerData(TrackerData data,
ErrorStatus status)
{
if (SamplesGrabbed++ >= NumberOfSamplesToGrab)
{
Running = false;
}
}
}
static void Exithandler(int sig)
{
Tracker.Shutdown();
Running = false;
}
static int Main(string[] args)
{
ConsoleCtrlEventHandler += new ConsoleEventHandler(ConsoleHandler);
SetConsoleCtrlHandler(ConsoleCtrlEventHandler, true);
try
{
Tracker tracker = new Tracker();
Console.Write("Running PST Server version " + tracker.GetVersionInfo() + "\n");
TrackerListener listener = new MyTrackerListener();
tracker.AddTrackerListener(ref listener);
tracker.StartTracker();
Console.Write("System check: " + tracker.Systemcheck() + "\n\n");
Console.Write("***************************\n\n");
tracker.SetFramerate(30);
Console.Write("Frame rate set to " + tracker.GetFramerate() + " Hz\n");
double min = 0.0, max = 0.0;
tracker.GetExposureRange(ref min, ref max);
Console.Write("Exposure range: " + min + " s - " + max + " s\n");
Console.Write("Set exposure to " + max + "\n");
tracker.SetExposure(max);
Console.Write("Check new exposure: " + tracker.GetExposure() + " s\n\n");
Console.Write("***************************\n\n");
Console.Write("Set frame rate to 60 Hz\n");
tracker.SetFramerate(60);
Console.Write("Frame rate set to " + tracker.GetFramerate() + " Hz\n");
Console.Write("Check exposure: " + tracker.GetExposure() + " s\n");
tracker.GetExposureRange(ref min, ref max);
Console.Write("New exposure range " + min + " s - " + max + " s\n\n");
Console.Write("***************************\n\n");
double exposureHalf = min + (max - min) / 2.0;
Console.Write("Set exposure half way: " + exposureHalf + " s\n");
tracker.SetExposure(exposureHalf);
Console.Write("New exposure: " + tracker.GetExposure() + " s\n\n");
Console.Write("***************************\n\n");
while (Running)
{
Thread.Sleep(100);
}
}
{
Console.Write(e + "\n");
}
finally
{
Tracker.Shutdown();
}
Console.Write("Press enter to continue...\n");
Console.Read();
return 0;
}
}
}