Exemple #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Result"/> class.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="rawBytes">The raw bytes.</param>
 /// <param name="resultPoints">The result points.</param>
 /// <param name="format">The format.</param>
 public Result(String text,
               byte[] rawBytes,
               ResultPoint[] resultPoints,
               BarcodeFormat format)
    : this(text, rawBytes, resultPoints, format, DateTime.Now.Ticks)
 {
 }
Exemple #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Result"/> class.
 /// </summary>
 /// <param name="text">The text.</param>
 /// <param name="rawBytes">The raw bytes.</param>
 /// <param name="resultPoints">The result points.</param>
 /// <param name="format">The format.</param>
 /// <param name="timestamp">The timestamp.</param>
 public Result(String text, byte[] rawBytes, ResultPoint[] resultPoints, BarcodeFormat format, long timestamp)
 {
    if (text == null && rawBytes == null)
    {
       throw new ArgumentException("Text and bytes are null");
    }
    Text = text;
    RawBytes = rawBytes;
    ResultPoints = resultPoints;
    BarcodeFormat = format;
    ResultMetadata = null;
    Timestamp = timestamp;
 }
Exemple #3
0
        /// <summary>
        /// Orders an array of three ResultPoints in an order [A,B,C] such that AB is less than AC and
        /// BC is less than AC and the angle between BC and BA is less than 180 degrees.
        /// </summary>
        /// <param name="patterns">array of three <see cref="ResultPoint" /> to order</param>
        public static void orderBestPatterns(ResultPoint[] patterns)
        {
            // Find distances between pattern centers
            float zeroOneDistance = distance(patterns[0], patterns[1]);
            float oneTwoDistance  = distance(patterns[1], patterns[2]);
            float zeroTwoDistance = distance(patterns[0], patterns[2]);

            ResultPoint pointA, pointB, pointC;

            // Assume one closest to other two is B; A and C will just be guesses at first
            if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance)
            {
                pointB = patterns[0];
                pointA = patterns[1];
                pointC = patterns[2];
            }
            else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance)
            {
                pointB = patterns[1];
                pointA = patterns[0];
                pointC = patterns[2];
            }
            else
            {
                pointB = patterns[2];
                pointA = patterns[0];
                pointC = patterns[1];
            }

            // Use cross product to figure out whether A and C are correct or flipped.
            // This asks whether BC x BA has a positive z component, which is the arrangement
            // we want for A, B, C. If it's negative, then we've got it flipped around and
            // should swap A and C.
            if (crossProductZ(pointA, pointB, pointC) < 0.0f)
            {
                ResultPoint temp = pointA;
                pointA = pointC;
                pointC = temp;
            }

            patterns[0] = pointA;
            patterns[1] = pointB;
            patterns[2] = pointC;
        }
		private void drawLine(Canvas canvas, Paint paint, ResultPoint a, ResultPoint b) 
		{
			canvas.DrawLine(a.X, a.Y, b.X, b.Y, paint);
		}
