Esempio n. 1
0
        private void PerformDraw(PlayingInfo playingInfo)
        {
            byte imageSize = 2;
            byte textSize  = 3;
            var  result    = new List <LayoutDrawElement>();

            if (playingInfo.IsPlaying != _isPlaying)
            {
                _isPlaying = playingInfo.IsPlaying;
                _playPauseButton.ReplaceText(_isPlaying.Value?FontAwesomeRes.fa_pause:FontAwesomeRes.fa_play);
            }

            if (_previousRepresentation != playingInfo?.BitmapRepresentation)
            {
                _previousRepresentation = playingInfo?.BitmapRepresentation;

                using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * imageSize, LayoutContext.IconSize.Height * imageSize))
                {
                    bitmap.MakeTransparent();
                    if (playingInfo?.BitmapRepresentation != null)
                    {
                        using (BitmapEx coverBitmap = playingInfo.BitmapRepresentation.CreateBitmap())
                        {
                            BitmapHelpers.ResizeBitmap(coverBitmap, bitmap);
                        }
                    }

                    result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(imageSize, imageSize), 0, 0, LayoutContext));
                }
            }

            using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height))
            {
                var lineWidth = 0.05;

                bitmap.MakeTransparent();
                var title = playingInfo?.Title;
                DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, title, LayoutContext.Options.Theme.ForegroundColor);

                if (playingInfo != null)
                {
                    using (var graphics = bitmap.CreateGraphics())
                        using (var brush = new SolidBrush(GlobalContext.Options.Theme.ForegroundColor))
                        {
                            var rect = new Rectangle(0, (int)(bitmap.Height * (1 - lineWidth)), (int)(bitmap.Width * playingInfo.CurrentPosition.TotalMilliseconds / playingInfo.DurationSpan.TotalMilliseconds), (int)(bitmap.Height * lineWidth));
                            graphics.FillRectangle(brush, rect);
                        }
                }

                result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 0, LayoutContext));
            }

            using (var bitmap = new BitmapEx(LayoutContext.IconSize.Width * textSize, LayoutContext.IconSize.Height))
            {
                bitmap.MakeTransparent();
                var artist = playingInfo?.Artist ?? string.Empty;
                var album  = playingInfo?.Album ?? string.Empty;
                var text   = $"{artist}\n{album}";
                DefaultDrawingAlgs.DrawText(bitmap, GlobalContext.Options.Theme.FontFamily, text, GlobalContext.Options.Theme.ForegroundColor);
                result.AddRange(BitmapHelpers.ExtractLayoutDrawElements(bitmap, new DeviceSize(textSize, 1), imageSize, 1, LayoutContext));
            }

            DrawInvoke(result);
        }
Esempio n. 2
0
        public override async Task <(SKBitmap, FilteringStatsModel)> Run(SKBitmap raw)
        {
            var filtered        = (SKBitmap)null;
            var stats           = (FilteringStatsModel)null;
            var runnerException = (Exception)null;

            var runConfig = this.PrepareConfig();

            var runResult = (RunResultDto)null;

            var serverPipe = new ServerPipe("testpipe", x => x.StartObjectReaderAsync());

            serverPipe.Connected += async(sndr, args) =>
            {
                try
                {
                    serverPipe.Flush();
                    await serverPipe.WriteObject(runConfig);

                    serverPipe.Flush();
                }
                catch (Exception exception)
                {
                    runnerException = exception;
                }
            };
            serverPipe.DataReceived += (sndr, args) =>
            {
                if (args.Error == null)
                {
                    runResult = (RunResultDto)args.ObjectData;
                }
                else
                {
                    runnerException = args.Error;
                }
            };

            this.runnerProcess = Process.Start(new ProcessStartInfo
            {
#if Linux
                FileName = "dotnet",
#if DEBUG
                Arguments = Path.Combine("bin", "Debug", "net5.0", "NLMRunner.dll"),
#else
                Arguments = "NLMRunner.dll",
#endif
                ErrorDialog = true,
#elif Windows
                FileName = "NLMRunner.exe",
#endif
            });

            await this.runnerProcess.WaitForExitAsync();

            if (runResult != null)
            {
                if (runResult.Exception != null)
                {
                    runnerException = runResult.Exception;
                }
                else
                {
                    using (var filteredFile = new MemoryStream(runResult.OutputFile))
                    {
                        filtered = SKBitmap.Decode(filteredFile);
                    }

                    stats = BitmapHelpers.CalculateStats(raw, filtered, runResult.Time);
                }
            }
            else if (!this.cancelled)
            {
                runnerException = new ApplicationException("Wystąpił niemożliwy do obsłużenia błąd krytyczny.");
            }

            if (runnerException != null)
            {
                throw runnerException;
            }

            if (filtered == null || stats == null)
            {
                throw new ApplicationException("Proces zakończył się bez rezultatu.");
            }

            return(filtered, stats);
        }
