Package: nile
nilenileAboutInstallationSamplesBasic UsageAdvanced usageContributingAboutnileis a library that aims to simplify building applications that leverage real time data collected from one or more sensors or media devices.nilesimplifies this process by implementing the boiler plate code that orchestrates configurations composed of these key abstractions:Device abstraction that yields dataFunctional layer to transform dataProcessing layer that applies logic to transformation outputnilewill handle all device orchestration including wiring up the correct device, transformer and processing layers, managing device lifecycle and cleaning up unused resources.Installationnilecurrently supports Python versions3.4,3.5,3.6and3.7. It can be installed by runningpip install nile.SamplesA dockerized sample is included with this repository. In this samplenileorchestrates streaming from multiple webcam devices pipes the feeds to a camera-specific set of consumers which print output in a table format tostdout. More specifically, the following configurations are used:Intersection WebcamFrames converted to grayscaleOutput piped to ML model that counts vehicalsOutput piped to brightness detectionCollege Campus WebcamFrames converted to grayscaleOutput piped to brightness detectionThe sample can be run locally by running the following commands:# clone the repogitclonehttps://github.com/microsoft/nile.git# enter the nile directorycdnile/# ensure Docker is runningdocker--version# build the projectdockerbuild.-tnile# run the samplesdockerrunnileBasic UsageIn order to usenileyou must implement three abstractions (documentation here):Device: Represents a data stream adapter to a physical media device. For example you may build separate devices to stream audio from microphone and HTTP endpoints.Transformer: Transform source data. For example, you may transform an MPEG audio stream into PCM/WAV format.Consumer: Represents a consumer of the transformed device data. There may be many of these per device. For example, in an audio-streaming application you may build separate consumers to (1) analyze audio wave frequencies, (2) analyze audio wave amplitudes and (3) archive audio onto a cloud-provided storage endpoint.The samples directory contains real-world implementations that target live webcam video analysis.Examples can be found here.Once you have these you can orchestrate them usingnile:fromtimeimportsleepfromnile.controllersimportDeviceController,DeviceFleetManager# import your implementations here...# the controller manages the configuration for a single devicedevice_controller=DeviceController(YourCustomDevice(),YourCustomTransformer(),(YourCustomDeviceConsumer(),),throttle_time_ms=-1# a positive value specifies the polling delay on the device)# the fleet manager handles configurations for multiple devicesfleet_manager=DeviceFleetManager()fleet_manager.set_controllers({device_controller})# process for 20 secondssleep(20)# this closes all devices under management and cleans any resources for those devicesfleet_controller.shutdown()Advanced usagenilesupports non-trivial configurations as well and can update in real-time to configuration updates. Here is a more complex orchestration that leverages these features. The source code for the providers can be foundhere:# example runs brigtness detection on video frames for 20 seconds, and then adds a car count consumer# to one of the video feeds.fromtimeimportsleepfromnile.controllersimportDeviceController,DeviceFleetManagerfromprovidersimportBrightnessMeasureConsumer,CarCounterConsumer,FrameToGrayscaleTransformer,HttpVideoCaptureDevice# ML model to count carscar_count_consumer=CarCounterConsumer()# Measure avg. brightnessbrightness_measure_consumer=BrightnessMeasureConsumer()# Convert img to grayscaleimage_converter=FrameToGrayscaleTransformer()road_cam=HttpVideoCaptureDevice('Tennasee Road','http://traf3.murfreesborotn.gov/axis-cgi/mjpg/video.cgi')campus_cam=HttpVideoCaptureDevice('Bowdoin Campus','http://webcam1.bowdoin.edu:4200/axis-cgi/mjpg/video.cgi')fleet_controller=DeviceFleetManager()# start with both feeds running through brightness measuringfleet_controller.set_controllers({DeviceController(device=road_cam,transformer=image_converter,consumers=(brightness_measure_consumer,),throttle_time_ms=-1),DeviceController(device=campus_cam,transformer=image_converter,consumers=(brightness_measure_consumer,),throttle_time_ms=-1)})# process for 20 secondssleep(20)# add car count detection on road camfleet_controller.set_controllers({DeviceController(device=road_cam,transformer=image_converter,consumers=(brightness_measure_consumer,car_count_consumer),throttle_time_ms=-1),DeviceController(device=campus_cam,transformer=image_converter,consumers=(brightness_measure_consumer,),throttle_time_ms=-1)})# process for 20 secondssleep(20)# close devices and clean up all resourcesfleet_controller.shutdown()ContributingThis project welcomes contributions and suggestions.  Most contributions require you to agree to a
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
the rights to use your contribution. For details, visithttps://cla.microsoft.com.When you submit a pull request, a CLA-bot will automatically determine whether you need to provide
a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions
provided by the bot. You will only need to do this once across all repos using our CLA.This project has adopted themicrosoft Open Source Code of Conduct.
For more information see theCode of Conduct FAQor
contactopencode@microsoft.comwith any additional questions or comments.For additional guidance, refer to the project-specificcontributing guidelinesas well as thepull request template