예제 #1
0
        /// <summary>
        /// generates String for point-info in Json format
        /// </summary>
        /// <param name="points"></param>
        /// <returns></returns>
        public static String PointstoJson(double[][] points, double[][] cameraPoints)
        {
            if (points != null)
            {
                int    i    = 0;
                String jSon = "{\"Items\":[";



                foreach (double[] point in points)
                {
                    // invert y axis
                    //  jSon += IRUtils.IRPointsJson(i, (width - (int)point[0]) - (width/2) , (height - (int)point[1]) - (height/2) , (int)zCoordinates[i]);
                    // no invert
                    if (point != null)
                    {
                        jSon += IRUtils.IRPointsJson(i, cameraPoints[i][0], cameraPoints[i][1], point[2]);
                        //   break;
                    }
                    else
                    {
                        jSon += IRUtils.IRPointsJsonNull(i);
                    }
                    if (i < points.Length - 1)
                    {
                        jSon += ",";
                    }

                    i++;
                }


                jSon += "]}";


                return(jSon);
            }
            else
            {
                return(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Finds connected components in the thresholded image(Binary) and draws rectangles around them
        /// returns the thesholded image if "showThesholdedImg" is true, and the non-thresholded otherwise
        /// </summary>
        /// <param name="img"></param>
        /// <param name="thresholdImg"></param>
        /// <param name="showThesholdedImg"></param>
        /// <returns></returns>
        public void TrackedData(double[][] centroidPoints)
        {
            //int minArea = Properties.UserSettings.Default.DataIndicatorMinimumArea;

            // Get Connected component in the frame



            if (centroidPoints == null)
            {
                if (mainWindow != null)
                {
                    mainWindow.StatusText = "Detected too many makers in the frame  N =" + numbOfPoints + " should be lower than " + maxPoints;
                }
                return;
            }



            // index for array
            int index;



            int i = 0;

            // if we have no previous points we add the conneted components as the tracked points
            if (screen.PrevPoints == null)
            {
                if (this.maxPoints != numbOfPoints)
                {
                    mainWindow.StatusText = "Unable to detect a r: " + rows + " c: " + cols + " grid in the image";

                    return;
                }



                double[][] orderedCentroidPoints = new double[rows * cols][];



                Array.Sort(centroidPoints, (left, right) => right[1].CompareTo(left[1]));

                int count = 0;

                for (int k = 0; k < rows; k++)
                {
                    double[][] colArray = centroidPoints.Skip(k * cols).Take(cols).ToArray();
                    Array.Sort(colArray, (left, right) => left[0].CompareTo(right[0]));

                    foreach (double[] p in colArray)
                    {
                        orderedCentroidPoints[count] = p;
                        count++;
                    }
                }



                screen.Initialize(orderedCentroidPoints);
            }
            else
            { // If we have previous points, we search for their nearest neighbours in the new frame.
              // copy previous points to new point to avoid loosing any points
              // newPoints = prevPoints;



                if (firstDetected)
                {
                    if (mainWindow != null)
                    {
                        mainWindow.StatusText = "Detected a r: " + rows + " c: " + cols + " grid in the image";
                    }


                    firstDetected = false;
                }



                // Use Hungarian algorithm to find points from the old frame, in the new frame
                int[] minInd = GetPointsIndices(centroidPoints);


                double[][] rearranged = IRUtils.RearrangeArray(centroidPoints, minInd, screen.PrevPoints.Length);



                //Update points
                foreach (double[] point in rearranged)
                {
                    if (point != null)
                    {
                        index = minInd[i] + 2;

                        // if the area is more than minArea, discard
                        if (true) // (area > minArea)
                        {
                            PointInfo pInfo = screen.PointInfo[i];
                            pInfo.Visible = true;
                        }
                    }

                    i++;
                }



                screen.UpdateScreen(rearranged);
            }
        }