Esempio n. 3
0
        //handle input of photos, either from gallery or camera
        protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
        {
            base.OnActivityResult(requestCode, resultCode, data);
            string    path = "";
            Bitmap    pic;
            ImageView iv = null;

            if (imageViewRow != null)
            {
                iv = (ImageView)imageViewRow.FindViewWithTag("image");
            }

            //user cancelled
            if (resultCode == Result.Canceled && requestCode != REQUEST_DRAWING)
            {
                File.Delete(photoFile.Path);
                return;
            }
            //camera
            if (requestCode == REQUEST_IMAGE_CAPTURE)
            {
                //

                GalleryAddPic();


                if (this is DrawingActivity)
                {
                    SetPic(DrawingActivity.BackgroundImage, photoUri);
                }
                else
                {
                    SetPic(iv, photoUri);
                }

                path = mCurrentPhotoPath;
            }

            //gallery
            else if (requestCode == REQUEST_GALLERY_IMAGE)
            {
                pic = MediaStore.Images.Media.GetBitmap(ContentResolver, data.Data);
                using (var os = new FileStream(mCurrentPhotoPath, FileMode.Create))
                {
                    pic.Compress(Bitmap.CompressFormat.Jpeg, 100, os);
                }

                path = mCurrentPhotoPath;

                if (this is DrawingActivity)
                {
                    SetPic(DrawingActivity.BackgroundImage, data.Data);
                }
                else
                {
                    SetPic(iv, data.Data);
                }


                //iv.SetImageBitmap(imageBitmap);
            }
            //this only has a value when coming directly from the camera/gallery
            if (bindingForImage != null)
            {
                XForm.SetValue(bindingForImage.nodeset, path);
            }

            //coming back from a canvas
            if (requestCode == REQUEST_DRAWING && data != null)
            {
                iv = (ImageView)WidgetHelper.viewToPass.FindViewWithTag("image");
                iv.SetImageBitmap(BitmapHelpers.LoadAndResizeBitmap(data.Data.Path, 100, 100, this));
                //iv.SetImageBitmap(Bitmap.CreateScaledBitmap(BitmapFactory.DecodeFile(data.Data.Path), 100, 100, true));
            }

            if (this is ScrollFormActivity)
            {
                try
                {
                    _formActivity.FireFormChangeEvent(imageViewRow);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }

                if (showDialogAfterImageSelect)
                {
                    iv.PerformClick();
                }
            }
        }
        private void DisplayThumbnail()
        {
            var thumbnail = BitmapHelpers.CreateThumbnail(_file.Path, 450, 450);

            _app.ShowPicture(thumbnail);
        }
 private void AddFileInfo(FileInfo fi)
 {
     FullName = fi.FullName;
     Name     = fi.Name;
     Image    = BitmapHelpers.GetFileIcon(fi.FullName, 16, 16);
 }
