public byte[] ResizePhoto(Stream photoStream)
        {
            var      bitmap = SKBitmap.Decode(photoStream);
            SKImage  image;
            SKBitmap newBitmap = null;
            int      maxMpix   = 12 * 1000 * 1000;

            RtbLog.AppendText($"Image size: {bitmap.Width}x{bitmap.Height}\n");
            if ((bitmap.Width * bitmap.Height) >= maxMpix - 1) // more than 12 MP
            {
                newBitmap = bitmap.Resize(ResizeUntilMPixels(bitmap.Info, maxMpix), SKFilterQuality.High);
                image     = SKImage.FromBitmap(newBitmap);
                RtbLog.AppendText($"Image resized: {newBitmap.Width}x{newBitmap.Height}\n");
            }
            else
            {
                image = SKImage.FromBitmap(bitmap);
            }

            using (var data = image.Encode(SKEncodedImageFormat.Jpeg, 90))
            {
                var array = data.ToArray();
                bitmap.Dispose();
                newBitmap?.Dispose();
                image.Dispose();
                return(array);
            }
        }
示例#2
0
        private void DisplayValue(string sVal)
        {
            try
            {
                ushort v  = ushort.Parse(sVal);
                double cv = double.Parse(sVal);
                if (v < 0 || v > maxPhotoVal)
                {
                    return;
                }

                SensorData data = new SensorData(DateTime.Now, v);
                photoDatas.Add(data);
                InsertDataToDB(data);

                TxtSensorCount.Text      = photoDatas.Count.ToString();
                PgbPhotoRegistor.Value   = v;
                LblPhotoRegistor.Content = v.ToString();

                string item = $"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")}\t{v}";
                if (AxisX.MaxValue < 200)
                {
                    AxisX.MaxValue++;
                }
                RtbLog.AppendText($"{item}\n");
                RtbLog.ScrollToEnd();
                LineValues.Add(cv);
                DataContext = this;
            }
            catch (Exception ex)
            {
                RtbLog.AppendText($"Error : {ex.Message}\n");
                RtbLog.ScrollToEnd(); //RtbLog.ScrollToCaret();
            }
        }
示例#3
0
        private void DisplayValue(string sVal)
        {
            try
            {
                ushort v = ushort.Parse(sVal);
                if (v < 0 || v > maxPhotoVal)
                {
                    return;
                }

                SensorData data = new SensorData(DateTime.Now, v);
                photoDatas.Add(data);

                TxtSensorCount.Text    = photoDatas.Count.ToString();
                PgbPhotoRegistor.Value = v;
                LblPhotoRegistor.Text  = v.ToString();

                string item = $"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")}\t{v}";

                RtbLog.AppendText($"{item}\n");
                //RtbLog.ScrollToCaret();
            }
            catch (Exception ex)
            {
                RtbLog.AppendText($"Error : {ex.Message}\n");
                //RtbLog.ScrollToCaret();
            }
        }
示例#4
0
        private void DisplayValue(string sVal)
        {
            try
            {
                ushort v = ushort.Parse(sVal);
                if (v < 0 || v > maxPhotoVal)
                {
                    return;
                }

                SensorData data = new SensorData(DateTime.Now, v);
                photoDatas.Add(data);
                InsertDataToDB(data);

                TxtSensorCount.Text    = photoDatas.Count.ToString();
                PgbPhotoRegistor.Value = v;
                LblPhotoRegistor.Text  = v.ToString();

                string item = $"{DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")}\t{v}";

                RtbLog.AppendText($"{item}\n");
                RtbLog.ScrollToCaret();

                ChtSensorValues.Series[0].Points.Add(v);

                ChtSensorValues.ChartAreas[0].AxisX.Minimum = 0;
                ChtSensorValues.ChartAreas[0].AxisX.Maximum =
                    (photoDatas.Count >= xCount) ? photoDatas.Count : xCount;

                if (photoDatas.Count > xCount)
                {
                    ChtSensorValues.ChartAreas[0].AxisX.ScaleView.Zoom(
                        photoDatas.Count - xCount, photoDatas.Count);
                }
                else
                {
                    ChtSensorValues.ChartAreas[0].AxisX.ScaleView.Zoom(0, xCount);
                }

                if (IsSimulation == false)
                {
                    BtnPortValue.Text = $"{serial.PortName}\n{sVal}";
                }
                else
                {
                    BtnPortValue.Text = $"{sVal}";
                }
            }
            catch (Exception ex)
            {
                RtbLog.AppendText($"Error : {ex.Message}\n");
                RtbLog.ScrollToCaret();
            }
        }
        private async Task ActDetect()
        {
            var photo = GetPhoto(DetectFpath.TextBox);

            if (photo == null)
            {
                return;
            }

            AddViewTabWithPB(photo, ref ViewImage);
            ViewImage2.Visibility = Visibility.Hidden;


            RtbLog.AppendText("Called Detect method...\n");
            InGo(false);

            bool?demographics = CbDemographics.IsChecked;
            bool?attributes   = CbAttributes.IsChecked;
            bool?landmarks    = CbLandmarks.IsChecked;
            bool?liveness     = CbLiveness.IsChecked;

            await Task.Run(async() =>
            {
                var r = (await tevian.Detect(photo,
                                             fdMinSize.Float,
                                             fdMinSize.Float,
                                             fdThreshold.Float,
                                             false,
                                             null,
                                             demographics,
                                             attributes,
                                             landmarks,
                                             liveness));

                await Dispatcher.BeginInvoke((Action)(() =>
                {
                    RtbLog.AppendText("Response: " + JsonConvert.SerializeObject(r) + "\n");

                    if (r.Item1.Length == 0)
                    {
                        return;
                    }

                    var bboxes = r.Item1.Select(fwi => fwi.Bbox).ToArray();

                    DrawBboxes(photo, bboxes, ref ViewImage);

                    InGo(true);
                }));
            });
        }
 private async void ButtonRegister_OnClick(object sender, RoutedEventArgs e)
 {
     await Task.Run(async() =>
     {
         try
         {
             await Tevian.Tevian.CreateAccount(LtbEmail.TextBox, LtbPassw.TextBox);
             ButtonLogin_OnClick(sender, e);
         }
         catch (TevianException ex)
         {
             await Dispatcher.BeginInvoke((Action)(() => { RtbLog.AppendText(ex.ToString() + "\n"); }));
             MessageBox.Show(ex.ToString(), "Exception", MessageBoxButton.OK);
         }
     });
 }
