private void btnSample_Click(object sender, EventArgs e)
        {
            m_ltPoints.Clear();
            m_ltPatterns.Clear();

            Bitmap   bmpScreen        = new Bitmap("575.bmp");
            IplImage imgConvertBitmap = IplImage.FromBitmap(bmpScreen);
            IplImage imgMain          = new IplImage(new CvSize(imgConvertBitmap.Width, imgConvertBitmap.Height), BitDepth.U8, 1);

            Cv.CvtColor(imgConvertBitmap, imgMain, ColorConversion.RgbToGray);
            Cv.Threshold(imgMain, imgMain, 210, 255, ThresholdType.Binary);

            m_ltPatterns.Add(new IplImage("Pattern01.bmp", LoadMode.GrayScale));
            m_ltPatterns.Add(new IplImage("Pattern02.bmp", LoadMode.GrayScale));
            m_ltPatterns.Add(new IplImage("Pattern03.bmp", LoadMode.GrayScale));
            m_ltPatterns.Add(new IplImage("Pattern04.bmp", LoadMode.GrayScale));
            m_ltPatterns.Add(new IplImage("Pattern05.bmp", LoadMode.GrayScale));
            m_ltPatterns.Add(new IplImage("Pattern06.bmp", LoadMode.GrayScale));
            m_ltPatterns.Add(new IplImage("Pattern07.bmp", LoadMode.GrayScale));

            foreach (IplImage iplTemp in m_ltPatterns)
            {
                Cv.Threshold(iplTemp, iplTemp, 210, 255, ThresholdType.Binary);
            }

            foreach (IplImage iplTemp in m_ltPatterns)
            {
                int iWidth  = imgMain.Width - iplTemp.Width + 1;
                int iHeight = imgMain.Height - iplTemp.Height + 1;

                IplImage imgResult = new IplImage(Cv.Size(iWidth, iHeight), BitDepth.F32, 1);
                Cv.MatchTemplate(imgMain, iplTemp, imgResult, MatchTemplateMethod.CCorrNormed);

                double  dMin, dMax;
                CvPoint ptLeftTop;
                CvPoint ptRightBottom;
                Cv.MinMaxLoc(imgResult, out dMin, out dMax, out ptRightBottom, out ptLeftTop);
                //cvRectangle(A, left_top, cvPoint(left_top.x + B->width, left_top.y + B->height), CV_RGB(255, 0, 0));
                Cv.Rectangle(imgMain, ptLeftTop, new CvPoint(ptLeftTop.X + iplTemp.Width, ptLeftTop.Y + iplTemp.Height), Cv.RGB(255, 255, 255));

                m_ltPoints.Add(new Point(ptLeftTop.X, ptLeftTop.Y));
            }

            pictureBoxIpl.ImageIpl = imgMain;

            pictureBoxIpl.Invalidate();
        }
        private void Start()
        {
            if (m_hWndMain == IntPtr.Zero)
            {
                return;
            }

            Size     szScreen  = new Size(m_rcSize.right, m_rcSize.bottom);
            Bitmap   bmpScreen = new Bitmap(szScreen.Width, szScreen.Height, PixelFormat.Format32bppArgb);
            Graphics g         = Graphics.FromImage(bmpScreen);

            g.CopyFromScreen(m_rcLocation.left, m_rcLocation.top, 0, 0, szScreen);

            string text = DateTime.Now.Millisecond.ToString() + "\r\n";

            bmpScreen.Save(DateTime.Now.Millisecond.ToString() + ".bmp");

            IplImage imgConvertBitmap = IplImage.FromBitmap(bmpScreen);
            IplImage imgMain          = new IplImage(new CvSize(imgConvertBitmap.Width, imgConvertBitmap.Height), BitDepth.U8, 1);

            Cv.CvtColor(imgConvertBitmap, imgMain, ColorConversion.RgbToGray);
            Cv.Threshold(imgMain, imgMain, 200, 255, ThresholdType.Binary);

            foreach (IplImage iplTemp in m_ltPatterns)
            {
                int iWidth  = imgMain.Width - iplTemp.Width + 1;
                int iHeight = imgMain.Height - iplTemp.Height + 1;

                IplImage imgResult = new IplImage(Cv.Size(iWidth, iHeight), BitDepth.F32, 1);
                Cv.MatchTemplate(imgMain, iplTemp, imgResult, MatchTemplateMethod.CCoeffNormed);

                double  dMin, dMax;
                CvPoint ptLeftTop;
                CvPoint ptRightBottom;
                Cv.MinMaxLoc(imgResult, out dMin, out dMax, out ptRightBottom, out ptLeftTop);

                m_ltPoints.Add(new Point(m_ptStartDot.X + ptLeftTop.X + 15, m_ptStartDot.Y + ptLeftTop.Y + 15));
            }

            //
            //102 369

            SetCursorPos(m_ptStartDot.X, m_ptStartDot.Y);


            foreach (Point ptLocation in m_ltPoints)
            {
                text += "X : " + ptLocation.X + ", " + ptLocation.Y + "\r\n";

                SetCursorPos(ptLocation.X, ptLocation.Y);

                Thread.Sleep(72);

                mouse_event(WM_LBUTTONDOWN, 0, 0, 0, 0);

                Thread.Sleep(65);

                mouse_event(WM_LBUTTONUP, 0, 0, 0, 0);

                Thread.Sleep(65);
            }

            pictureBoxIpl.ImageIpl = imgMain;

            pictureBoxIpl.Invalidate();

            System.IO.File.WriteAllText("Recent_crood.txt", text);  // 로그 쓴다
        }
