예제 #1
0
        public static double templateMatch()
        {
            DateTime t1 = DateTime.Now, t2 = t1;

            int resultNum = 1000;

            float[] X1 = new float[1000];
            float[] X2 = new float[1000];
            float[] Y1 = new float[1000];
            float[] Y2 = new float[1000];
            X1[0] = rect.X + rect.Width / 2;
            X2[0] = rect.X + rect.Width;
            Y1[0] = rect.Y + rect.Height / 2;
            Y2[0] = rect.Y + rect.Height;
            float[] Alpha = new float[1000];

            t1 = DateTime.Now;
            templateMatchDLL(tempFilename, objFilename, ref resultNum, X1, Y1, X2, Y2, Alpha);
            t2 = DateTime.Now;

            for (int i = 0; i < resultNum; i++)
            {
                ImageShow.addRect(new PointF(X1[i], Y1[i]), new PointF(X2[i], Y2[i]), Alpha[i], true);
            }

            return((t2 - t1).TotalMilliseconds);
        }
예제 #2
0
        public static double detectDefect(ref int isOK)
        {
            DateTime t1 = DateTime.Now, t2 = t1;

            //tempSelectPointIndex.Add(new PointF((float)1152.76, (float)1154.42));
            //tempSelectPointIndex.Add(new PointF((float)1506.53, (float)1118.48));
            //tempSelectPointIndex.Add(new PointF((float)1503.34, (float)1347.21));
            //tempSelectPointIndex.Add(new PointF((float)1166.15, (float)1367.25));

            //selectPointIndex.Add(new PointF((float)1079.04, (float)1087.97));
            //selectPointIndex.Add(new PointF((float)1390.66, (float)1264.99));
            //selectPointIndex.Add(new PointF((float)1254.86, (float)1449.18));
            //selectPointIndex.Add(new PointF((float)966.40, (float)1268.93));

            if (templateFile != null && objectFile != null && tempSelectPointIndex.Count() == 4 && selectPointIndex.Count() == 4)
            {
                int   resultNum = 1000;
                int[] X         = new int[resultNum];
                int[] Y         = new int[resultNum];
                int[] W         = new int[resultNum];
                int[] H         = new int[resultNum];

                t1 = DateTime.Now;
                defectDetect(templateFile, objectFile,
                             tempSelectPointIndex[0].X, tempSelectPointIndex[0].Y,
                             tempSelectPointIndex[1].X, tempSelectPointIndex[1].Y,
                             tempSelectPointIndex[2].X, tempSelectPointIndex[2].Y,
                             tempSelectPointIndex[3].X, tempSelectPointIndex[3].Y,
                             selectPointIndex[0].X, selectPointIndex[0].Y,
                             selectPointIndex[1].X, selectPointIndex[1].Y,
                             selectPointIndex[2].X, selectPointIndex[2].Y,
                             selectPointIndex[3].X, selectPointIndex[3].Y,
                             colorThr, areaThr, ref resultNum, X, Y, W, H);
                t2 = DateTime.Now;

                for (int i = 0; i < resultNum; i++)
                {
                    ImageShow.addRect(new PointF((float)(X[i] + (double)W[i] / 2.0), (float)(Y[i] + (double)H[i] / 2.0)), new PointF((float)X[i], (float)Y[i]), 0, false);
                }

                if (resultNum > 0)
                {
                    isOK = 2;
                }
                else
                {
                    isOK = 1;
                }
            }
            return((t2 - t1).TotalMilliseconds);
        }
예제 #3
0
        public override void mouseDown(PointF p1)
        {
            float x1 = (p1.X - ImageShow.position.X) / ImageShow.scale;
            float y1 = (p1.Y - ImageShow.position.Y) / ImageShow.scale;

            ImageShow.addRect(new PointF(x1, y1), new PointF(x1, y1), 0, true);
            if (figureDetect.setRectParaState)
            {
                figureDetect.shapeIndex = ImageShow.shapes.Count - 1;
            }
            if (CodeRecog.setRectParaState > 0)
            {
                CodeRecog.shapeIndex = ImageShow.shapes.Count - 1;
            }
        }
예제 #4
0
        public static double callTemplateDetect()
        {
            DateTime t1 = DateTime.Now, t2 = t1;

            if (ImageShow.nowFile != null && filename != null && detectROI != new Rectangle(0, 0, 0, 0))
            {
                ImageShow.source = new Bitmap(ImageShow.nowFile);
                Rectangle rect = new Rectangle(0, 0, ImageShow.source.Width, ImageShow.source.Height);
                System.Drawing.Imaging.BitmapData bmpData = ImageShow.source.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, ImageShow.source.PixelFormat);

                IntPtr ptr = bmpData.Scan0;

                int    bytes     = Math.Abs(bmpData.Stride) * ImageShow.source.Height;
                byte[] rgbValues = new byte[bytes];

                System.Runtime.InteropServices.Marshal.Copy(ptr, rgbValues, 0, bytes);

                byte[] data = new byte[detectROI.Width * (bmpData.Stride / bmpData.Width) * detectROI.Height];
                for (int i = 0; i < detectROI.Height; i++)
                {
                    for (int j = 0; j < detectROI.Width * (bmpData.Stride / bmpData.Width); j++)
                    {
                        data[i * detectROI.Width * (bmpData.Stride / bmpData.Width) + j] = rgbValues[(i + detectROI.Y) * bmpData.Stride + j + detectROI.X * (bmpData.Stride / bmpData.Width)];
                    }
                }


                int     resultNum = 1000;
                int[]   resultX   = new int[resultNum];
                int[]   resultY   = new int[resultNum];
                int[]   dir       = new int[resultNum];
                float[] rate      = new float[resultNum];

                t1 = DateTime.Now;
                templateDetect(detectROI.Width, detectROI.Height, detectROI.Height * detectROI.Width * (bmpData.Stride / bmpData.Width), data, filename, ref resultNum, resultX, resultY, dir, rate);
                t2 = DateTime.Now;

                for (int i = 0; i < resultNum; i++)
                {
                    ImageShow.addRect(new PointF((float)(resultX[i] + detectROI.X), (float)(resultY[i] + detectROI.Y)),
                                      new PointF((float)(resultX[i] + detectROI.X + Math.Sqrt(w * w / 4 + h * h / 4) * Math.Cos((double)dir[i] * Math.PI / 180.0 + Math.Atan((double)h / (double)w))),
                                                 (float)(resultY[i] + detectROI.Y + Math.Sqrt(w * w / 4 + h * h / 4) * Math.Sin((double)dir[i] * Math.PI / 180.0 + Math.Atan((double)h / (double)w)))), (float)(dir[i] * Math.PI / 180.0), false);
                }

                ImageShow.source.UnlockBits(bmpData);
            }
            return((t2 - t1).TotalMilliseconds);
        }