Пример #1
0
 public CvRect(CvPoint offset, CvSize size)
 {
     this.x = offset.x;
     this.y = offset.y;
     this.width = size.width;
     this.height = size.height;
 }
Пример #2
0
        void DrawSquares(List<CvPoint> squares, PieceInfo[] pieces, HighGuiWindow window)
        {
            using (IplImage cpy = lastFrame.CloneImage())
            {

                StructureSafeMemoryBox<CvPoint> pt = new StructureSafeMemoryBox<CvPoint>(4);
                IntPtrSafeMemoryBox rect = new IntPtrSafeMemoryBox();
                rect.Value = pt.Pointer;
                Int32SafeMemoryBox count = new Int32SafeMemoryBox();
                count.Value = 4;

                for (int i = 0; i < squares.Count; i += 4)
                {
                    pt[0] = squares[i + 0];
                    pt[1] = squares[i + 1];
                    pt[2] = squares[i + 2];
                    pt[3] = squares[i + 3];

                    CvPoint center = new CvPoint((squares[i + 0].x + squares[i + 2].x) / 2,
                        (squares[i + 0].y + squares[i + 2].y) / 2);

                    // CvScalar color = new CvScalar(0, 255, 255);
                    CxCore.cvPolyLine(cpy, rect.Pointer, count.Pointer,
                        1, 1, CvScalar.FromRGB(255, 255, 0), 3, CxCore.CV_AA, 0);
                }

                PieceInfo[,] layout = lastLayout;
                if (layout != null)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        for (int j = 0; j < 3; j++)
                        {
                            pt[0] = new CvPoint(j * 20 + 3, i * 20 + 3);
                            pt[1] = new CvPoint(j * 20 + 3, i * 20 + 18);
                            pt[2] = new CvPoint(j * 20 + 18, i * 20 + 18);
                            pt[3] = new CvPoint(j * 20 + 18, i * 20 + 3);
                            CvScalar color = CvScalar.FromRGB(layout[i, j].color[0], layout[i, j].color[1], layout[i, j].color[2]);
                            CxCore.cvFillPoly(cpy, rect.Pointer, count.Pointer, 1, color, CxCore.CV_AA, 0);
                        }
                    }
                }

                count.Dispose();
                rect.Dispose();
                pt.Dispose();

                window.ShowImage(cpy);
            }
        }
Пример #3
0
 private static bool InPoints(CvPoint p, IList<CvPoint> points, int index, int count)
 {
     for (int j = 0; j < count; j++)
     {
         if (CvPoint.Distance2(p, points[index + j]) < 25) return true;
     }
     return false;
 }
Пример #4
0
 public static int Distance2(CvPoint p1, CvPoint p2)
 {
     int dx = p1.x - p2.x;
     int dy = p1.y - p2.y;
     return dx * dx + dy * dy;
 }