private static bool WriteLineLog(ref HelixSoloSensor sensor, HelixImage image, string resultFolder)
        {
            List <string> logLines = new List <string>();

            logLines.AddRange(new string[] { $"{sensor.SerialNumber}\t{sensor.PartNumber}\t{sensor.Date}", image.Name,
                                             "CG_Row\tCG_Col\tWidth\tPeak_Intensity\tFocus_Score" });
            if (image.CGs.Count > 0)
            {
                foreach (CGInfo cg in image.CGs)
                {
                    logLines.Add(cg.ToString());
                }
                logLines.AddRange(new string[] {
                    $"\nCG Count:\t{image.CGs.Count}\n",
                    $"CG Avg:\t{image.CgAverages.Item2}",
                    $"CG Avg Left:\t{image.CgAverages.Item1}",
                    $"CG Avg Right:\t{image.CgAverages.Item3}\n",
                    $"Width Avg:\t{image.WidthAverages.Item2}",
                    $"Width Avg Left:\t{image.WidthAverages.Item1}",
                    $"Width Avg Right:\t{image.WidthAverages.Item3}\n",
                    $"Line Angle Degrees:\t{image.LineAngle}\n",
                    $"Line Focus Score:\t{image.FocusScore}"
                });
            }
            else
            {
                logLines.Add("\nNo laser line found");
            }

            string path = Path.Join(resultFolder, $"{Path.GetFileNameWithoutExtension(image.Name)}.txt");

            File.WriteAllLines(path, logLines);
            return(true);
        }
Ejemplo n.º 2
0
        private static Dictionary<string,int[]> GetStaringDotBox(string z, ref List<string> images)
        {
            Dictionary<string, int[]> box = new Dictionary<string, int[]>() 
            { 
                { "tr", new int[2]{ 0,1200} },
                { "bl", new int[2]{ 1600,0} },
            };
            HelixImage image1 = null;
            HelixImage image2 = null;
            foreach(string img in images) //Get 2 different images of same z value
            {
                string zValue = GetImageZValue(img);
                if (zValue == z && Path.GetFileNameWithoutExtension(img).Contains("A0"))
                {
                    if (image1 == null) { image1 = new HelixImage(img); }
                    else if (Path.GetFileNameWithoutExtension(img) != image1.Name && image2 == null) { image2 = new HelixImage(img); break; }
                }
            }
            IPixelCollection<byte> img1Pixels = image1.Magick.GetPixels();
            IPixelCollection<byte> img2Pixels = image2.Magick.GetPixels();
            box["tr"][1] = image1.Magick.Height;
            box["bl"][0] = image1.Magick.Width;

            int intensityThreshold = (int)(255f * Config.StaringDotSensitivityPercent);
            int xStart = (int)((Config.StaringDotExcludeXPercent * image1.Magick.Width) / 2);
            int xEnd = image1.Magick.Width - xStart;
            int yStart = (int)((Config.StaringDotExcludeYPercent * image1.Magick.Height) / 2);
            int yEnd = image1.Magick.Height - yStart;

            //Create coords for box corners
            for (int x = xStart; x < xEnd; x++)
            {
                for (int y = yStart; y < yEnd; y++)
                {
                    if(img1Pixels.GetPixel(x, y).GetChannel(0) > intensityThreshold &&
                        img2Pixels.GetPixel(x, y).GetChannel(0) > intensityThreshold)
                    {
                        if (x < box["bl"][0]) { box["bl"][0] = x; }
                        if (x > box["tr"][0]) { box["tr"][0] = x; }

                        if (y < box["tr"][1]) { box["tr"][1] = y; }
                        if (y > box["bl"][1]) { box["bl"][1] = y; }
                    }
                }
            }
            //Add padding for the box borders
            if (box["bl"][0] > 5) { box["bl"][0] -= 5; };
            box["bl"][1] += 5;
            box["tr"][0] += 5;
            if (box["tr"][1] > 5) { box["tr"][1] -= 5; }
            image1.Magick.Dispose();
            image2.Magick.Dispose();
            img1Pixels.Dispose();
            img2Pixels.Dispose();
            return box;
        }
        private static List <CGInfo> GetCgInfo(HelixImage image)
        {
            List <CGInfo>         cgList   = new List <CGInfo>();
            var                   pixels   = image.Magick.GetPixels();
            List <IPixel <byte> > cgPixels = new List <IPixel <byte> >();

            for (int col = 0; col < image.Magick.Width; col++)
            {
                int peak = 0;
                for (int row = 0; row < image.Magick.Height; row++)
                {
                    var pixel = pixels.GetPixel(col, row).GetChannel(0);
                    if (pixel > peak)
                    {
                        peak = pixel;
                    }
                }
                if (peak < (Config.LineThresholdPercent / 100.0) * 255.0)
                {
                    continue;
                }
                for (int row = 0; row < image.Magick.Height; row++)
                {
                    var pixel = pixels.GetPixel(col, row);
                    if (pixel.GetChannel(0) > (Config.LineThresholdPercent / 100.0) * peak)
                    {
                        cgPixels.Add(pixel);
                    }
                }
                float cgTotal  = 0;
                float cgMoment = 0;
                foreach (var pixel in cgPixels)
                {
                    cgTotal  += pixel.GetChannel(0);
                    cgMoment += pixel.GetChannel(0) * (pixel.Y - cgPixels[0].Y);
                }
                float cg = (float)(Math.Round(cgPixels[0].Y + (cgMoment / cgTotal), 1));
                Tuple <int, float> scoreIntensity = GetScoreIntensity(cgPixels);
                cgList.Add(new CGInfo(col, cg, scoreIntensity.Item2, cgPixels.Count, scoreIntensity.Item1));
                cgPixels.Clear();
            }
            return(cgList);
        }
Ejemplo n.º 4
0
 private static void RemoveDots(string zValue, Dictionary<string, int[]> box, List<string> laserImages)
 {
     byte[] pixelValue = BitConverter.GetBytes(0);
     foreach (string laserImage in laserImages)
     {
         if (GetImageZValue(laserImage) == zValue)
         {
             HelixImage image = new HelixImage(laserImage);
             IPixelCollection<byte> pixels = image.Magick.GetPixels();
             for (int x = box["bl"][0]; x <= box["tr"][0]; x++)
             {
                 for (int y = box["tr"][1]; y <= box["bl"][1]; y++)
                 {
                     pixels.SetPixel(x, y, pixelValue);
                 }
             }
             image.SaveImage(true);
             image.Magick.Dispose();
             pixels.Dispose();
         }
     }
 }
        private static List <HelixImage> SortNearFar(List <HelixImage> images)
        {
            bool sorted = false;

            while (!sorted)
            {
                sorted = true;
                for (int i = 0; i < images.Count; i++)
                {
                    if (i + 1 < images.Count)
                    {
                        if (int.Parse(images[i].ZValue) > int.Parse(images[i + 1].ZValue))
                        {
                            HelixImage popImage = images[i + 1];
                            images.RemoveAt(i + 1);
                            images.Insert(i, popImage);
                            sorted = false;
                        }
                    }
                }
            }
            return(images);
        }