Page 19 - MSDN Magazine, June 2017
P. 19

Then, at each iteration, I convert a given pixel to the gray scale by averaging values from each color channel:
private static byte GetGrayscaleValue(byte[] pixelBuffer, uint startIndex) {
var grayValue = (pixelBuffer[startIndex] + pixelBuffer[startIndex + 1]
+ pixelBuffer[startIndex + 2]) / 3.0;
return Convert.ToByte(grayValue);
When you provision the remote monitoring solution, the Azure IoT Suite portal creates several Azure resources: IoT Hub, Stream Analytics jobs, Storage and the App Service.
Brightness is passed to the view through the ProcessingDone event. This event is handled in the MainPage class (MainPage.xaml.cs), where I display brightness in the label and a progress bar. Both controls are bounded to the Brightness property of the RemoteCameraView- Model. Note that ProcessingDone is raised from the background thread. Hence, I modify the RemoteCameraViewModel.Brightness through the UI thread using Dispatcher class, as shown in Figure 7.
Figure 6 Calculating the Mean Value of the Pixels
Provisioning the Remote Monitoring Solution
To provision a solution you can use a dedicated portal at azureiotsuite.com. After logging in and choosing your Azure subscription, you’ll be redirected to a page where you press the “Create a new solution” rectangle. This will open a Web site where you can choose one of two preconfigured solutions: predictive maintenance or remote monitoring (see Figure 8). After choosing the solution another form appears, which lets you set the solution name and region for Azure resources. Here, I set the solution name and region to RemoteCameraMonitoring and West US, respectively.
When you provision the remote monitoring solution, the Azure IoT Suite portal creates several Azure resources: IoT Hub, Stream Analytics jobs, Storage and the App Service. The IoT Hub pro- vides bidirectional communication between the cloud and remote devices. Data streamed by remote devices is transformed by a Stream Analytics job, which typically filters out unnecessary data. Filtered data is stored or directed for further analysis. Finally, the App Service is used to host the Web portal.
Solution provisioning can also be done from the command line. To do so, you can clone or download the solution source code from bit.ly/2osI4RW, and then follow the instruction at bit.ly/2p7MPPc. You also have the option to deploy a solution locally, as shown at
Figure 8 Azure IoT Suite Preconfigured Solutions (Top) and Remote Monitoring Solution Configuration (Bottom)
}
private byte CalculateMeanGrayValue(byte[] pixelBuffer) {
// Loop index increases by four since
// there are four channels (blue, green, red and alpha). // Alpha is ignored for brightness calculation
const int step = 4;
double mean = 0.0;
for (uint i = 0; i < pixelBuffer.Length; i += step) {
mean += GetGrayscaleValue(pixelBuffer, i); }
mean /= (pixelBuffer.Length / step);
return Convert.ToByte(mean); }
Figure 7 Modifying the RemoteCameraViewModel.Brightness Through the UI Thread Using the Dispatcher Class
private async void DisplayBrightness(byte brightness) {
if (Dispatcher.HasThreadAccess) {
remoteCameraViewModel.Brightness = brightness; }
else {
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => {
DisplayBrightness(brightness); });
} }
msdnmagazine.com
June 2017 15


































































   17   18   19   20   21