1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Iisu;
- namespace bbiwarg.InputProviders
- {
- class InputProvider
- {
- public int ImageWidth { get; private set; }
- public int ImageHeight { get; private set; }
- public virtual int CurrentFrameID { get { return device.FrameId; } }
- public InputFrame CurrentFrame { get; private set; }
- protected IHandle handle;
- protected IDevice device;
- protected IDataHandle<Iisu.Data.IImageData> depthImage;
- protected IDataHandle<Iisu.Data.IImageData> confidenceImage;
- public void start()
- {
- createDevice();
- registerHandles();
- device.Start();
- }
- public void stop()
- {
- device.Stop(true);
- }
- protected void createDevice()
- {
- handle = Iisu.Iisu.Context.CreateHandle();
- IDeviceConfiguration conf = createDeviceConfiguration();
- device = handle.InitializeDevice(conf);
- }
- protected virtual IDeviceConfiguration createDeviceConfiguration()
- {
- return handle.CreateDeviceConfiguration();
- }
- protected virtual void registerHandles()
- {
- ImageWidth = device.RegisterParameterHandle<int>("SOURCE.CAMERA.DEPTH.Width").Value;
- ImageHeight = device.RegisterParameterHandle<int>("SOURCE.CAMERA.DEPTH.Height").Value;
- depthImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.DEPTH.Image");
- confidenceImage = device.RegisterDataHandle<Iisu.Data.IImageData>("SOURCE.CAMERA.CONFIDENCE.Image");
- device.EventManager.RegisterEventListener("DEVICE.DataFrame", new onNewFrameDelegate(onNewFrame));
- }
- private delegate void onNewFrameDelegate(String name, uint frameID);
- private void onNewFrame(String name, uint frameID)
- {
- device.UpdateFrame(false);
- IntPtr rawDepthData = depthImage.Value.Raw;
- IntPtr rawConfidenceData = confidenceImage.Value.Raw;
- device.ReleaseFrame();
- CurrentFrame = new InputFrame(CurrentFrameID, ImageWidth, ImageHeight, rawDepthData, rawConfidenceData);
- }
- }
- }
|