private void CreateLinesFromPointCloud(VectorImage image, VectorCloud2D cloud) { for (int i = 0; i < cloud.Count - 1; i++) { image.Add(new Line2D(cloud[i], cloud[i + 1])); } }
public static void PointInTriangleTest(VectorImage image) { Triangle2D t = new Triangle2D(new Vector2D(25, 150), new Vector2D(200, 200), new Vector2D(60, 80)); image.Add(t); VectorCloud2D pc = PointCloudCreator.Create(new Rectangle2D(new Vector2D(10, 10), new Vector2D(300, 300)), 500); pc.Add(t.a); pc.Add(t.b); pc.Add(t.c); foreach (Vector2D p in pc) { p.SetData(new PrimitiveRenderData(t.IsInside(p) ? Color.DarkGreen : Color.DarkRed)); } image.Add(pc); }
private static void MakeShapesFromSectors(VectorImage image, Dictionary <int, List <Line2D> > sectors) { foreach (KeyValuePair <int, List <Line2D> > lines in sectors) { Shape2D shape = Shape2DFunctions.CreateShapesFromLines(lines.Value); PrimitiveRenderData.Get(shape).Text = "Sector: " + lines.Key; image.Add(shape); } }
private void ReadGeometry(WkbStreamReader wkbReader, VectorImage image) { int geometryType = wkbReader.ReadInt32(); int dimensionRaw = geometryType / 1000; int geoType = geometryType - (dimensionRaw * 1000); wkbReader.Dimension = 2; if (dimensionRaw == 1) { wkbReader.Dimension = 3; } if (dimensionRaw == 2) { wkbReader.Dimension = 3; } if (dimensionRaw == 3) { wkbReader.Dimension = 4; } int numPoints = -1; switch (geoType) { case 1: image.Add(wkbReader.ReadPoint()); break; case 2: numPoints = wkbReader.ReadInt32(); CreateLinesFromPointCloud(image, wkbReader.ReadPointCloud(numPoints)); break; case 3: int numRings = wkbReader.ReadInt32(); for (int i = 0; i < numRings; i++) { numPoints = wkbReader.ReadInt32(); image.Add(new Shape2D(wkbReader.ReadPointCloud(numPoints))); } break; } /*geoType * Geometry 00 * Point 01 * LineString 02 * Polygon 03 * MultiPoint 04 * MultiLineString 05 * MultiPolygon 06 * GeometryCollection 07 * CircularString 08 * CompoundCurve 09 * CurvePolygon 10 * MultiCurve 11 * MultiSurface 12 * Curve 13 * Surface 14 * PolyhedralSurface 15 * TIN 16 * Triangle 17 */ }
/// <summary> /// Finds and classifies detections for all frames in a video. /// </summary> /// <param name="detect_path">Path to detect model file.</param> /// <param name="classify_path">Path to classify model file.</param> /// <param name="roi">Region of interest output from FindVideoRoi.</param> /// <param name="endpoints">Ruler endpoints output from FindVideoRoi.</param> /// <param name="detections">Detections for each frame.</param> /// <param name="scores">Cover and species scores for each detection.</param> static void DetectAndClassify( string detect_path, string classify_path, string vid_path, Rect roi, PointPair endpoints, out VectorVectorDetection detections, out VectorVectorClassification scores) { // Determined by experimentation with GPU having 8GB memory. const int kMaxImg = 32; // Initialize the outputs. detections = new VectorVectorDetection(); scores = new VectorVectorClassification(); // Create and initialize the detector. Detector detector = new Detector(); ErrorCode status = detector.Init(detect_path, 0.5); if (status != ErrorCode.kSuccess) { throw new Exception("Failed to initialize detector!"); } // Create and initialize the classifier. Classifier classifier = new Classifier(); status = classifier.Init(classify_path, 0.5); if (status != ErrorCode.kSuccess) { throw new Exception("Failed to initialize classifier!"); } // Initialize the video reader. VideoReader reader = new VideoReader(); status = reader.Init(vid_path); if (status != ErrorCode.kSuccess) { throw new Exception("Failed to open video!"); } // Iterate through frames. bool vid_end = false; while (true) { // Find detections. VectorVectorDetection dets = new VectorVectorDetection(); VectorImage imgs = new VectorImage(); for (int i = 0; i < kMaxImg; ++i) { Image img = new Image(); status = reader.GetFrame(img); if (status != ErrorCode.kSuccess) { vid_end = true; break; } img = openem.Rectify(img, endpoints); img = openem.Crop(img, roi); imgs.Add(img); status = detector.AddImage(img); if (status != ErrorCode.kSuccess) { throw new Exception("Failed to add frame to detector!"); } } status = detector.Process(dets); if (status != ErrorCode.kSuccess) { throw new Exception("Failed to process detector!"); } for (int i = 0; i < dets.Count; ++i) { } detections.AddRange(dets); for (int i = 0; i < detections.Count; ++i) { } // Classify detections. for (int i = 0; i < dets.Count; ++i) { VectorClassification score_batch = new VectorClassification(); for (int j = 0; j < dets[i].Count; ++j) { Image det_img = openem.GetDetImage(imgs[i], dets[i][j].location); status = classifier.AddImage(det_img); if (status != ErrorCode.kSuccess) { throw new Exception("Failed to add frame to classifier!"); } } status = classifier.Process(score_batch); if (status != ErrorCode.kSuccess) { throw new Exception("Failed to process classifier!"); } scores.Add(score_batch); } if (vid_end) { break; } } }
/// <summary> /// Main program. /// </summary> static int Main(string[] args) { // Check input arguments. if (args.Length < 2) { Console.WriteLine("Expected at least two arguments:"); Console.WriteLine(" Path to protobuf file containing model"); Console.WriteLine(" Paths to one or more image files"); return(-1); } // Create and initialize detector. Detector detector = new Detector(); ErrorCode status = detector.Init(args[0]); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to initialize detector!"); return(-1); } // Load in images. VectorImage imgs = new VectorImage(); for (int i = 1; i < args.Length; i++) { Image img = new Image(); status = img.FromFile(args[i]); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to load image {0}!", args[i]); return(-1); } imgs.Add(img); } // Add images to processing queue. foreach (var img in imgs) { status = detector.AddImage(img); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to add image for processing!"); return(-1); } } // Process the loaded images. VectorVectorDetection detections = new VectorVectorDetection(); status = detector.Process(detections); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to process images!"); return(-1); } // Display the detections on the image. for (int i = 0; i < detections.Count; ++i) { foreach (var det in detections[i]) { imgs[i].DrawRect(det.location); } imgs[i].Show(); } return(0); }
/// <summary> /// Main program. /// </summary> static int Main(string[] args) { // Check input arguments. if (args.Length < 2) { Console.WriteLine("Expected at least two arguments:"); Console.WriteLine(" Path to protobuf file containing model"); Console.WriteLine(" Paths to one or more image files"); return(-1); } // Create and initialize the mask finder. RulerMaskFinder mask_finder = new RulerMaskFinder(); ErrorCode status = mask_finder.Init(args[0]); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to initialize ruler mask finder!"); return(-1); } // Load in images. VectorImage imgs = new VectorImage(); for (int i = 1; i < args.Length; i++) { Image img = new Image(); status = img.FromFile(args[i]); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to load image {0}!", args[i]); return(-1); } imgs.Add(img); } // Add images to processing queue. foreach (var img in imgs) { status = mask_finder.AddImage(img); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to add image for processing!"); return(-1); } } // Process the loaded images. VectorImage masks = new VectorImage(); status = mask_finder.Process(masks); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to process images!"); return(-1); } for (int i = 0; i < masks.Count; ++i) { // Resize the masks back into the same size as the images. masks[i].Resize(imgs[i].Width(), imgs[i].Height()); // Check if the ruler is present. bool present = openem.RulerPresent(masks[i]); if (!present) { Console.WriteLine("Could not find ruler in image! Skipping..."); continue; } // Find orientation and region of interest based on the mask. PointPair endpoints = new PointPair(); endpoints = openem.RulerEndpoints(masks[i]); Image r_mask = openem.Rectify(masks[i], endpoints); Rect roi = openem.FindRoi(r_mask); // Rectify, crop, and display the image. Image r_img = openem.Rectify(imgs[i], endpoints); Image c_img = openem.Crop(r_img, roi); c_img.Show(); } return(0); }
/// <summary> /// Main program. /// </summary> static int Main(string[] args) { // Check input arguments. if (args.Length < 2) { Console.WriteLine("Expected at least two arguments:"); Console.WriteLine(" Path to protobuf file containing model"); Console.WriteLine(" Paths to one or more image files"); return(-1); } // Create and initialize classifier. Classifier classifier = new Classifier(); ErrorCode status = classifier.Init(args[0]); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to initialize classifier!"); return(-1); } // Load in images. VectorImage imgs = new VectorImage(); PairIntInt img_size = classifier.ImageSize(); for (int i = 1; i < args.Length; i++) { Image img = new Image(); status = img.FromFile(args[i]); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to load image {0}!", args[i]); return(-1); } img.Resize(img_size.first, img_size.second); imgs.Add(img); } // Add images to processing queue. foreach (var img in imgs) { status = classifier.AddImage(img); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to add image for processing!"); return(-1); } } // Process the loaded images. VectorClassification scores = new VectorClassification(); status = classifier.Process(scores); if (status != ErrorCode.kSuccess) { Console.WriteLine("Failed to process images!"); return(-1); } // Display the images and print scores to console. for (int i = 0; i < scores.Count; ++i) { Console.WriteLine("*******************************************"); Console.WriteLine("Fish cover scores:"); Console.WriteLine("No fish: {0}", scores[i].cover[0]); Console.WriteLine("Hand over fish: {0}", scores[i].cover[1]); Console.WriteLine("Fish clear: {0}", scores[i].cover[2]); Console.WriteLine("*******************************************"); Console.WriteLine("Fish species scores:"); Console.WriteLine("Fourspot: {0}", scores[i].species[0]); Console.WriteLine("Grey sole: {0}", scores[i].species[1]); Console.WriteLine("Other: {0}", scores[i].species[2]); Console.WriteLine("Plaice: {0}", scores[i].species[3]); Console.WriteLine("Summer: {0}", scores[i].species[4]); Console.WriteLine("Windowpane: {0}", scores[i].species[5]); Console.WriteLine("Winter: {0}", scores[i].species[6]); Console.WriteLine(""); imgs[i].Show(); } return(0); }