示例#1
0
文件: SunoLogic.cs 项目: novatia/SUNO
        public Bitmap renderSunoPreview(TrajectorySet ts, int susanCornerPixelRadius, int houghLineWidth, Boolean susanRender, Boolean houghRender, Boolean blackRender, Boolean trajectoryPointsRender)
        {
            HoughLineTransformation lineTransform = ts.lineTransform;

            HoughLine[]     lines   = ts.lines;
            List <IntPoint> corners = ts.corners;

            Bitmap image = AForge.Imaging.Image.Clone(ts.image, PixelFormat.Format24bppRgb);

            Graphics g = Graphics.FromImage(image);

            if (susanRender)
            {
                foreach (IntPoint corner in corners)
                {
                    g.FillEllipse(new SolidBrush(Color.Red), corner.X, corner.Y, susanCornerPixelRadius, susanCornerPixelRadius);
                }
            }


            if (blackRender)
            {
                foreach (System.Drawing.Point current_point in ts.black_points)
                {
                    g.FillEllipse(new SolidBrush(Color.Yellow), current_point.X, current_point.Y, susanCornerPixelRadius, susanCornerPixelRadius);
                }
            }

            if (trajectoryPointsRender)
            {
                foreach (System.Drawing.Point current_point in ts.trajectory_points)
                {
                    g.FillEllipse(new SolidBrush(Color.Coral), current_point.X, current_point.Y, susanCornerPixelRadius, susanCornerPixelRadius);
                }
            }



            BitmapData sourceData = image.LockBits(
                new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.ReadOnly, image.PixelFormat);

            if (houghRender)
            {
                foreach (HoughLine line in lines)
                {
                    drawHoughLine(line, image, sourceData, houghLineWidth);
                }
            }
            image.UnlockBits(sourceData);
            return(image);
        }
示例#2
0
        static void Main(string[] args)
        {
            TrajectorySet newSet = new TrajectorySet("gnss_point.csv", new NewTrajectorySetCreator(), CoordinateGenerator.CRSParseFromEPSG(4326));

            IShapefile roadShapefile = VectorFactory.OpenShapefile("road.shp", VectorOpenMode.Common);

            IMapMatch mapMatchFunction = new HMMMapMatch(roadShapefile, 0.000173);

            IMapMatch mapMatchFunction2 = new HMMMapMatch(roadShapefile, 0.000173, roadShapefile.GetBoundaryBox(), "Direction");

            TrajectorySet matchedSet = new TrajectorySet();

            foreach (Trajectory trajectory in newSet.TrajectoryList)
            {
                Trajectory mapMatchedTrajectory = mapMatchFunction.MatchRoute(trajectory, 0.000173 * 2, 10);

                matchedSet.AddTrajectory(mapMatchedTrajectory);
            }

            IShapefile matchedShapefile = matchedSet.ExportToShapefile(CoordinateGenerator.CRSParseFromEPSG(4326));

            matchedShapefile.ExportShapefile("matchedTrajectory2.shp");
        }
示例#3
0
        public static void InitCamera(model.WIACamera camera, String iso, String exposure, ref TrajectorySet ts)
        {
            ts.ISO = "" + iso;
            ts.EXP = "" + exposure;

            InitCamera(camera, iso, exposure);
        }
示例#4
0
        public static Image TakePicture(model.WIACamera camera, ref TrajectorySet ts)
        {
            ts.shot_time = DateTime.Now;

            return(TakePicture(camera));
        }
