Exemple #1
0
        public void ShowGraphFilterResult(int imgID)
        {
            long           msec     = DateTimeOffset.Now.ToUnixTimeMilliseconds();
            List <DataSrc> dataSrcs = graphFilter.GetOuts();
            long           msec2    = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            ProgressBarInfo = "Time:" + (msec2 - msec) + " (ms)";


            if (dataSrcs.Count == 0)
            {
                Console.WriteLine("Filter error");
                return;
            }

            imgID = imgID % dataSrcs.Count;
            var bitmap = OpenCVHelper.GetRGBBitmapFromCvMat(dataSrcs[imgID].Image);

            if (bitmap == null)
            {
                Console.WriteLine("read error");
                return;
            }

            SetImageSource(bitmap, dataSrcs[imgID].Info);
        }
Exemple #2
0
        /// <summary>
        /// Set up basic properties.
        /// </summary>
        private void Setup()
        {
            rfbInput      = new RfbInput();
            landmarkInput = new LandmarkInput();

            cameraFocalLength = new Vector2(330.0f, 330.0f);
            closestDistance   = 10000.0f;
            CameraMode        = false;
            ShowDetail        = false;
            taskRunning       = false;

            openCVHelper = new OpenCVBridge.OpenCVHelper();
            drawingFace  = new DrawingFace(imageDisplayMaxWidth, imageDisplayMaxHeight);

            imageOriginalWidth  = 1;
            imageOriginalHeight = 1;

            imageInputData = new SoftwareBitmap(BitmapPixelFormat.Bgra8, FaceDetectionHelper.inputImageDataWidth, FaceDetectionHelper.inputImageDataHeight, BitmapAlphaMode.Premultiplied);

            recognizeButton.Visibility = Visibility.Collapsed;



            LoadFaceDetectionModelAsync();
            LoadFaceLandmarkModelAsync();
        }
Exemple #3
0
        public void ExportGraphFilterResult(int nId, string fileName, ExportSettings exportSettings)
        {
            BaseFilter mainFileFilter = graphFilter.FindFirtsFilter(FilterType.File);

            if (mainFileFilter != null)
            {
                mainFileFilter["Path"] = new FilterBuilder.Filter.FileInfo(fileName);
                List <DataSrc> dataSrcs = graphFilter.GetOuts();
                if (dataSrcs.Count == 0)
                {
                    // todo
                    return;
                }

                for (int nSrcId = 0; nSrcId < dataSrcs.Count; nSrcId++)
                {
                    string filename = exportSettings.GetFileName(dataSrcs[nSrcId].Info);
                    if (filename == null)
                    {
                        filename = nSrcId.ToString() + "." + exportSettings.Format;
                    }

                    string ToFolder = exportSettings.GetFolder(dataSrcs[nSrcId].Info);
                    ToFolder += "\\" + nId + "\\";

                    filename = ToFolder + filename;

                    try
                    {
                        if (!Directory.Exists(ToFolder))
                        {
                            Directory.CreateDirectory(ToFolder);
                        }


                        ImageFormat useFormat = ImageFormat.Jpeg;
                        switch (exportSettings.Format)
                        {
                        case "jpg": useFormat = ImageFormat.Jpeg; break;

                        case "png": useFormat = ImageFormat.Png; break;

                        case "bmp": useFormat = ImageFormat.Bmp; break;
                        }

                        Bitmap bitmap = OpenCVHelper.GetRGBBitmapFromCvMat(dataSrcs[nSrcId].Image);
                        bitmap.Save(filename, useFormat);
                    } catch { }
                }
            }
        }
        public Scenario1_ExampleOperations()
        {
            this.InitializeComponent();
            _previewRenderer = new FrameRenderer(PreviewImage);
            _outputRenderer  = new FrameRenderer(OutputImage);

            _helper = new OpenCVHelper();

            _FPSTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            _FPSTimer.Tick += UpdateFPS;
        }
