private float CalculateUnitsPerPixel(CameraVsPhysicalPoint neighbor)
		{
			float physicalDistance = (float)Math.Sqrt(
				(neighbor.PhysicalPoint.X - this.PhysicalPoint.X) * (neighbor.PhysicalPoint.X - this.PhysicalPoint.X) +
				(neighbor.PhysicalPoint.Y - this.PhysicalPoint.Y) * (neighbor.PhysicalPoint.Y - this.PhysicalPoint.Y));

			float pixelDistance = (float)Math.Sqrt(
				(neighbor.CameraPoint.X - this.CameraPoint.X) * (neighbor.CameraPoint.X - this.CameraPoint.X) +
				(neighbor.CameraPoint.Y - this.CameraPoint.Y) * (neighbor.CameraPoint.Y - this.CameraPoint.Y));

			return physicalDistance / pixelDistance;
		}
Exemplo n.º 2
0
        private float CalculateUnitsPerPixel(CameraVsPhysicalPoint neighbor)
        {
            float physicalDistance = (float)Math.Sqrt(
                (neighbor.PhysicalPoint.X - this.PhysicalPoint.X) * (neighbor.PhysicalPoint.X - this.PhysicalPoint.X) +
                (neighbor.PhysicalPoint.Y - this.PhysicalPoint.Y) * (neighbor.PhysicalPoint.Y - this.PhysicalPoint.Y));

            float pixelDistance = (float)Math.Sqrt(
                (neighbor.CameraPoint.X - this.CameraPoint.X) * (neighbor.CameraPoint.X - this.CameraPoint.X) +
                (neighbor.CameraPoint.Y - this.CameraPoint.Y) * (neighbor.CameraPoint.Y - this.CameraPoint.Y));

            return(physicalDistance / pixelDistance);
        }
Exemplo n.º 3
0
 public CalibrationPoint(
     CameraVsPhysicalPoint center,
     CameraVsPhysicalPoint left,
     CameraVsPhysicalPoint right,
     CameraVsPhysicalPoint above,
     CameraVsPhysicalPoint below)
 {
     this.CameraPoint    = center.CameraPoint;
     this.PhysicalPoint  = center.PhysicalPoint;
     this.UnitsPerPixelX = CalculateUnitsPerPixelX(left, right);
     this.UnitsPerPixelY = CalculateUnitsPerPixelY(above, below);
 }
		public CalibrationPoint(
			CameraVsPhysicalPoint center,
			CameraVsPhysicalPoint left,
			CameraVsPhysicalPoint right,
			CameraVsPhysicalPoint above,
			CameraVsPhysicalPoint below)
		{
			this.CameraPoint = center.CameraPoint;
			this.PhysicalPoint = center.PhysicalPoint;
			this.UnitsPerPixelX = CalculateUnitsPerPixelX(left, right);
			this.UnitsPerPixelY = CalculateUnitsPerPixelY(above, below);
		}
		public CameraVsPhysicalPoint[,] GetCameraVsPhysicalPoints()
		{
			CameraVsPhysicalPoint[,] cameraVsPhysicalPoints = new CameraVsPhysicalPoint[this.XCount, this.YCount];
			for (int i = 0; i < this.XCount; i++)
			{
				for (int j = 0; j < this.YCount; j++)
				{
					PointF physicalCenter = GetPhysicalCenter(i, j);
					MCvBox2D box = m_InsideRectangles[i, j];

					cameraVsPhysicalPoints[i, j] = new CameraVsPhysicalPoint(
						box.center,
						physicalCenter);
				}
			}

			return cameraVsPhysicalPoints;
		}
        public CameraVsPhysicalPoint[,] GetCameraVsPhysicalPoints()
        {
            CameraVsPhysicalPoint[,] cameraVsPhysicalPoints = new CameraVsPhysicalPoint[this.XCount, this.YCount];
            for (int i = 0; i < this.XCount; i++)
            {
                for (int j = 0; j < this.YCount; j++)
                {
                    PointF   physicalCenter = GetPhysicalCenter(i, j);
                    MCvBox2D box            = m_InsideRectangles[i, j];

                    cameraVsPhysicalPoints[i, j] = new CameraVsPhysicalPoint(
                        box.center,
                        physicalCenter);
                }
            }

            return(cameraVsPhysicalPoints);
        }
