예제 #1
0
        private void CaptureImages(PointF [] imagePoints, Bitmap frame)
        {
            try
            {
                if (curFrame == null)
                {
                    curFrame = new CvImageWrapper(frame);
                }
                else
                {
                    curFrame.setImage(frame);
                }

                for (int i = 0; i < imagePoints.Length; i++)
                {
                    PointF imagePoint = imagePoints[i];

                    CvRect cropDimensions = new CvRect();
                    cropDimensions.x      = (int)imagePoint.X - obsSize / 2;
                    cropDimensions.y      = (int)imagePoint.Y - obsSize / 2;
                    cropDimensions.width  = obsSize;
                    cropDimensions.height = obsSize;

                    CvImageWrapper curObs = curFrame.cropSubImage(cropDimensions);

                    this.templatesList[i].Add(curObs);
                }
            }
            catch (Exception e)
            {
            }
        }
예제 #2
0
        public override void ProcessKeys(Keys keys)
        {
            if (finished)
            {
                return;
            }

            lock (mutex)
            {
                if (keys.Equals(Keys.Shift) || keys.Equals(Keys.ShiftKey) ||
                    keys.Equals(Keys.LShiftKey) || keys.Equals(Keys.RShiftKey))
                {
                    for (int i = 0; i < curPoints.Length; i++)
                    {
                        PointF curPoint = curPoints[i];

                        if (curPoint.X <= obsSize / 2 || curPoint.X >= curFrame.Size.Width - obsSize / 2)
                        {
                            return;
                        }
                        if (curPoint.Y <= obsSize / 2 || curPoint.Y >= curFrame.Size.Height - obsSize / 2)
                        {
                            return;
                        }

                        if (curFrame == null)
                        {
                            return;
                        }


                        CvRect cropDimensions = new CvRect();
                        cropDimensions.x      = (int)curPoint.X - obsSize / 2;
                        cropDimensions.y      = (int)curPoint.Y - obsSize / 2;
                        cropDimensions.width  = obsSize;
                        cropDimensions.height = obsSize;

                        CvImageWrapper curObs = curFrame.cropSubImage(cropDimensions);

                        this.templatesList[i].Add(curObs);
                        numKeyPressed++;
                        if (numKeyPressed == this.numTemplates)
                        {
                            Thread.Sleep(300);
                            finished = true;
                        }
                        else
                        {
                            SendMessage();
                        }
                    }
                }
            }
        }
예제 #3
0
        public override bool Process(PointF  [] imagePoints, System.Drawing.Bitmap[] frames)
        {
            lock (mutex)
            {
                if (finished)
                {
                    return(false);
                }

                if (centerPoint.IsEmpty)
                {
                    centerPoint.X = imagePoints[0].X;
                    centerPoint.Y = imagePoints[0].Y;
                    return(true);
                }

                if (curFrame == null)
                {
                    curFrame = new CvImageWrapper(frames[0]);
                }
                else
                {
                    curFrame.setImage(frames[0]);
                }


                if (setupFrame == null)
                {
                    setupFrame = new Bitmap(curFrame.Size.Width, curFrame.Size.Height);
                    InitSetupFrame();
                }

                relCurPoint = mouseControlStandard.ComputeRelCursorInWindow(imagePoints[0], centerPoint);
                int xRectIndex = (int)Math.Floor((double)rectangleLength * relCurPoint.X);
                int yRectIndex = (int)Math.Floor((double)rectangleLength * relCurPoint.Y);

                if (xRectIndex >= rectangleLength)
                {
                    xRectIndex = rectangleLength - 1;
                }
                if (yRectIndex >= rectangleLength)
                {
                    yRectIndex = rectangleLength - 1;
                }
                if (xRectIndex < 0)
                {
                    xRectIndex = 0;
                }
                if (yRectIndex < 0)
                {
                    yRectIndex = 0;
                }

                if (rectangles[xRectIndex, yRectIndex] && !finished)
                {
                    rectangles[xRectIndex, yRectIndex] = false;
                    curNumRectangles++;

                    for (int i = 0; i < imagePoints.Length; i++)
                    {
                        PointF imagePoint = imagePoints[i];

                        if (!(imagePoint.X <= obsSize / 2 || imagePoint.X >= curFrame.Size.Width - obsSize / 2) &&
                            !(imagePoint.Y <= obsSize / 2 || imagePoint.Y >= curFrame.Size.Height - obsSize / 2))
                        {
                            CvRect cropDimensions = new CvRect();
                            cropDimensions.x      = (int)imagePoint.X - obsSize / 2;
                            cropDimensions.y      = (int)imagePoint.Y - obsSize / 2;
                            cropDimensions.width  = obsSize;
                            cropDimensions.height = obsSize;

                            CvImageWrapper curObs = curFrame.cropSubImage(cropDimensions);
                            this.templatesList[i].Add(curObs);
                            UpdateSetupFrame();
                        }
                    }

                    if (curNumRectangles == this.numTemplates)
                    {
                        this.finished = true;
                        return(false);
                    }
                    else
                    {
                        SendMessage();
                    }
                }

                else if (shouldSendMessage)
                {
                    shouldSendMessage = false;
                    SendMessage();
                }
                return(true);
            }
        }