Exemple #5
0
        public async void InitializeManager()
        {
            _helper = new OpenCVHelper();

            // Find the sources
            var allGroups = await MediaFrameSourceGroup.FindAllAsync();

            var sourceGroups = allGroups.Select(g => new
            {
                Group      = g,
                SourceInfo = g.SourceInfos.FirstOrDefault(i => i.SourceKind == MediaFrameSourceKind.Color)
            }).Where(g => g.SourceInfo != null).ToList();

            if (sourceGroups.Count == 0)
            {
                // No camera sources found
                return;
            }
            var selectedSource = sourceGroups.FirstOrDefault();

            // Initialize MediaCapture
            try
            {
                await InitializeMediaCaptureAsync(selectedSource.Group);
            }
            catch (Exception exception)
            {
                Debug.WriteLine("MediaCapture initialization error: " + exception.Message);
                await CleanupMediaCaptureAsync();

                return;
            }

            // Create the frame reader
            MediaFrameSource frameSource = _mediaCapture.FrameSources[selectedSource.SourceInfo.Id];
            var format = frameSource.SupportedFormats.OrderByDescending(x => x.VideoFormat.Width * x.VideoFormat.Height).FirstOrDefault();
            await frameSource.SetFormatAsync(format);

            BitmapSize size = new BitmapSize() // Choose a lower resolution to make the image processing more performant
            {
                Height = format.VideoFormat.Height,
                Width  = format.VideoFormat.Width
            };

            _reader = await _mediaCapture.CreateFrameReaderAsync(frameSource, MediaEncodingSubtypes.Bgra8, size);

            _reader.FrameArrived += HandleFrameArrive;
            await _reader.StartAsync();
        }
Exemple #6
0
        public HttpServer(Camera camera, VideoSetting videoSetting)
        {
            this._camera      = camera;
            this.videoSetting = videoSetting;
            this.isFeedActive = false;

            this._listener = new StreamSocketListener();
            this._listener.ConnectionReceived      += this.ProcessRequest;
            this._listener.Control.KeepAlive        = false;
            this._listener.Control.NoDelay          = false;
            this._listener.Control.QualityOfService = SocketQualityOfService.LowLatency;
            this._listener.BindServiceNameAsync(80.ToString()).GetAwaiter();
            this.openCvHelper = new OpenCVHelper();
            this.LoadModelAsync().GetAwaiter();
        }
        public override bool Do()
        {
            try
            {
                var bReqFullUpdate = !m_isSelfClearOut || (pixelSumResults.Count == 0);
                if (bReqFullUpdate)
                {
                    pixelSumResults.Clear();
                }

                FilterDrawMode drawMode = (FilterDrawMode)EnumPropertys["Draw"].Value;

                int listID = 0;
                for (int srcID = 0; srcID < Sources.Count; srcID++)
                {
                    var outDatas = Sources[srcID].GetOut();
                    for (int dataID = 0; dataID < outDatas.Count; dataID++)
                    {
                        if (bReqFullUpdate)
                        {
                            pixelSumResults.Add(OpenCVHelper.GetPixelSum(outDatas[dataID].Image));
                        }

                        if (drawMode == FilterDrawMode.Show)
                        {
                            double val  = pixelSumResults[listID];
                            Mat    copy = outDatas[dataID].Image.Clone();
                            CvInvoke.PutText(
                                copy,
                                "sum:" + val.ToString(),
                                new System.Drawing.Point(10, IntPropertys["y"].Value),
                                FontFace.HersheyComplex, 1.0, new Bgr(IntPropertys["r"].Value, IntPropertys["g"].Value, IntPropertys["b"].Value).MCvScalar);
                            this.m_out.Add(new DataSrc(copy, outDatas[dataID].Info, false));
                        }
                        else
                        {
                            this.m_out.Add(outDatas[dataID].Clone());
                        }

                        listID++;
                    }
                }
            } catch { return(false); }
            return(true);
        }
        public override bool Do()
        {
            Mat kernelMat = OpenCVHelper.GetMat(TablePropertys["Kernel"].m_table, TablePropertys["Kernel"].Rows, TablePropertys["Kernel"].Columns);

            try
            {
                var kernel = TablePropertys["Kernel"];
                foreach (var src in Sources)
                {
                    foreach (var outData in src.GetOut())
                    {
                        Mat dst = outData.Image.Clone();
                        CvInvoke.Filter2D(outData.Image, dst, kernelMat, new System.Drawing.Point(-1, -1));
                        this.m_out.Add(new DataSrc(dst, outData.Info, false));
                    }
                }
            }
            catch { return(false); }
            return(true);
        }