示例#7
0
        private void LoopPublish()
        {
            while (true)
            {
                SensorInfo value = SensorFaker.Generate();
                CurrValue = JsonConvert.SerializeObject(value, Formatting.Indented);
                BrokerClient.Publish("home/device/data", Encoding.Default.GetBytes(CurrValue));
                this.Invoke(new Action(() =>
                {
                    RtbLog.AppendText($"Published: {CurrValue}\n");
                    RtbLog.ScrollToCaret();
                }));

                Thread.Sleep(1000);
            }
        }
示例#8
0
        private void DisplayValue(string sVal)
        {
            try
            {
                ushort v = ushort.Parse(sVal);
                if (v < 0 || v > maxPhotoVal)
                {
                    return;
                }

                SensorData data = new SensorData(DateTime.Now, v);
                photoDatas.Add(data);
                TxtSensorCount.Text    = photoDatas.Count.ToString();
                PgbPhotoRegistor.Value = v;
                LblPhotoRegistor.Text  = v.ToString();

                string item = $"{photoDatas.Count} {DateTime.Now.ToString("yy-MM-dd hh:mm:ss")}\t{v}";


                RtbLog.AppendText($"{item}\n");
                RtbLog.ScrollToEnd();



                vs.Add(v);
                Time.Add(time);

                linegraph.PlotY(vs);


                if (IsSimulation == false)
                {
                    BtnPortValue.Content = $"{serial.PortName}\n{sVal}";
                    InsertDataToDB(data);
                }
                else
                {
                    BtnPortValue.Content = $"{sVal}";
                }
            }
            catch (Exception ex)
            {
                RtbLog.AppendText($"Error : {ex.Message}\n");
                RtbLog.ScrollToEnd();
            }
        }
        private async Task ActMatch()
        {
            var photo1 = GetPhoto(Match1FPath.TextBox);
            var photo2 = GetPhoto(Match2FPath.TextBox);

            if (photo1 == null || photo2 == null)
            {
                return;
            }

            AddViewTabWithPB(photo1, ref ViewImage);
            AddViewTabWithPB(photo2, ref ViewImage2);
            ViewImage2.Visibility = Visibility.Visible;

            RtbLog.AppendText("Called Match method...\n");
            InGo(false);

            await Task.Run(async() =>
            {
                var r = await tevian.Match(photo1, photo2,
                                           fdMinSize2.Float,
                                           fdMinSize2.Float,
                                           fdMinSize2.Float);

                await Dispatcher.BeginInvoke((Action)(() =>
                {
                    RtbLog.AppendText("Response: " + JsonConvert.SerializeObject(r) + "\n");

                    if (r == null)
                    {
                        return;
                    }

                    //var bboxes = r.face1_bbox.Select(fwi => fwi.Bbox).ToArray();

                    DrawBboxes(photo1, new[] { r.Face1.Bbox }, ref ViewImage);

                    DrawBboxes(photo2, new[] { r.Face2.Bbox }, ref ViewImage2);
                    InGo(true);
                }));
            });
        }
 private async void ButtonLogin_OnClick(object sender, RoutedEventArgs e)
 {
     await Task.Run(async() =>
     {
         try
         {
             tevian = new Tevian.Tevian(LtbEmail.TextBox, LtbPassw.TextBox);
             await Dispatcher.BeginInvoke((Action)(() =>
             {
                 BtnGo.IsEnabled = true;
                 AuthPanel.IsEnabled = false;
                 RtbLog.AppendText("Logged in. JWT: " + tevian.jwt + "\n");
             }));
         }
         catch (TevianException ex)
         {
             MessageBox.Show(ex.ToString(), "Exception", MessageBoxButton.OK);
         }
     });
 }