示例#5
0
文件: SunoLogic.cs 项目: novatia/SUNO
        public TrajectorySet CalculateDiscontinuityPoints(TrajectorySet ts, int lineScanThreshold, int lineScanRadius, int radialThreshold, Boolean geometrical)
        {
            //foreach hough line
            foreach (HoughLine line in ts.lines)
            {
                int    r = line.Radius;
                double t = line.Theta;

                // check if line is in lower part of the image
                if (r < 0)
                {
                    t += 180;
                    r  = -r;
                }

                // convert degrees to radians
                t = (t / 180) * Math.PI;

                // get image centers (all coordinate are measured relative
                // to center)
                int w2 = ts.image.Width / 2;
                int h2 = ts.image.Height / 2;

                double x0 = 0, x1 = 0, y0 = 0, y1 = 0;

                if (line.Theta != 0)
                {
                    // none vertical line
                    x0 = -w2; // most left point
                    x1 = w2;  // most right point

                    // calculate corresponding y values
                    y0 = (-Math.Cos(t) * x0 + r) / Math.Sin(t);
                    y1 = (-Math.Cos(t) * x1 + r) / Math.Sin(t);
                }
                else
                {
                    // vertical line
                    x0 = line.Radius;
                    x1 = line.Radius;

                    y0 = h2;
                    y1 = -h2;
                }

                int X0, Y0, X1, Y1;

                X0 = (int)x0 + w2;
                Y0 = h2 - (int)y0;
                X1 = (int)x1 + w2;
                Y1 = h2 - (int)y1;

                PlotFunction plot = AddPlotPoint;
                Line((int)X0, (int)Y0, (int)X1, (int)Y1, plot);

                double R = -((double)Y1 - (double)Y0) / ((double)X1 - (double)X0);

                ts.bresenhamsLines.Add(current_line_points);

                List <System.Drawing.Point> black_points = new List <System.Drawing.Point>();
                int          end_segments       = 10;
                Boolean      start_segment      = false;
                BlackSegment current_segment    = new BlackSegment();
                int          segment_tollerance = 10;

                foreach (System.Drawing.Point current in current_line_points)
                {
                    //get pixel neighbours average colour
                    double average;
                    if (geometrical)
                    {
                        average = GetNeightbourAveragePixelColor(ts.elaborated_image, current, lineScanRadius);
                    }
                    else
                    {
                        average = GetNeightbourAveragePixelColor(ts.elaborated_image, current, lineScanRadius, R);
                    }

                    if (average > lineScanThreshold)
                    {
                        if (!start_segment)
                        {
                            current_segment.start = current;
                            start_segment         = true;
                        }
                        black_points.Add(current);
                    }
                    else
                    {
                        if (start_segment)
                        {
                            segment_tollerance--;

                            if (segment_tollerance <= 0)
                            {
                                current_segment.end = current;
                                start_segment       = false;
                                ts.black_segments.Add(current_segment);
                                current_segment    = new BlackSegment();
                                segment_tollerance = 10;
                            }
                        }
                    }
                }

                current_line_points = new List <System.Drawing.Point>();
                ts.black_points     = new List <System.Drawing.Point>(black_points);

                //foreach segment check the size and get the central pixel
                foreach (BlackSegment current in ts.black_segments)
                {
                    if (geometrical)
                    {
                        /* Algoritmo basato su punto medio dei segmenti
                         * restituisce alcuni falsi positivi a causa dell'imprecisione introdotta dal calcolo della media dei punti
                         * inoltre non restituisce i punti esatti intermedi della discontinuità.*/

                        int len = SunoLogic.distanceBetween2Points(current.start, current.end);

                        int     mid_len = len / 2;
                        Boolean start   = false;
                        foreach (System.Drawing.Point current_point in ts.black_points)
                        {
                            if (current_point.X == current.start.X && current_point.Y == current.start.Y)
                            {
                                start = true;
                            }

                            if (start)
                            {
                                mid_len--;
                                if (mid_len <= 0)
                                {
                                    ts.trajectory_points.Add(current_point);
                                    start = false;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        List <System.Drawing.Point> start_neightbour = new List <System.Drawing.Point>();
                        List <System.Drawing.Point> end_neightbour   = new List <System.Drawing.Point>();

                        foreach (IntPoint current_corner in ts.corners)
                        {
                            System.Drawing.Point current_corner_point = new System.Drawing.Point(current_corner.X, current_corner.Y);

                            //check start points
                            int distance_from_start = SunoLogic.distanceBetween2Points(current_corner_point, current.start);

                            if (distance_from_start - radialThreshold <= 0)
                            {
                                start_neightbour.Add(current_corner_point);
                            }

                            int distance_from_end = SunoLogic.distanceBetween2Points(current_corner_point, current.end);

                            if (distance_from_end - radialThreshold <= 0)
                            {
                                end_neightbour.Add(current_corner_point);
                            }
                        }

                        int ts_x = 0, ts_y = 0, te_x = 0, te_y = 0;
                        int count = 0;

                        foreach (System.Drawing.Point current_pount in start_neightbour)
                        {
                            //media tra le coordinate X dello start
                            //media tra le coordinate Y dello start
                            ts_x += current_pount.X;
                            ts_y += current_pount.Y;

                            count++;
                        }

                        if (count == 0)
                        {
                            ts_x = current.start.X;
                            ts_y = current.start.Y;
                        }
                        else
                        {
                            ts_x /= count;
                            ts_y /= count;
                        }
                        count = 0;

                        foreach (System.Drawing.Point current_pount in end_neightbour)
                        {
                            //media tra le coordinate X dell'end
                            //media tra le coordinate Y dell'end

                            te_x += current_pount.X;
                            te_y += current_pount.Y;

                            count++;
                        }

                        if (count == 0)
                        {
                            te_x = current.end.X;
                            te_y = current.end.Y;
                        }
                        else
                        {
                            te_x /= count;
                            te_y /= count;
                        }

                        //calculate segment lenght
                        System.Drawing.Point mid = SunoLogic.midPoint(new System.Drawing.Point(ts_x, ts_y), new System.Drawing.Point(te_x, te_y));

                        //add point
                        ts.trajectory_points.Add(mid);
                    }
                }
            }

            return(ts);
        }
示例#6
0
文件: SunoLogic.cs 项目: novatia/SUNO
 public NeighbourQuadrantList GetNeighbourQuadrantList(TrajectorySet img)
 {
     return(null);
 }
示例#7
0
文件: SunoLogic.cs 项目: novatia/SUNO
        public TrajectorySet CalculateTrajectorySet(Bitmap image, Double HoughRelativeIntensity, Int32 SusanCornerDifferenceTreshold, Int32 SusanCornerGeometricalTreshold, Int32 lineScanThreshold, Int32 lineScanRadius, Int32 radialThreshold, Boolean geometrical)
        {
            TrajectorySet ts = new TrajectorySet();

            ts.elaboration_start_time = DateTime.Now;

            Bitmap hough_image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb);
            Bitmap susan_image = AForge.Imaging.Image.Clone(image, PixelFormat.Format24bppRgb);

            // AForge.Imaging.Image.FormatImage(ref hough_image);
            // AForge.Imaging.Image.FormatImage(ref susan_image);

            //FILTERS AND SOURCE INIT
            hough_image = Grayscale.CommonAlgorithms.RMY.Apply(hough_image);
            susan_image = Grayscale.CommonAlgorithms.RMY.Apply(susan_image);

            hough_image = ApplyFilter(hough_image, new Threshold());
            susan_image = ApplyFilter(susan_image, new Threshold());



            //INIT OBJECTS


            HoughLineTransformation lineTransform  = new HoughLineTransformation();
            SusanCornersDetector    susanTransform = new SusanCornersDetector(SusanCornerDifferenceTreshold, SusanCornerGeometricalTreshold);

            FiltersSequence filter = new FiltersSequence(
                Grayscale.CommonAlgorithms.BT709,
                new Threshold(64)
                );

            //APPLY ALGOS AND GET ENTITIES
            BitmapData houghSourceData = hough_image.LockBits(
                new Rectangle(0, 0, hough_image.Width, hough_image.Height),
                ImageLockMode.ReadOnly, hough_image.PixelFormat);

            lineTransform.ProcessImage(houghSourceData);


            hough_image.UnlockBits(houghSourceData);
            ts.elaborated_image = AForge.Imaging.Image.Clone(hough_image, PixelFormat.Format24bppRgb);;
            hough_image.Dispose();

            HoughLine[] lines = lineTransform.GetLinesByRelativeIntensity(HoughRelativeIntensity);

            BitmapData sousanSourceData = susan_image.LockBits(
                new Rectangle(0, 0, susan_image.Width, susan_image.Height),
                ImageLockMode.ReadOnly, susan_image.PixelFormat);

            List <IntPoint> corners = susanTransform.ProcessImage(sousanSourceData);

            susan_image.UnlockBits(sousanSourceData);
            susan_image.Dispose();

            //populat trajectoryset
            ts.image          = image;
            ts.lineTransform  = lineTransform;
            ts.lines          = lines;
            ts.susanTransform = susanTransform;
            ts.corners        = corners;

            //get discontinuity points
            this.CalculateDiscontinuityPoints(ts, lineScanThreshold, lineScanRadius, radialThreshold, geometrical);

            //get trajectory lines (W=3)

            //get trajectory lines (W=2)

            //get trajectory lines (W=1)

            //get quadrant foreach lines W=3, W=2, W=1
            ts.elaboration_end_time = DateTime.Now;

            return(ts);
        }