Пример #1
0
        private bool RunDisplayTest(TestItem testItem, Bitmap bitmap, Bitmap bmpDisp, ref List <IntPoint> ptCorners)
        {
            string imageName = string.Format("{0}{1}_{2:yyyyMMddHHmmss}_{3}.bmp", IMAGE_SAVE_PATH, SerialNumber, DateTime.Now, testItem.TestName);

            if (testItem.RGB == Color.FromArgb(255, 255, 255))
            {
                //Process Image to 1bpp to increase SNR
                Bitmap m_orig = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
                // only support the 32bppArgb for Aforge Blob Counter
                Bitmap processbmp = m_orig.Clone(new Rectangle(0, 0, m_orig.Width, m_orig.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                ip.GetDisplayCornerfrombmp(processbmp, out ptCorners);
            }

            if (ptCorners == null)
            {
                return(false);
            }

            // save original image
            // bitmap: the first bitmap, bmpDisp: the second bitmap.
            if (bmpDisp == null)
            {
                bmpDisp = bitmap;
            }
            bmpDisp.Save(imageName);

            // cropping screen image
            Bitmap srcimg    = new Bitmap(System.Drawing.Image.FromFile(imageName, true));
            Bitmap updateimg = CroppingImage((Bitmap)srcimg.Clone(), ptCorners);

            args.Image = updateimg;
            dataChange.Invoke(this, args);

            // 截取区域图像
            Bitmap cropimg = ip.croppedimage(srcimg, ptCorners, dut.ui_width, dut.ui_height);

            cropimg.Save(imageName + "_cropped.bmp");
            args.Image = new Bitmap(cropimg);
            dataChange.Invoke(this, args);

            Bitmap bmpCroping = null;

            if (bmpDisp != bitmap)
            {
                bmpCroping = ip.croppedimage(bitmap, ptCorners, dut.ui_width, dut.ui_height);
            }
            else
            {
                bmpCroping = cropimg;
            }

            // anaylse
            ColorimeterResult colorimeterRst = new ColorimeterResult(bmpCroping, cropimg);

            colorimeterRst.Analysis(ref testItem, dut);

            //if (this.config.IsOnlineShopfloor)
            //{
            //    UploadItemDataToSFC(testItem, "Camera");
            //}
            this.DrawZone(cropimg, testItem.TestName);

            return(testItem.RunUnifAndMura()); //testItem.Run();
        }
Пример #2
0
        public override void Calibration(float exposure = 0)
        {
            double flexPixel    = 0;
            double maxFlexPixel = 0;

            System.Drawing.Color pixel;
            StringBuilder        matrixStr = new StringBuilder();

            System.Threading.Thread.Sleep(3000);

            foreach (int[] item in rgbList)
            {
                List <AForge.IntPoint> cors = null;

                if (dut.ChangePanelColor(item[0], item[1], item[2]))
                {
                    System.Threading.Thread.Sleep(5000);
                    matrixStr.Clear();

                    camera.ExposureTime = this.CalExposureTime(exposure, item);
                    System.Drawing.Bitmap bitmap = camera.GrabImage();
                    if (this.videoCavaus != null)
                    {
                        this.videoCavaus.Image = System.Drawing.Image.FromHbitmap(bitmap.GetHbitmap());
                    }
                    //Process Image to 1bpp to increase SNR
                    Bitmap m_orig = bitmap.Clone(new Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.PixelFormat.Format1bppIndexed);
                    // only support the 32bppArgb for Aforge Blob Counter
                    Bitmap processbmp = m_orig.Clone(new Rectangle(0, 0, m_orig.Width, m_orig.Height), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                    pipe.GetDisplayCornerfrombmp(processbmp, out cors);

                    Bitmap cropimg = null;

                    if (cors != null)
                    {
                        cropimg = pipe.croppedimage(bitmap, cors, dut.ui_width, dut.ui_height);
                        if (this.videoCavaus != null)
                        {
                            this.videoCavaus.Image = System.Drawing.Image.FromHbitmap(bitmap.GetHbitmap());
                        }
                    }

                    double[,] matrix = new double[cropimg.Width, cropimg.Height];

                    for (int i = 0; i < cropimg.Height; i++)
                    {
                        for (int j = 0; j < cropimg.Width; j++)
                        {
                            pixel        = cropimg.GetPixel(i, j);
                            flexPixel    = redWeight * pixel.R + greenWeight * pixel.G + blueWeight * pixel.B;
                            matrix[i, j] = flexPixel;

                            if (flexPixel > maxFlexPixel)
                            {
                                maxFlexPixel = flexPixel;
                            }
                        }
                    }

                    for (int i = 0; i < cropimg.Height; i++)
                    {
                        for (int j = 0; j < cropimg.Width; j++)
                        {
                            if (matrix[i, j] != 0)
                            {
                                matrix[i, j] = maxFlexPixel / matrix[i, j];
                            }

                            matrixStr.Append(matrix[i, j]);

                            if (j != cropimg.Width - 1)
                            {
                                matrixStr.Append(", ");
                            }
                        }
                        matrixStr.AppendLine();
                    }

                    string fullname = string.Format("{0}{1}_{2:000}{3:000}{4:000}_Flex.csv", PATH, serialNumber, item[0], item[1], item[2]);
                    using (StreamWriter sw = new StreamWriter(fullname, true))
                    {
                        sw.Write(matrixStr.ToString());
                        sw.Flush();
                        sw.Close();
                    }
                }
            }
        }