Exemplo n.º 7
0
        private float CalculateUnitsPerPixelY(CameraVsPhysicalPoint above, CameraVsPhysicalPoint below)
        {
            // above or below but not both can be null
            float pointsUsed     = 0;
            float unitsPerPixelY = 0;

            if (above != null)
            {
                pointsUsed     += 1;
                unitsPerPixelY += CalculateUnitsPerPixel(above);
            }
            if (below != null)
            {
                pointsUsed     += 1;
                unitsPerPixelY += CalculateUnitsPerPixel(below);
            }

            return(unitsPerPixelY / pointsUsed);
        }
Exemplo n.º 8
0
        private float CalculateUnitsPerPixelX(CameraVsPhysicalPoint left, CameraVsPhysicalPoint right)
        {
            // left or right but not both can be null
            float pointsUsed     = 0;
            float unitsPerPixelX = 0;

            if (left != null)
            {
                pointsUsed     += 1;
                unitsPerPixelX += CalculateUnitsPerPixel(left);
            }
            if (right != null)
            {
                pointsUsed     += 1;
                unitsPerPixelX += CalculateUnitsPerPixel(right);
            }

            return(unitsPerPixelX / pointsUsed);
        }
		private float CalculateUnitsPerPixelX(CameraVsPhysicalPoint left, CameraVsPhysicalPoint right)
		{
			// left or right but not both can be null
			float pointsUsed = 0;
			float unitsPerPixelX = 0;

			if (left != null)
			{
				pointsUsed += 1;
				unitsPerPixelX += CalculateUnitsPerPixel(left);
			}
			if (right != null)
			{
				pointsUsed += 1;
				unitsPerPixelX += CalculateUnitsPerPixel(right);
			}

			return unitsPerPixelX / pointsUsed;
		}
		public void Initialize(CameraVsPhysicalPoint[,] cameraVsPhysicalPoints)
		{
			m_XCount = cameraVsPhysicalPoints.GetLength(0);
			m_YCount = cameraVsPhysicalPoints.GetLength(1);
			m_CalibrationPoints = new CalibrationPoint[m_XCount, m_YCount];

			CameraVsPhysicalPoint center, left, right, above, below;

			for (int i = 0; i < m_XCount; i++)
			{
				for (int j = 0; j < m_YCount; j++)
				{
					center = cameraVsPhysicalPoints[i,j];
					left = (i == 0 ? null : cameraVsPhysicalPoints[i - 1, j]);
					right = (i == m_XCount - 1 ? null : cameraVsPhysicalPoints[i + 1, j]);
					above = (j == 0 ? null : cameraVsPhysicalPoints[i, j - 1]);
					below = (j == m_YCount - 1 ? null : cameraVsPhysicalPoints[i, j + 1]);

					m_CalibrationPoints[i, j] = new CalibrationPoint(center, left, right, above, below);
				}
			}
		}
		private float CalculateUnitsPerPixelY(CameraVsPhysicalPoint above, CameraVsPhysicalPoint below)
		{
			// above or below but not both can be null
			float pointsUsed = 0;
			float unitsPerPixelY = 0;

			if (above != null)
			{
				pointsUsed += 1;
				unitsPerPixelY += CalculateUnitsPerPixel(above);
			}
			if (below != null)
			{
				pointsUsed += 1;
				unitsPerPixelY += CalculateUnitsPerPixel(below);
			}

			return unitsPerPixelY / pointsUsed;
		}
		private void Print(CameraVsPhysicalPoint[,] cameraVsPhysicalPoints)
		{
			int xCount = cameraVsPhysicalPoints.GetLength(0);
			int yCount = cameraVsPhysicalPoints.GetLength(1);

			Debug.WriteLine("---- cameraVsPhysicalPoints ----");
			for (int i = 0; i < xCount; i++)
			{
				for (int j = 0; j < yCount; j++)
				{
					CameraVsPhysicalPoint point = cameraVsPhysicalPoints[i,j];
					string line = String.Format(
						"{0},{1}   {2:###},{3:###}   {4:###},{5:###}",
						i, j, point.PhysicalPoint.X, point.PhysicalPoint.Y, point.CameraPoint.X, point.CameraPoint.Y);
					Debug.WriteLine(line);
				}
			}
		}