123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Diagnostics;
- using Iisu;
- namespace bbiwarg.Input.InputProviding
- {
-
-
-
-
-
- public delegate void DeviceStartedEventHandler(object sender, EventArgs e);
-
-
-
-
-
- public delegate void NewFrameEventHandler(object sender, NewFrameEventArgs e);
-
-
-
- public class NewFrameEventArgs : EventArgs
- {
-
-
-
- public int FrameID { get; private set; }
-
-
-
- public int Width { get; private set; }
-
-
-
- public int Height { get; private set; }
-
-
-
- public IntPtr RawDepthData { get; private set; }
-
-
-
- public IntPtr RawConfidenceData { get; private set; }
-
-
-
-
-
-
-
-
- public NewFrameEventArgs(int frameID, int width, int height, IntPtr rawDepthData, IntPtr rawConfidenceData)
- {
- FrameID = frameID;
- Width = width;
- Height = height;
- RawDepthData = rawDepthData;
- RawConfidenceData = rawConfidenceData;
- }
- }
-
-
-
- public class InputProvider
- {
-
-
-
- protected IHandle handle;
-
-
-
- protected IDevice device;
-
-
-
- protected IParameterHandle<float> frameRate;
-
-
-
- protected IParameterHandle<int> width;
-
-
-
- protected IParameterHandle<int> height;
-
-
-
- protected IParameterHandle<float> hfov;
-
-
-
- protected IParameterHandle<float> vfov;
-
-
-
- protected IDataHandle<Iisu.Data.IImageData> depthImage;
-
-
-
- protected IDataHandle<Iisu.Data.IImageData> confidenceImage;
-
-
-
- public int ImageWidth { get { return width.Value; } }
-
-
-
- public int ImageHeight { get { return height.Value; } }
-
-
-
- public float HFOV { get { return hfov.Value; } }
-
-
-
- public float VFOV { get { return vfov.Value; } }
-
-
-
- public bool IsActive { get; private set; }
-
-
-
- public virtual int CurrentFrameID { get { return device.FrameId; } }
-
-
-
- public event DeviceStartedEventHandler DeviceStartedEvent;
-
-
-
- public event NewFrameEventHandler NewFrameEvent;
-
-
-
- public InputProvider()
- {
- IsActive = false;
- }
-
-
-
- public void initialize()
- {
- createDevice();
- registerHandles();
- }
-
-
-
- public void start()
- {
- device.Start();
- IsActive = true;
- if (DeviceStartedEvent != null)
- DeviceStartedEvent(this, new EventArgs());
- run();
- }
-
-
-
- public void stop()
- {
- IsActive = false;
- device.Stop(true);
- }
-
-
-
- protected void createDevice()
- {
- handle = Iisu.Iisu.Context.CreateHandle();
- IDeviceConfiguration conf = createDeviceConfiguration();
- device = handle.InitializeDevice(conf);
- }
-
-
-
-
- protected virtual IDeviceConfiguration createDeviceConfiguration()
- {
- IDeviceConfiguration conf = handle.CreateDeviceConfiguration();
- conf.IsAsynchronous = false;
- return conf;
- }
-
-
-
- protected virtual void registerHandles()
- {
- width = device.RegisterParameterHandle<int>("SOURCE.CAMERA.DEPTH.Width");
- height = device.RegisterParameterHandle<int>("SOURCE.CAMERA.DEPTH.Height");
- hfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.HFOV");
- vfov = device.RegisterParameterHandle<float>("SOURCE.CAMERA.DEPTH.VFOV");
- frameRate = device.RegisterParameterHandle<float>("SOURCE.FrameRate");
- depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
- confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
- }
-
-
-
- protected virtual void run()
- {
- while (IsActive)
- nextFrame();
- }
-
-
-
- protected virtual void nextFrame()
- {
- device.UpdateFrame(true);
- provideNewFrame();
- device.ReleaseFrame();
- }
-
-
-
- protected void provideNewFrame()
- {
- if (NewFrameEvent != null)
- NewFrameEvent(this, new NewFrameEventArgs(CurrentFrameID, ImageWidth, ImageHeight, depthImage.Value.Raw, confidenceImage.Value.Raw));
- }
- }
- }
|