Esempio n. 1
0
 public bool Init()
 {
     DhCamera.InitDhSdk();
     for (int i = 0; i < camera.Count(); i++)
     {
         camera[i] = new DhCamera(i);
         if (camera[i].Open() == false)
         {
             return(false);
         }
         camera[i].SetBalanceRatio(BalanceWhiteChanelEnum.BALANCE_RATIO_SELECTOR_RED, booldcardinfo[i].bloodParameter.camre_rb);
         camera[i].SetBalanceRatio(BalanceWhiteChanelEnum.BALANCE_RATIO_SELECTOR_BLUE, booldcardinfo[i].bloodParameter.camre_gb);
         camera[i].SetBalanceRatio(BalanceWhiteChanelEnum.BALANCE_RATIO_SELECTOR_GREEN, booldcardinfo[i].bloodParameter.camre_bb);
         camera[i].SetGain(booldcardinfo[i].bloodParameter.camre_gain);
         camera[i].SetExposureTime(booldcardinfo[i].bloodParameter.onedcode_s3);
         Unet[i] = PyTorchSDK.CreateModel(64, 128);
         PyTorchSDK.LoadModel(Unet[i], "model/unet_gpu.pt");
         Ocrnet[i] = PyTorchSDK.CreateModel(28, 28);
         PyTorchSDK.LoadModel(Ocrnet[i], "model/orc_gpu.pt");
     }
     SetTimplateImage("template.jpg");
     SetTimplateImage("icon.jpg");
     SetTimplateImage("a.jpg");
     SetTimplateImage("mask.jpg");
     return(true);
 }
Esempio n. 2
0
        //杂质检测
        public static List <List <InspectionRect> > ForeignInspection(List <Mat> imgs, List <List <int> > liquilevel, ref List <Mat> retimgs, int inspection_count, int inspection_minarea, int netindex)
        {
            List <List <InspectionRect> > rectlist = new List <List <InspectionRect> >();
            Mat mask = GetTimplateImage("mask.jpg");

            Cv2.Resize(mask, mask, new OpenCvSharp.Size(64, 128));
            foreach (var item in imgs)
            {
                PyTorchSDK.AddImage(Unet[netindex], item.Data);
            }
            PyTorchSDK.Test(Unet[netindex], false);
            var data  = PyTorchSDK.GetOutPut(Unet[netindex]);
            int index = 0;

            while (data != IntPtr.Zero)
            {
                Mat img_tem = new Mat(128, 64, MatType.CV_8U, data);
                //要为奇数//膨胀
                //Mat se = Cv2.GetStructuringElement(MorphShapes.Rect, new OpenCvSharp.Size(1, 2), new OpenCvSharp.Point(0, 0));
                //Cv2.Dilate(img_tem, img_tem, se, new OpenCvSharp.Point(-1, -1), 1);
                img_tem = img_tem.Threshold(inspection_count, 255, ThresholdTypes.Binary);
                retimgs.Add(img_tem.Clone());
                OpenCvSharp.Point[][] contours;
                HierarchyIndex[]      hierarchyIndexes;

                Mat img_masked = new Mat();
                img_tem.CopyTo(img_masked, mask);

                img_masked.FindContours(out contours, out hierarchyIndexes, RetrievalModes.CComp, ContourApproximationModes.ApproxSimple);
                rectlist.Add(new List <InspectionRect>());
                for (int i = 0; i < contours.Length; i++)
                {
                    var rect = Cv2.BoundingRect(contours[i]);
                    if (rect.Width * rect.Height > inspection_minarea && (rect.Y > liquilevel[index][0] || rect.Y + rect.Height > liquilevel[index][0]))
                    {
                        rectlist[rectlist.Count - 1].Add(new InspectionRect(rect, rect.Width * rect.Height, rect.Width * rect.Height));
                    }
                }
                data = PyTorchSDK.GetOutPut(Unet[netindex]);
                index++;
            }
            return(rectlist);
        }
Esempio n. 3
0
        public static string CheckOrc(List <Mat> imgs, int index)
        {
            string orc_str = "";

            if (imgs.Count != 0)
            {
                foreach (var img in imgs)
                {
                    PyTorchSDK.AddImage(Ocrnet[index], img.Data);
                }
                PyTorchSDK.Test(Ocrnet[index], true);
                var data = PyTorchSDK.GetOutPutInt(Ocrnet[index]);
                while (data != -1)
                {
                    orc_str += data;
                    data     = PyTorchSDK.GetOutPutInt(Ocrnet[index]);
                }
            }
            return(orc_str);
        }