Esempio n. 1
0
        protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img)
        {
            if (_take_texture_image)
            {
                _take_texture_image = false;
                _texture_image      = img.Copy();
                lock (Context.Viewer) {
                    UpdateAllColors();
                }
            }

            if (_clear_points)
            {
                _clear_points = false;
                _pixel_point_ids.Reset();
                Context.Setup.ScanWorkflow.Reset();
                _pointcloud.ClearPoints();
            }

            // Update the transformation between positioner coordinate system and camera coordinate system
            if (_update_positioner_transformation)
            {
                _update_positioner_transformation = false;
                Context.Setup.Positioner.UpdateTransformation(Context.Setup.Camera);
                _pixel_point_ids.Reset();
                Context.Setup.ScanWorkflow.Reset();
            }

            if (Context.Setup.Camera.FrameSize != _pixel_point_ids.Size)
            {
                _pixel_point_ids.Size = Context.Setup.Camera.FrameSize;
            }

            List <Vector> points;
            List <System.Drawing.Point> pixels;

            if (Context.Setup.ScanWorkflow.Process(Context.Setup, img, out points, out pixels))
            {
                lock (Context.Viewer) {
                    UpdatePoints(points, pixels);
                }
                foreach (System.Drawing.Point p in pixels)
                {
                    img[p.Y, p.X] = new Bgr(Color.Green);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Find checkerboard in image
        /// </summary>
        /// <param name="img">Image to search pattern for</param>
        /// <param name="image_points">Detected checkerboard image points</param>
        /// <returns>True if pattern was found, false otherwise</returns>
        public override bool FindPattern(Emgu.CV.Image <Gray, byte> img, out System.Drawing.PointF[] image_points)
        {
            Emgu.CV.Image <Gray, byte> my_img = img.Copy();
            my_img._EqualizeHist();
            bool found = Emgu.CV.CameraCalibration.FindChessboardCorners(
                my_img,
                _inner_corners,
                Emgu.CV.CvEnum.CALIB_CB_TYPE.ADAPTIVE_THRESH |
                Emgu.CV.CvEnum.CALIB_CB_TYPE.FILTER_QUADS |
                Emgu.CV.CvEnum.CALIB_CB_TYPE.NORMALIZE_IMAGE,
                out image_points
                );

            if (found)
            {
                my_img.FindCornerSubPix(
                    new System.Drawing.PointF[][] { image_points },
                    new System.Drawing.Size(5, 5),
                    new System.Drawing.Size(-1, -1),
                    new MCvTermCriteria(0.001));
            }
            return(found);
        }
Esempio n. 3
0
        protected override void OnFrame(Parsley.Core.BuildingBlocks.FrameGrabber fp, Emgu.CV.Image <Emgu.CV.Structure.Bgr, byte> img)
        {
            #region take texture
            if (_take_texture_image) //even handler jika mengambil texture image
            {
                _take_texture_image = false;
                _texture_image      = img.Copy();
                lock (Context.Viewer)
                {
                    UpdateAllColors();
                }
            }
            #endregion

            #region clear point
            if (_clear_points)
            { //even handler jika menghapus point 3d yg sdh ada
                _clear_points = false;
                _pixel_point_ids.Reset();
                Context.Setup.ScanWorkflow.Reset();
                _pointcloud.ClearPoints();
            }
            #endregion

            #region update positioner
            // Update the transformation between positioner coordinate system and camera coordinate system
            if (_update_positioner_transformation)
            {
                _update_positioner_transformation = false;
                Context.Setup.Positioner.UpdateTransformation(Context.Setup.Camera);
                _pixel_point_ids.Reset();
                Context.Setup.ScanWorkflow.Reset();
            }
            #endregion

            #region penyesuaian proporsi pixel dengan frame size
            if (Context.Setup.Camera.FrameSize != _pixel_point_ids.Size)
            {
                _pixel_point_ids.Size = Context.Setup.Camera.FrameSize;
            }
            #endregion

            List <Vector> points; //array penyimpan koordinat  //sepertinya ini yang out of range
            List <System.Drawing.Point> pixels;

            #region start scanning
            if (_start_scanning)
            {
                //Console.Write(Context.Setup.ScanWorkflow.Process(Context.Setup, img, out points, out pixels));

                if (Context.Setup.ScanWorkflow.Process(Context.Setup, img, out points, out pixels)) //Jika syarat2 dalam scanworkflow.process terpenuhi maka akan ditambahkan pointcloudnya.
                {
                    Console.WriteLine(pixels.Count);
                    lock (Context.Viewer)
                    {
                        UpdatePoints(points, pixels); //memanggil fungsi UpdatePoints untuk update model 3d setiap waktu, tanpa perduli terdeteksi ada nilai baru atau tidak
                    }
                    foreach (System.Drawing.Point p in pixels)
                    {
                        img[p.Y, p.X] = new Bgr(Color.Green);
                    }
                }
            }

            #endregion
        }
        public void ExtraerArea()
        {
            System.Drawing.Bitmap memoryImageT =
                new System.Drawing.Bitmap(System.Drawing.Image.FromFile(
                                              archivo));


            Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte> imgOrig = new Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte>(memoryImageT);



            //detecta areas con texto

            textArea = detectLetters(imgOrig);


            for (int i = 0; i < textArea.Count; i++)
            {
                Emgu.CV.CvInvoke.Rectangle(imgOrig, textArea[i], new Emgu.CV.Structure.MCvScalar(0, 0, 255), 2);
            }

            Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte> memoryImageOut = imgOrig;


            memoryImageT = memoryImageOut.ToBitmap();



            System.Drawing.Bitmap memoryImageT2 =
                new System.Drawing.Bitmap(System.Drawing.Image.FromFile(
                                              archivo));



            //guardar segmentos de imagen
            Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte> imgOriginal = new Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte>(memoryImageT2);

            imgOriginal = new Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte>(imgOriginal.Mat.Bitmap);

            imageparts = new List <Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte> >(); // List of extracted image parts


            foreach (var roi in textArea)
            {
                imgOriginal.ROI = roi;
                imageparts.Add(imgOriginal.Copy());
            }
            int k = 0;

            contador = imageparts.Count;

            foreach (var imagen in imageparts)
            {
                //mejoro calidad de texto en cada segmento

                Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte> mt = new Emgu.CV.Image <Emgu.CV.Structure.Bgr, Byte>(imagen.Mat.Bitmap);

                Emgu.CV.CvInvoke.CvtColor(imagen, mt, Emgu.CV.CvEnum.ColorConversion.Bgr2Gray);
                guardarArchivo(mt.Mat, "z-imgtexto-" + k.ToString() + "-antes");
                int umbralsegmento = valorUmbral(mt.Mat.ToImage <Emgu.CV.Structure.Gray, Byte>());

                if (umbralsegmento < 200)
                {
                    Emgu.CV.CvInvoke.Threshold(mt, mt, umbral, 255, Emgu.CV.CvEnum.ThresholdType.Otsu);
                }



                Mat imagenMat = new Mat();


                if (Convert.ToDouble(imagen.Height) / dim <= 1.5)
                {
                    imagenMat = eliminarlineasegmento(mt.Mat.ToImage <Emgu.CV.Structure.Bgr, Byte>(), k, 40, dim * 130 / imagen.Height).Mat;
                }
                if (Convert.ToDouble(imagen.Height) / dim > 1.5 && imagen.Height / dim <= 2.0)//2.5
                {
                    imagenMat = eliminarlineasegmento(mt.Mat.ToImage <Emgu.CV.Structure.Bgr, Byte>(), k, 40, dim * 120 / imagen.Height).Mat;
                }
                if (Convert.ToDouble(imagen.Height) / dim > 2.0)
                {
                    imagenMat = eliminarlineasegmento(mt.Mat.ToImage <Emgu.CV.Structure.Bgr, Byte>(), k, 40, dim * 110 / imagen.Height).Mat;
                }


                /*
                 *
                 * Emgu.CV.CvInvoke.BitwiseNot(imagenMat, imagenMat);
                 *
                 * Mat verticalStructure = Emgu.CV.CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(2, 1), new Point(-1, -1));
                 *
                 * Emgu.CV.CvInvoke.Erode(imagenMat, imagenMat, verticalStructure, new Point(-1, -1), 1, Emgu.CV.CvEnum.BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                 *
                 *
                 * verticalStructure = Emgu.CV.CvInvoke.GetStructuringElement(Emgu.CV.CvEnum.ElementShape.Rectangle, new Size(2, 2), new Point(-1, -1));
                 *
                 *
                 * Emgu.CV.CvInvoke.Dilate(imagenMat, imagenMat, verticalStructure, new Point(-1, -1), 1, Emgu.CV.CvEnum.BorderType.Default, new Emgu.CV.Structure.MCvScalar());
                 *
                 *
                 *
                 * Emgu.CV.CvInvoke.BitwiseNot(imagenMat, imagenMat);
                 *
                 */


                guardarArchivo(imagenMat, "z-imgtexto-" + k.ToString());
                k++;
            }


            memoryImageT.Save(ruta + "/files/11textarea.bmp");
        }
        public bool recortarROI()
        {
            System.Drawing.Bitmap memoryImageT =
                new System.Drawing.Bitmap(System.Drawing.Image.FromFile(archivo));
            int minx = 10000;
            int miny = 10000;
            int maxx = 0;
            int maxy = 0;

            Emgu.CV.Image <Emgu.CV.Structure.Gray, Byte> img = new Emgu.CV.Image <Emgu.CV.Structure.Gray, Byte>(memoryImageT);

            umbral = valorUmbral(img);


            for (int v = 4; v < img.Height - 4; v++)
            {
                for (int u = 4; u < img.Width - 4; u++)
                {
                    byte a = img.Data[v, u, 0]; //Get Pixel Color | fast way
                    if (a <= umbral * 0.50 && (
                            (img.Data[v - 4, u - 4, 0] <= umbral * 0.50 && img.Data[v + 4, u + 4, 0] <= umbral * 0.50 && img.Data[v - 2, u - 2, 0] <= umbral * 0.50 && img.Data[v + 2, u + 2, 0] <= umbral * 0.50) ||
                            (img.Data[v + 4, u - 4, 0] <= umbral * 0.50 && img.Data[v - 4, u + 4, 0] <= umbral * 0.50 && img.Data[v + 2, u - 2, 0] <= umbral * 0.50 && img.Data[v - 2, u + 2, 0] <= umbral * 0.50) ||
                            (img.Data[v, u - 4, 0] <= umbral * 0.50 && img.Data[v, u + 2, 0] <= umbral * 0.50 && img.Data[v, u - 2, 0] <= umbral * 0.50 && img.Data[v, u + 2, 0] <= umbral * 0.50) ||
                            (img.Data[v + 4, u, 0] <= umbral * 0.50 && img.Data[v - 2, u, 0] <= umbral * 0.50 && img.Data[v + 2, u, 0] <= umbral * 0.50 && img.Data[v - 2, u, 0] <= umbral * 0.50)
                            ))
                    {
                        if (u < minx)
                        {
                            minx = u;
                        }
                        if (v < miny)
                        {
                            miny = v;
                        }
                        if (u > maxx)
                        {
                            maxx = u;
                        }
                        if (v > maxy)
                        {
                            maxy = v;
                        }
                    }
                }
            }
            Console.WriteLine("minimo: " + minx + "," + miny + "  maximo: " + maxx + "," + maxy);
            Rectangle roi = new Rectangle();

            roi.X      = minx;
            roi.Y      = miny;
            roi.Width  = maxx - minx;
            roi.Height = maxy - miny;
            img.ROI    = roi;
            guardarArchivo(img.Copy().Mat, "imagenROI");
            //detectar traslacion por relacion proporcional entre punto minimo y tamaño de la imagen

            float proporcionX = img.Width / minx;
            float proporcionY = img.Height / miny;

            archivo = ruta + "files/imagenROI.bmp";
            if ((proporcionX > 11 || proporcionX < 9) || (proporcionY > 47 || proporcionY < 45))
            {
                return(true);
            }

            return(false);
        }