Esempio n. 6
0
        private void ProccesFrame(object sender, EventArgs e)
        {
            videoCapture.Retrieve(frame, 0);
            if (!picCapture.CheckAccess())
            {
                picCapture.Dispatcher.Invoke(new Action(delegate()
                {
                    currentFrame = frame.ToImage <Bgr, Byte>().Resize(Convert.ToInt32(picCapture.Width), Convert.ToInt32(picCapture.Height), Inter.Cubic);
                }));
            }
            else
            {
                currentFrame = frame.ToImage <Bgr, Byte>().Resize(Convert.ToInt32(picCapture.Width), Convert.ToInt32(picCapture.Height), Inter.Cubic);
            }

            //detect faces
            if (!picCapture.CheckAccess())
            {
                picCapture.Dispatcher.Invoke(new Action(delegate()
                {
                    if (faceDetectionEnabled)
                    {
                        //Convert from Bgr to Gray Image
                        Mat grayImage = new Mat();
                        CvInvoke.CvtColor(currentFrame, grayImage, ColorConversion.Bgr2Gray);
                        //Enchance the image to get better result
                        CvInvoke.EqualizeHist(grayImage, grayImage);

                        System.Drawing.Rectangle[] faces = faceCascadeClassifier.DetectMultiScale(grayImage, 1.1, 3, System.Drawing.Size.Empty, System.Drawing.Size.Empty);

                        if (faces.Length > 0)
                        {
                            foreach (var face in faces)
                            {
                                CvInvoke.Rectangle(currentFrame, face, new Bgr(System.Drawing.Color.Red).MCvScalar, 2);

                                Image <Bgr, Byte> resultImage = currentFrame.Convert <Bgr, Byte>();
                                resultImage.ROI = face;

                                if (faceRecognationEnabled)
                                {
                                    Image <Gray, Byte> grayFaceResult = resultImage.Convert <Gray, Byte>().Resize(200, 200, Inter.Cubic);
                                    CvInvoke.EqualizeHist(grayFaceResult, grayFaceResult);
                                    var result = recognizer.Predict(grayFaceResult);

                                    //Debug.WriteLine(result.Label + ". " + result.Distance);
                                    //Here results found known faces
                                    if (result.Label != -1 && result.Distance < 2000)
                                    {
                                        CvInvoke.PutText(currentFrame, PersonsNames[result.Label], new System.Drawing.Point(face.X - 2, face.Y - 2),
                                                         FontFace.HersheyComplex, 1.0, new Bgr(System.Drawing.Color.Orange).MCvScalar);
                                        CvInvoke.Rectangle(currentFrame, face, new Bgr(System.Drawing.Color.Green).MCvScalar, 2);
                                    }
                                    //here results did not found any know faces
                                    else
                                    {
                                        CvInvoke.PutText(currentFrame, "Unknown", new System.Drawing.Point(face.X - 2, face.Y - 2),
                                                         FontFace.HersheyComplex, 1.0, new Bgr(System.Drawing.Color.Orange).MCvScalar);
                                        CvInvoke.Rectangle(currentFrame, face, new Bgr(System.Drawing.Color.Red).MCvScalar, 2);
                                    }
                                }
                            }
                        }
                    }
                }));
            }


            else
            {
                if (faceDetectionEnabled)
                {
                    //Convert from Bgr to Gray Image
                    Mat grayImage = new Mat();
                    CvInvoke.CvtColor(currentFrame, grayImage, ColorConversion.Bgr2Gray);
                    //Enchance the image to get better result
                    CvInvoke.EqualizeHist(grayImage, grayImage);

                    System.Drawing.Rectangle[] faces = faceCascadeClassifier.DetectMultiScale(grayImage, 1.1, 3, System.Drawing.Size.Empty, System.Drawing.Size.Empty);

                    if (faces.Length > 0)
                    {
                        foreach (var face in faces)
                        {
                            CvInvoke.Rectangle(currentFrame, face, new Bgr(System.Drawing.Color.Red).MCvScalar, 2);

                            Image <Bgr, Byte> resultImage = currentFrame.Convert <Bgr, Byte>();
                            resultImage.ROI = face;


                            if (faceRecognationEnabled)
                            {
                                Image <Gray, Byte> grayFaceResult = resultImage.Convert <Gray, Byte>().Resize(200, 200, Inter.Cubic);
                                CvInvoke.EqualizeHist(grayFaceResult, grayFaceResult);
                                var result = recognizer.Predict(grayFaceResult);

                                Debug.WriteLine(result.Label + ". " + result.Distance);
                                //Here results found known faces
                                if (result.Label != -1 && result.Distance < 2000)
                                {
                                    CvInvoke.PutText(currentFrame, PersonsNames[result.Label], new System.Drawing.Point(face.X - 2, face.Y - 2),
                                                     FontFace.HersheyComplex, 1.0, new Bgr(System.Drawing.Color.Orange).MCvScalar);
                                    CvInvoke.Rectangle(currentFrame, face, new Bgr(System.Drawing.Color.Green).MCvScalar, 2);
                                }
                                //here results did not found any know faces
                                else
                                {
                                    CvInvoke.PutText(currentFrame, "Unknown", new System.Drawing.Point(face.X - 2, face.Y - 2),
                                                     FontFace.HersheyComplex, 1.0, new Bgr(System.Drawing.Color.Orange).MCvScalar);
                                    CvInvoke.Rectangle(currentFrame, face, new Bgr(System.Drawing.Color.Red).MCvScalar, 2);
                                }
                            }
                        }
                    }
                }
            }



            //Render the video capture into Picture Box picCapture

            if (!picCapture.CheckAccess())
            {
                picCapture.Dispatcher.Invoke(new Action(delegate()
                {
                    picCapture.Source = BitmapHelpers.ToBitmapSource(currentFrame);
                }));
            }
            else
            {
                picCapture.Source = BitmapHelpers.ToBitmapSource(currentFrame);
            }
        }