Exemple #9
0
        private int CheckPercentageImage(RoiPositionModel roiPositionModel, Process process, Tuple <double, double, double> lower, Tuple <double, double, double> upper)
        {
            var applciationData = ObjectExtensions.GetInstance <ApplicationDataManager>().Find(process.ProcessName) ?? new ApplicationDataModel();

            if (DisplayHelper.ProcessCapture(process, out Bitmap bitmap, applciationData.IsDynamic))
            {
                var processPosition = new Rect();
                NativeHelper.GetWindowRect(process.MainWindowHandle, ref processPosition);

                var factor  = NativeHelper.GetSystemDPI();
                var factorX = 1.0F * factor.X / ConstHelper.DefaultDPI;
                var factorY = 1.0F * factor.Y / ConstHelper.DefaultDPI;

                var realLeft = roiPositionModel.RoiPosition.Left - ((processPosition.Left - roiPositionModel.MonitorInfo.Rect.Left));
                var realTop  = roiPositionModel.RoiPosition.Top - (processPosition.Top - roiPositionModel.MonitorInfo.Rect.Top);

                var realWidth  = (int)Math.Truncate(roiPositionModel.RoiPosition.Width * factorX);
                var realHeight = (int)Math.Truncate(roiPositionModel.RoiPosition.Height * factorY);

                //var realWidth = realLeft + roiPositionModel.RoiPosition.Width;
                //var realHeight = realTop + roiPositionModel.RoiPosition.Height;


                var roi = new Rect()
                {
                    Left   = 327,
                    Right  = 1563,
                    Top    = 548,
                    Bottom = 773,
                };

                var roiBitmap = OpenCVHelper.MakeRoiImage(bitmap, roi);

                roiBitmap.Save("crop.jpg");

                canvasCaptureImage.Background = new ImageBrush(roiBitmap.ToBitmapSource());

                var percent = OpenCVHelper.SearchImagePercentage(roiBitmap, lower, upper);
            }
            return(0);
        }
Exemple #10
0
        public MainPage()
        {
            this.InitializeComponent();

            puzzleSolver   = new PuzzleSolver();
            PanelParser    = new Parser();
            BrightnessCalc = new BrightnessCalculator();

            stylusDriver = new StylusDriver(phoneConfig);

            _SourceRenderer      = new FrameRenderer(PreviewImage);
            _ColorFilterRenderer = new FrameRenderer(ColotFilterImage);
            _ClippedRenderer     = new FrameRenderer(ClippedImage);

            _cvhelper = new OpenCVHelper();

            _FPSTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromSeconds(1)
            };
            _FPSTimer.Tick += UpdateFPS;

            _MessageTimer = new DispatcherTimer()
            {
                Interval = TimeSpan.FromMilliseconds(100)
            };
            _MessageTimer.Tick += MessageTimer_Tick;
            MessageSB           = new StringBuilder();

            webcam = new Webcam(100);
            webcam.OnReceiveFrame += Webcam_OnReceiveFrame;

            StartPoint = new Point(phoneConfig.PadPanelLocation.Left, phoneConfig.PadPanelLocation.Top);
            EndPoint   = new Point(phoneConfig.PadPanelLocation.Right, phoneConfig.PadPanelLocation.Bottom);
            TargetScoreTextbox.Text = TargetRouteScore.ToString();

            FastModeCheckButton.IsChecked = FastMode;
            AutoModeCheckButton.IsChecked = AutoMode;
        }