Exemple #5
0
 /// <summary>
 /// Adds the result points.
 /// </summary>
 /// <param name="newPoints">The new points.</param>
 public void addResultPoints(ResultPoint[] newPoints)
 {
    var oldPoints = ResultPoints;
    if (oldPoints == null)
    {
       ResultPoints = newPoints;
    }
    else if (newPoints != null && newPoints.Length > 0)
    {
       var allPoints = new ResultPoint[oldPoints.Length + newPoints.Length];
       Array.Copy(oldPoints, 0, allPoints, 0, oldPoints.Length);
       Array.Copy(newPoints, 0, allPoints, oldPoints.Length, newPoints.Length);
       ResultPoints = allPoints;
    }
 }
 /// <summary>
 /// Returns the z component of the cross product between vectors BC and BA.
 /// </summary>
 private static float crossProductZ(ResultPoint pointA, ResultPoint pointB, ResultPoint pointC)
 {
    float bX = pointB.x;
    float bY = pointB.y;
    return ((pointC.x - bX) * (pointA.y - bY)) - ((pointC.y - bY) * (pointA.x - bX));
 }
 /// <summary>
 /// calculates the distance between two points
 /// </summary>
 /// <param name="pattern1">first pattern</param>
 /// <param name="pattern2">second pattern</param>
 /// <returns>
 /// distance between two points
 /// </returns>
 public static float distance(ResultPoint pattern1, ResultPoint pattern2)
 {
    return MathUtils.distance(pattern1.x, pattern1.y, pattern2.x, pattern2.y);
 }
      /// <summary>
      /// Orders an array of three ResultPoints in an order [A,B,C] such that AB is less than AC and
      /// BC is less than AC and the angle between BC and BA is less than 180 degrees.
      /// </summary>
      /// <param name="patterns">array of three <see cref="ResultPoint" /> to order</param>
      public static void orderBestPatterns(ResultPoint[] patterns)
      {
         // Find distances between pattern centers
         float zeroOneDistance = distance(patterns[0], patterns[1]);
         float oneTwoDistance = distance(patterns[1], patterns[2]);
         float zeroTwoDistance = distance(patterns[0], patterns[2]);

         ResultPoint pointA, pointB, pointC;
         // Assume one closest to other two is B; A and C will just be guesses at first
         if (oneTwoDistance >= zeroOneDistance && oneTwoDistance >= zeroTwoDistance)
         {
            pointB = patterns[0];
            pointA = patterns[1];
            pointC = patterns[2];
         }
         else if (zeroTwoDistance >= oneTwoDistance && zeroTwoDistance >= zeroOneDistance)
         {
            pointB = patterns[1];
            pointA = patterns[0];
            pointC = patterns[2];
         }
         else
         {
            pointB = patterns[2];
            pointA = patterns[0];
            pointC = patterns[1];
         }

         // Use cross product to figure out whether A and C are correct or flipped.
         // This asks whether BC x BA has a positive z component, which is the arrangement
         // we want for A, B, C. If it's negative, then we've got it flipped around and
         // should swap A and C.
         if (crossProductZ(pointA, pointB, pointC) < 0.0f)
         {
            ResultPoint temp = pointA;
            pointA = pointC;
            pointC = temp;
         }

         patterns[0] = pointA;
         patterns[1] = pointB;
         patterns[2] = pointC;
      }
 public QrCodeDataParticle(ResultPoint[] resultPoints, int id, Color startColor, Color endColor)
     : base(resultPoints, id)
 {
     _startColor = startColor;
     _endColor = endColor;
 }
Exemple #10
0
 /// <summary>
 /// calculates the distance between two points
 /// </summary>
 /// <param name="pattern1">first pattern</param>
 /// <param name="pattern2">second pattern</param>
 /// <returns>
 /// distance between two points
 /// </returns>
 public static float distance(ResultPoint pattern1, ResultPoint pattern2)
 {
     return(MathUtils.distance(pattern1.x, pattern1.y, pattern2.x, pattern2.y));
 }
 public QrCodeDataCoin(ResultPoint[] resultPoints, int id)
     : base(resultPoints, id)
 {
 }
 private void OnResultPointFound(ResultPoint resultPoint)
 {
    if (explicitResultPointFound != null)
    {
       explicitResultPointFound(this, resultPoint);
    }
 }
 /// <summary>
 /// Constructs a QrCodeData object.
 /// </summary>
 /// <param name="resultPoints">Result points detected by ZXing</param>
 /// <param name="id">Id of QR-code</param>
 public QrCodeData(ResultPoint[] resultPoints, int id)
 {
     _target = resultPoints;
     Id = id;
     _time = DateTime.UtcNow;
 }
 /// <summary>
 /// Update the position of the object through new <see cref="ResultPoint"/>s. Also resets the timers used to detroy the object.
 /// </summary>
 /// <param name="newResultPoints">Newly detected QR-code position</param>
 public void Update(ResultPoint[] newResultPoints)
 {
     _target = newResultPoints;
     _time = DateTime.UtcNow;
     _destroyTime = DateTime.MinValue;
 }
Exemple #15
0
 /// <summary>
 /// Adds the result points.
 /// </summary>
 /// <param name="newPoints">The new points.</param>
 public void addResultPoints([System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray] ResultPoint[] newPoints)
 {
    var oldPoints = ResultPoints;
    if (oldPoints == null)
    {
       ResultPoints = newPoints;
    }
    else if (newPoints != null && newPoints.Length > 0)
    {
       var allPoints = new ResultPoint[oldPoints.Length + newPoints.Length];
       Array.Copy(oldPoints, 0, allPoints, 0, oldPoints.Length);
       Array.Copy(newPoints, 0, allPoints, oldPoints.Length, newPoints.Length);
       ResultPoints = allPoints;
    }
 }