private bool isBabyYiNing = false; //不跑小马的代码 /// <summary> /// 拼图回调函数,用于执行界面更新 /// </summary> /// <param name="end"></param> /// <param name="isFront"></param> /// <param name="bitmap"></param> /// <param name="rect"></param> /// <param name="scale"></param> /// <returns></returns> public int doStitchCallBack(bool isEnd, OneStitchSidePcb oneStitchSidePcb, OneStitchSidePcb.BitmapInfo bitmapInfo, RectangleF scaleRect) { Console.WriteLine("doStitchCallBack"); //bool end, bool isFront, Bitmap bitmap, RectangleF rect //if (InvokeRequired) //{ // // If called from a different thread, we must use the Invoke method to marshal the call to the proper GUI thread. // // The grab result will be disposed after the event call. Clone the event arguments for marshaling to the GUI thread. // BeginInvoke(new StitchCallBack(doStitchCallBack), isEnd, oneStitchSidePcb, bitmapInfo, scaleRect); // return 0; //} Rectangle scaleR = new Rectangle(Convert.ToInt32(scaleRect.X), Convert.ToInt32(scaleRect.Y), Convert.ToInt32(scaleRect.Width), Convert.ToInt32(scaleRect.Height)); aiDetect(oneStitchSidePcb.zTrajectory, bitmapInfo, scaleR, oneStitchSidePcb.scale, oneStitchSidePcb.confidence, oneStitchSidePcb.savePath); return(1); }
/// <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()); }