Exemple #1
0
        //Board(81cells) recognition
        public Mat _2B_SDK_ProjectivTransformInv(Mat frame2, Point[] Q4W, bool DispB)
        {
            int  rgN = regSize, Na = 0, Nb = regSize, Nc = Na + Nb;
            Size sz = new Size(rgN, rgN);

            //射影変換設定
            Point[] reaXY = { new Point(Na, Na), new Point(Nc, Na), new Point(Nc, Nc), new Point(Na, Nc) }; //■テンプレート枠

            PT.SetPoint(reaXY, Q4W);                                                                        //Projective transformation parameter set
            PT.ProjectionSolver();                                                                          //Calculation of projective transformation parameters

            byte b255 = 255, b0 = 0, thVal = 128;
            Mat  BlockImg = new Mat(sz, MatType.CV_8UC1);

            unsafe {
                int   Hi = frame2.Height, Wi = frame2.Width, Wb = BlockImg.Width;
                byte *S = frame2.DataPointer;
                byte *D = BlockImg.DataPointer;

                Point Qi = new Point(), Qr = new Point();
                for (int y = 0; y < rgN; y++)
                {
                    Qr.Y = y;
                    for (int x = 0; x < rgN; x++)
                    {
                        Qr.X = x;
                        Qi   = PT.Convert_RtoI(Qr);
                        if (Qi.X < 0 || Qi.X >= Wi || Qi.Y < 0 || Qi.Y >= Hi)
                        {
                            continue;
                        }
                        D[y * Wb + x] = (S[Qi.Y * Wi + Qi.X] > thVal)? b255: b0;
                    }
                }
            }
            //    Cv2.ImWrite("BlockImg.jpg", BlockImg);

            if (DispB)
            {
                new Window("SDK_MakeOutCel", WindowMode.KeepRatio, BlockImg);
            }
            return(BlockImg);
        }