예제 #1
0
        private async void ProcessImage(SoftwareBitmap SourceBitmap)
        {
            SoftwareBitmap RotatedSourceBitmap = new SoftwareBitmap(BitmapPixelFormat.Bgra8, SourceBitmap.PixelHeight, SourceBitmap.PixelWidth, BitmapAlphaMode.Premultiplied);

            _cvhelper.RotateImage(SourceBitmap, RotatedSourceBitmap, 90);

            int PanelWidth  = (int)Math.Abs(EndPoint.X - StartPoint.X);
            int PanelHeight = (int)Math.Abs(EndPoint.Y - StartPoint.Y);

            SoftwareBitmap CroppedBitmap = new SoftwareBitmap(BitmapPixelFormat.Bgra8, (int)PanelImageSize.Width, (int)PanelImageSize.Height, BitmapAlphaMode.Premultiplied);

            _cvhelper.CropImage(StartPoint, EndPoint, RotatedSourceBitmap, CroppedBitmap);
            BrightnessCalc.CalcBrightness(CroppedBitmap);

            SoftwareBitmap MaskedBitmap = new SoftwareBitmap(BitmapPixelFormat.Bgra8, (int)PanelImageSize.Width, (int)PanelImageSize.Height, BitmapAlphaMode.Premultiplied);

            _cvhelper.MaskAndDrawPanelArea(CroppedBitmap, MaskedBitmap);

            using (var ImgResult = PanelParser.ParsePanelImage(MaskedBitmap))
            {
                var FilterImg = ImgResult?.SelectResult(FilterSelectedBeadType);
                if (FilterImg != null)
                {
                    _ColorFilterRenderer.RenderFrame(SoftwareBitmap.Copy(FilterImg));
                }
            }

            _SourceRenderer.RenderFrame(RotatedSourceBitmap);
            _ClippedRenderer.RenderFrame(CroppedBitmap);

            await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                LightThresTextbox.Text = "Thres:" + (BrightnessCalc.Threshold?.ToString("0.00") ?? String.Empty);
                LightValueTextbox.Text = "Value:" + (BrightnessCalc.Latest?.ToString("0.00") ?? String.Empty);
                AnalyzedTextBlock.Text = PanelParser.GetParsedPanel().ToString() ?? String.Empty;
            });
        }
예제 #2
0
        public static IAsyncAction RenderFrameAsync_out(FrameRenderer frameRenderer, VideoFrame inputVideoFrame)
        {
            return(AsyncInfo.Run(async(token) =>
            {
                bool useDX = inputVideoFrame.SoftwareBitmap == null;
                if (frameRenderer == null)
                {
                    throw (new InvalidOperationException("FrameRenderer is null"));
                }

                SoftwareBitmap softwareBitmap = null;
                if (useDX)
                {
                    softwareBitmap = await SoftwareBitmap.CreateCopyFromSurfaceAsync(inputVideoFrame.Direct3DSurface);
                    softwareBitmap = SoftwareBitmap.Convert(softwareBitmap, BitmapPixelFormat.Bgra8, BitmapAlphaMode.Premultiplied);
                }
                else
                {
                    softwareBitmap = inputVideoFrame.SoftwareBitmap;

                    int a = 1;

                    if (a == 1)
                    {
                        using (BitmapBuffer buffer = softwareBitmap.LockBuffer(BitmapBufferAccessMode.Write))
                        {
                            using (var reference = buffer.CreateReference())
                            {
                                unsafe
                                {
                                    byte *dataInBytes;
                                    uint capacity;

                                    ((IMemoryBufferByteAccess)reference).GetBuffer(out dataInBytes, out capacity);

                                    // Fill-in the BGRA plane
                                    BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0);
                                    // In BGRA8 format, each pixel is defined by 4 bytes
                                    const int BYTES_PER_PIXEL = 4;

                                    for (int i = 0; i < bufferLayout.Height; i++)
                                    {
                                        for (int j = 0; j < bufferLayout.Width; j++)
                                        {
                                            var currPixel = bufferLayout.StartIndex + bufferLayout.Stride * i + BYTES_PER_PIXEL * j;
                                            // Read the current pixel information into b,g,r channels (leave out alpha channel)
                                            var b = dataInBytes[currPixel + 0]; // Blue
                                            var g = dataInBytes[currPixel + 1]; // Green
                                            var r = dataInBytes[currPixel + 2]; // Red
                                                                                // Boost the green channel, leave the other two untouched
                                            dataInBytes[currPixel + 0] = r;
                                            dataInBytes[currPixel + 1] = g;
                                            dataInBytes[currPixel + 2] = b;
                                        }
                                    }
                                }
                            }
                        }
                    }



                    // Scale image to appropriate size
                    //BitmapTransform transform = new BitmapTransform()
                    //{
                    //    ScaledWidth = Convert.ToUInt32(WriteableBitmap.PixelWidthProperty),
                    //    ScaledHeight = Convert.ToUInt32(WriteableBitmap.PixelHeightProperty)
                    //};
                    //softwareBitmap = new SoftwareBitmap(
                    //    BitmapPixelFormat.Bgra8,
                    //    inputVideoFrame.SoftwareBitmap.PixelWidth,
                    //    inputVideoFrame.SoftwareBitmap.PixelHeight,
                    //    inputVideoFrame.SoftwareBitmap.BitmapAlphaMode);
                    //inputVideoFrame.SoftwareBitmap.CopyTo(softwareBitmap);
                }

                frameRenderer.RenderFrame(softwareBitmap);
            }));
        }