Пример #3
0
 public static IplImage GetFrame()
 {
     return(IplImage.FromBitmap(Properties.Resources.frame).Clone());
 }
Пример #4
0
 public static IplImage GetPortrait()
 {
     return(IplImage.FromBitmap(Properties.Resources.portrait).Clone());
 }
Пример #5
0
        EyeRects Recognize(PictureBox bb, Panel container)
        {
            const double ScaleFactor  = 2.5;
            const int    MinNeighbors = 1;
            CvSize       MinSize      = new CvSize(30, 30);

            //CvCapture cap = CvCapture.FromCamera(1);
            CvHaarClassifierCascade cascade = CvHaarClassifierCascade.FromFile("haarcascade_eye.xml");
            //IplImage img = cap.QueryFrame();
            IplImage          img  = IplImage.FromBitmap(new Bitmap(bb.Image));
            CvSeq <CvAvgComp> eyes = Cv.HaarDetectObjects(img, cascade, Cv.CreateMemStorage(), ScaleFactor, MinNeighbors, HaarDetectionType.DoCannyPruning, MinSize);

            img.DrawRect(new CvRect(30, 30, bb.Image.Width - 30, bb.Image.Height - 60), CvColor.Yellow);
            var rcs = new EyeRects();

            foreach (CvAvgComp eye in eyes.AsParallel())
            {
                rcs.AddRect(eye.Rect);
                img.DrawRect(eye.Rect, CvColor.Yellow);

                if (eye.Rect.Left > pn.Width / 2)
                {
                    try
                    {
                        IplImage rightEyeImg1 = img.Clone();
                        Cv.SetImageROI(rightEyeImg1, eye.Rect);
                        IplImage rightEyeImg2 = Cv.CreateImage(eye.Rect.Size, rightEyeImg1.Depth, rightEyeImg1.NChannels);
                        Cv.Copy(rightEyeImg1, rightEyeImg2, null);
                        Cv.ResetImageROI(rightEyeImg1);

                        //Bitmap rightEyeBm = BitmapConverter.ToBitmap(rightEyeImg2);
                        //spMain.Panel2.Image = rightEyeBm;
                    }
                    catch { }
                }
                else
                {
                    try
                    {
                        IplImage leftEyeImg1 = img.Clone();
                        Cv.SetImageROI(leftEyeImg1, eye.Rect);
                        IplImage leftEyeImg2 = Cv.CreateImage(eye.Rect.Size, leftEyeImg1.Depth, leftEyeImg1.NChannels);
                        Cv.Copy(leftEyeImg1, leftEyeImg2, null);
                        Cv.ResetImageROI(leftEyeImg1);

                        //Bitmap leftEyeBm = BitmapConverter.ToBitmap(leftEyeImg2);
                        //pctLeftEye.Image = leftEyeBm;
                    }
                    catch { }
                }
            }
            Bitmap bm = BitmapConverter.ToBitmap(img);

            //bm.SetResolution(1500, 1500);
            //pctCvWindow.Image = bm;
            //PictureBox pb = new PictureBox();
            //pb.Image = bm;
            //pb.Image = bm;
            bb.Image = bm;

            //spMain.Panel2.Controls.Clear();
            if (pn.Controls.Count < 1)
            {
                pn.Controls.Add(bb);
                //bb.Click += bb_Click;
            }
            bb.Dock = DockStyle.Fill;
            //pb.Image = bm;
            img = null;
            bm  = null;
            return(rcs);
        }