Exemple #11
0
        public async Task <Tuple <bool, IBaseEventTriggerModel> > TriggerProcess <T>(T model, ProcessConfigModel processConfigModel) where T : BaseEventTriggerModel <T>
        {
            var isExcute = false;

            var hWnd            = IntPtr.Zero;
            var applciationData = ObjectExtensions.GetInstance <ApplicationDataManager>().Find(model.ProcessInfo.ProcessName) ?? new ApplicationDataModel();

            for (int i = 0; i < processConfigModel.Processes.Count; ++i)
            {
                var factor = CalculateFactor(processConfigModel.Processes[i].MainWindowHandle, model, applciationData.IsDynamic);

                if (string.IsNullOrEmpty(applciationData.HandleName))
                {
                    hWnd = processConfigModel.Processes[i].MainWindowHandle;
                }
                else
                {
                    var item = NativeHelper.GetChildHandles(processConfigModel.Processes[i].MainWindowHandle).Where(r => r.Item1.Equals(applciationData.HandleName)).FirstOrDefault();

                    if (item != null)
                    {
                        hWnd = item.Item2;
                    }
                    else
                    {
                        hWnd = processConfigModel.Processes[i].MainWindowHandle;
                    }
                }

                if (model.RepeatInfo.RepeatType == RepeatType.Search && model.SubEventTriggers.Count > 0)
                {
                    var count = model.RepeatInfo.Count;
                    while (DisplayHelper.ProcessCapture(processConfigModel.Processes[i], out Bitmap bmp, applciationData.IsDynamic) && count-- > 0)
                    {
                        var targetBmp  = model.Image.Resize((int)Math.Truncate(model.Image.Width * factor.Item1.Item1), (int)Math.Truncate(model.Image.Height * factor.Item1.Item1));
                        var similarity = OpenCVHelper.Search(bmp, targetBmp, out Point location, processConfigModel.SearchImageResultDisplay);
                        LogHelper.Debug($"RepeatType[Search : {count}] : >>>> Similarity : {similarity} % max Loc : X : {location.X} Y: {location.Y}");
                        this.baseContentView.CaptureImage(bmp);
                        if (!await TaskHelper.TokenCheckDelayAsync(model.AfterDelay, processConfigModel.Token) || similarity > processConfigModel.Similarity)
                        {
                            break;
                        }
                        for (int ii = 0; ii < model.SubEventTriggers.Count; ++ii)
                        {
                            await TriggerProcess(model.SubEventTriggers[ii], processConfigModel);

                            if (processConfigModel.Token.IsCancellationRequested)
                            {
                                break;
                            }
                        }
                        factor = CalculateFactor(processConfigModel.Processes[i].MainWindowHandle, model, applciationData.IsDynamic);
                    }
                }
                else
                {
                    var targetBmp = model.Image.Resize((int)Math.Truncate(model.Image.Width * factor.Item1.Item1), (int)Math.Truncate(model.Image.Height * factor.Item1.Item2));

                    if (model.SameImageDrag == true)
                    {
                        if (DisplayHelper.ProcessCapture(processConfigModel.Processes[i], out Bitmap bmp, applciationData.IsDynamic))
                        {
                            //Todo
                            for (int ii = 0; ii < model.MaxSameImageCount; ++ii)
                            {
                                var locations = OpenCVHelper.MultipleSearch(bmp, targetBmp, processConfigModel.Similarity, 2, processConfigModel.SearchImageResultDisplay);
                                if (locations.Count > 1)
                                {
                                    this.baseContentView.CaptureImage(bmp);
                                    var startPoint = new Point(locations[0].X + targetBmp.Width / 2, locations[0].Y + targetBmp.Height / 2);

                                    startPoint.X += this.GetRandomValue(0, targetBmp.Width / 2);
                                    startPoint.Y += this.GetRandomValue(0, targetBmp.Height / 2);

                                    var endPoint = new Point(locations[1].X + targetBmp.Width / 2, locations[1].Y + targetBmp.Width / 2);
                                    endPoint.X += this.GetRandomValue(0, targetBmp.Width / 2);
                                    endPoint.Y += this.GetRandomValue(0, targetBmp.Height / 2);

                                    SameImageMouseDragTriggerProcess(hWnd, startPoint, endPoint, model, factor.Item2, processConfigModel);
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else if (DisplayHelper.ProcessCapture(processConfigModel.Processes[i], out Bitmap bmp, applciationData.IsDynamic))
                    {
                        var similarity = OpenCVHelper.Search(bmp, targetBmp, out Point location, processConfigModel.SearchImageResultDisplay);
                        LogHelper.Debug($"Similarity : {similarity} % max Loc : X : {location.X} Y: {location.Y}");
                        if (model.SameImageDrag == false)
                        {
                            this.baseContentView.CaptureImage(bmp);
                        }
                        if (similarity > processConfigModel.Similarity)
                        {
                            if (model.SubEventTriggers.Count > 0)
                            {
                                if (model.RepeatInfo.RepeatType == RepeatType.Count || model.RepeatInfo.RepeatType == RepeatType.Once)
                                {
                                    for (int ii = 0; ii < model.RepeatInfo.Count; ++ii)
                                    {
                                        if (!await TaskHelper.TokenCheckDelayAsync(model.AfterDelay, processConfigModel.Token))
                                        {
                                            break;
                                        }
                                        for (int iii = 0; iii < model.SubEventTriggers.Count; ++iii)
                                        {
                                            await TriggerProcess(model.SubEventTriggers[iii], processConfigModel);

                                            if (processConfigModel.Token.IsCancellationRequested)
                                            {
                                                break;
                                            }
                                        }
                                    }
                                }
                                else if (model.RepeatInfo.RepeatType == RepeatType.NoSearch)
                                {
                                    while (await TaskHelper.TokenCheckDelayAsync(model.AfterDelay, processConfigModel.Token))
                                    {
                                        isExcute = false;
                                        for (int ii = 0; ii < model.SubEventTriggers.Count; ++ii)
                                        {
                                            var childResult = await TriggerProcess(model.SubEventTriggers[ii], processConfigModel);

                                            if (processConfigModel.Token.IsCancellationRequested)
                                            {
                                                break;
                                            }
                                            if (isExcute == false && childResult.Item1)
                                            {
                                                isExcute = childResult.Item1;
                                            }
                                        }
                                        if (!isExcute)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                isExcute = true;
                                if (model.EventType == EventType.Mouse)
                                {
                                    location.X = applciationData.OffsetX;
                                    location.Y = applciationData.OffsetY;
                                    MouseTriggerProcess(hWnd, location, model, factor.Item2, processConfigModel);
                                }
                                else if (model.EventType == EventType.Image)
                                {
                                    var percentageX = _random.NextDouble();
                                    var percentageY = _random.NextDouble();

                                    location.X = ((location.X + applciationData.OffsetX) / factor.Item2.Item1) + (targetBmp.Width / factor.Item2.Item1 * percentageX);
                                    location.Y = ((location.Y + applciationData.OffsetY) / factor.Item2.Item2) + (targetBmp.Height / factor.Item2.Item1 * percentageY);
                                    ImageTriggerProcess(hWnd, location, model);
                                }
                                else if (model.EventType == EventType.RelativeToImage)
                                {
                                    location.X = ((location.X + applciationData.OffsetX) / factor.Item2.Item1) + (targetBmp.Width / factor.Item2.Item1 / 2);
                                    location.Y = ((location.Y + applciationData.OffsetY) / factor.Item2.Item2) + (targetBmp.Height / factor.Item2.Item2 / 2);
                                    ImageTriggerProcess(hWnd, location, model);
                                }

                                else if (model.EventType == EventType.Keyboard)
                                {
                                    KeyboardTriggerProcess(processConfigModel.Processes[i].MainWindowHandle, model);
                                }
                                if (!await TaskHelper.TokenCheckDelayAsync(model.AfterDelay, processConfigModel.Token))
                                {
                                    break;
                                }

                                if (model.EventToNext > 0 && model.TriggerIndex != model.EventToNext)
                                {
                                    IBaseEventTriggerModel nextModel = null;
                                    if (model is GameEventTriggerModel)
                                    {
                                        nextModel = ObjectExtensions.GetInstance <CacheDataManager>().GetGameEventTriggerModel(model.EventToNext);
                                    }
                                    else if (model is EventTriggerModel)
                                    {
                                        nextModel = ObjectExtensions.GetInstance <CacheDataManager>().GetEventTriggerModel(model.EventToNext);
                                    }

                                    if (nextModel != null)
                                    {
                                        LogHelper.Debug($">>>>Next Move Event : CurrentIndex [ {model.TriggerIndex} ] NextIndex [ {nextModel.TriggerIndex} ] ");
                                        return(Tuple.Create(isExcute, nextModel));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            await TaskHelper.TokenCheckDelayAsync(processConfigModel.ItemDelay, processConfigModel.Token);

            return(Tuple.Create <bool, IBaseEventTriggerModel>(isExcute, null));
        }
Exemple #12
0
        public override bool Do()
        {
            try
            {
                m_rectangles.Clear();
                FilterDrawMode DrawOn = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                bool           bDraw  = DrawOn == FilterDrawMode.Show;

                int clVal     = IntPropertys["Color"].Value;
                var drawColor = new MCvScalar((clVal * 2) % 255, (clVal * 0.5) % 255, clVal);

                var CenterMode = (FilterLogicMode)EnumPropertys["PixelSumCenter"].Value;

                foreach (var src in Sources)
                {
                    foreach (var outData in src.GetOut())
                    {
                        Mat dst = outData.Image.Clone();

                        int xx = 0;
                        int yy = 0;

                        int ww = IntPropertys["width"].Value;
                        int hh = IntPropertys["height"].Value;

                        switch (CenterMode)
                        {
                        case FilterLogicMode.Off:
                            xx = IntPropertys["x"].Value;
                            yy = IntPropertys["y"].Value;
                            break;

                        case FilterLogicMode.On:
                            var pointCenter = OpenCVHelper.GetXYPixelSumCenter(outData.Image);
                            xx = pointCenter.X - ww / 2;
                            yy = pointCenter.Y - hh / 2;
                            break;
                        }

                        if (xx < 0)
                        {
                            xx = 0;
                        }

                        if (yy < 0)
                        {
                            yy = 0;
                        }

                        if (xx > outData.Image.Width)
                        {
                            xx = outData.Image.Width;
                        }

                        if (yy > outData.Image.Height)
                        {
                            xx = outData.Image.Height;
                        }

                        if ((ww + xx) > outData.Image.Width)
                        {
                            ww = outData.Image.Width - xx;
                        }

                        if ((hh + yy) > outData.Image.Height)
                        {
                            hh = outData.Image.Height - yy;
                        }

                        Rectangle rect = new Rectangle(xx, yy, ww, hh);

                        if (m_rectangles.Count == 0)
                        {
                            m_rectangles.Add(rect); // буду делать только один ректангл, на все GetOut's, тут множить смысла не даёю, да лишний CropRectFilter делает
                        }
                        if (bDraw)
                        {
                            CvInvoke.Rectangle(dst, rect, drawColor, 3);
                        }

                        this.m_out.Add(new DataSrc(dst, outData.Info, false));
                    }
                }
            }
            catch { return(false); }
            return(true);
        }