Esempio n. 1
0
        //检测错误保存文件
        public bool savepic(Bitmap bitmap, String path)
        {
            bbox_t_container boxlist = new bbox_t_container();
            bool             ng;

            byte[] byteImg = Bitmap2Byte(bitmap);
            long   intime  = DateTimeUtil.DateTimeToLongTimeStamp(DateTime.Now);
            int    n       = AITestSDK.detect_opencv_mat(byteImg, byteImg.Length, ref boxlist, (float)typenum);
            long   endtime = DateTimeUtil.DateTimeToLongTimeStamp(DateTime.Now);
            long   gettime = endtime - intime;

            Console.WriteLine(gettime);
            int j = 0;

            if (n == -1)
            {
                Loghelper.WriteLog("调用失败,请检测目录是否包含opencv的dll");
            }

            for (int i = 0; i < boxlist.bboxlist.Length; i++)
            {
                if (boxlist.bboxlist[i].h == 0)
                {
                    break;
                }
                else
                {
                    DrawRectangleInPicture(bitmap, (int)boxlist.bboxlist[i].x,
                                           (int)boxlist.bboxlist[i].y,
                                           (int)boxlist.bboxlist[i].w,
                                           (int)boxlist.bboxlist[i].h, Color.Red, 2, DashStyle.Solid);
                    j++;
                }
            }
            if (j > 0)
            {
                ng = true;
            }
            else
            {
                ng = false;
            }
            bitmap.Save(path, System.Drawing.Imaging.ImageFormat.Jpeg);
            return(ng);
        }
 /// <summary>
 /// AI大图检测
 /// </summary>
 /// <param name="isFront">是否是正面</param>
 /// <param name="bitmapInfo">图片信息</param>
 /// <param name="scaleRect">已经缩放的矩形框在缩放大图的位置</param>
 /// <param name="scale">缩放的尺度</param>
 /// <param name="confidence">置信度</param>
 /// <param name="savePath">图像保存地址</param>
 public void aiDetect(bool isFront, OneStitchSidePcb.BitmapInfo bitmapInfo, Rectangle scaleRect, double scale, float confidence, string savePath)
 {
     //Console.WriteLine(allDetectNum);
     MySmartThreadPool.InstanceSmall().QueueWorkItem((name, bmp) =>
     {
         try
         {
             bbox_t_container boxlist = new bbox_t_container();
             using (MemoryStream stream = new MemoryStream())
             {
                 bmp.Save(stream, ImageFormat.Jpeg);
                 byte[] byteImg = new byte[stream.Length];
                 stream.Seek(0, SeekOrigin.Begin);
                 stream.Read(byteImg, 0, Convert.ToInt32(stream.Length));
                 int n = -1;
                 lock (detectKey)
                 {
                     n = AITestSDK.detect_opencv_mat(byteImg, byteImg.Length, ref boxlist, confidence);
                 }
                 if (n == -1)
                 {
                     Console.WriteLine("AI调用失败");
                 }
                 else
                 {
                     resultJoin(name, isFront, scale, scaleRect, boxlist, new List <string>()
                     {
                         "NG"
                     }, new Point(0, 0));
                 }
             }
         }
         catch (Exception er) {  }
         finally
         {
             bmp.Dispose();
             allDetectNum++;
             aiDone(savePath);
         }
         //最总检测的结果还是放在这里发送吧
     }, bitmapInfo.name, (Bitmap)bitmapInfo.bitmap.Clone());
 }
        private int sdkin()
        {
            // VS要用管理员权限打开
            // VS要用管理员权限打开
            // VS要用管理员权限打开

            //初始化检测器
            //return AITestSDK.init(@"C:\Users\Administrator\Desktop\suomi-test-img\aimodel\config.data",
            //     // 特别说明,这里的路径一定要用 '/' 不能用反斜杠
            //     // 特别说明,这里的路径一定要用 '/' 不能用反斜杠
            //     // 特别说明,这里的路径一定要用 '/' 不能用反斜杠
            //     "C://Users//Administrator//Desktop//suomi-test-img//aimodel//voc.weights",
            //     0);
            return(AITestSDK.init(@"E:\BaiduNetdiskDownload\newdemoall\newdemoall\newdemoall\bin\x64\Debug\suomi\data\config.data",
                                  // 特别说明,这里的路径一定要用 '/' 不能用反斜杠
                                  // 特别说明,这里的路径一定要用 '/' 不能用反斜杠
                                  // 特别说明,这里的路径一定要用 '/' 不能用反斜杠
                                  "E:/BaiduNetdiskDownload/newdemoall/newdemoall/newdemoall/bin/x64/Debug/suomi/data/voc.weights",
                                  0));
        }