public bool Start(HostControl hostControl)
        {
            if (string.IsNullOrEmpty(CONFIG_PATH))
            {
                // Some default value.
                CONFIG_PATH = "C:\\config.json";
            }

            try
            {
                this.LoadJson();
            }
            catch (Exception ex)
            {
                return(false);
            }

            DONE_FOLDER         = Path.Combine(config.ReadFolder, "DONE");
            UNRECOGNIZED_FOLDER = Path.Combine(config.ReadFolder, "UNRECOGNIZED");

            this.CreateFolders();

            this.directoryInfo = new DirectoryInfo(config.ReadFolder);

            this.imageQueue = new ImageQueue();

            this.SetupCheckTimer();
            this.SetupTimeOut();

            // Initial check.
            Task.Run(() => { this.CheckFolder(null, null); });

            return(true);
        }
示例#2
0
        private void CameraGrabberFrameCallback(IntPtr Grabber, IntPtr pFrameBuffer, ref tSdkFrameHead pFrameHead, IntPtr Context)
        {
            int    w         = pFrameHead.iWidth;
            int    h         = pFrameHead.iHeight;
            bool   gray      = (pFrameHead.uiMediaType == (uint)emImageFormat.CAMERA_MEDIA_TYPE_MONO8);
            Bitmap ImageDisp = new Bitmap(w, h,
                                          gray ? w : w * 3,
                                          gray ? PixelFormat.Format8bppIndexed : PixelFormat.Format24bppRgb,
                                          pFrameBuffer);

            // 如果是灰度图要设置调色板
            if (gray)
            {
                ImageDisp.Palette = m_GrayPal;
            }

            using (var stream = new MemoryStream())
            {
                ImageDisp.Save(stream, ImageFormat.Bmp);
                App.Current.Dispatcher.InvokeAsync(new Action(() =>
                {
                    SetPreviewImage(stream);
                }));
            }

            if (DetectFlag)
            {
                Image.Bitmap = ImageDisp;
                ImageQueue.Enqueue(Image);
                CapCount++;
            }
        }
示例#3
0
 // thread safe wrt. Push
 internal Emgu.CV.UMat Pop()
 {
     Emgu.CV.UMat ret = null;
     if (ImageQueue.TryDequeue(out ret))
     {
         return(ret);
     }
     return(null);
 }
示例#4
0
 // thread safe wrt. Pop
 internal void Push(Emgu.CV.UMat image)
 {
     if (image != null)
     {
         if (ImageQueue.Count < Nthreads_ * 2)
         {
             ImageQueue.Enqueue(image);
         }
         else
         {
             //we are reaching into memory limits, so dispose it to prevent
             //exhausting the ram
             image.Dispose();
         }
     }
 }
示例#5
0
        void IDropTarget.Drop(IDropInfo dropInfo)
        {
            var dragFileList = ((DataObject)dropInfo.Data).GetFileDropList();
            int Counter      = 0;

            foreach (String str in dragFileList)
            {
                if ((System.IO.Path.GetExtension(str).ToUpperInvariant() == ".JPG") ||
                    (System.IO.Path.GetExtension(str).ToUpperInvariant() == ".PNG"))
                {
                    ImageQueue.Add(str);
                    Counter++;
                }
            }

            dropInfo.Effects = DragDropEffects.Copy;
            ConsoleLog(Counter + "/" + dragFileList.Count + " files are valid entries.");
        }
        public bool Start(HostControl hostControl)
        {
            DONE_FOLDER         = Path.Combine(ConfigurationManager.AppSettings["ReadFolder"], "DONE");
            UNRECOGNIZED_FOLDER = Path.Combine(ConfigurationManager.AppSettings["ReadFolder"], "UNRECOGNIZED");

            this.CreateFolders();

            this.directoryInfo = new DirectoryInfo(ConfigurationManager.AppSettings["ReadFolder"]);

            this.imageQueue = new ImageQueue();

            this.SetupCheckTimer();
            this.SetupTimeOut();

            // Initial check.
            Task.Run(() => { this.CheckFolder(null, null); });

            return(true);
        }
示例#7
0
 private void Hooks_DispatcherInactive(object sender, EventArgs e)
 {
     using (Mat source = capture.QueryFrame())
     {
         var frame = new Mat();
         CvInvoke.Resize(source, frame, ImageSize);
         if (frame != null && DetectFlag && !frame.IsEmpty)
         {
             Image <Bgr, Byte> Image = new Image <Bgr, Byte>(ImageSize);
             Image.Bitmap = (Bitmap)frame.Bitmap.Clone();
             ImageQueue.Enqueue(Image);
             using (var stream = new MemoryStream())
             {
                 frame.Bitmap.Save(stream, ImageFormat.Png);
                 SetPreviewImage(stream);
             }
         }
     }
 }
示例#8
0
        public void StartDetect()
        {
            Task.Run(() =>
            {
                Task.Run(() =>
                {
                    while (true)
                    {
                        Console.WriteLine("计算: " + FrameCount + " 采集: " + CapCount + "显示: " + DispCount + " 图片队列: " + ImageQueue.Count);
                        FrameCount       = 0;
                        CapCount         = 0;
                        DispCount        = 0;
                        CurrentLoopCount = serialComm.LoopCount;
                        Thread.Sleep(1000);
                    }
                });
                AlgorithmResult[] algorithmResults;
                while (DetectFlag)
                {
                    Task.Run(() =>
                    {
                        Image <Bgr, byte> image;
                        if (ImageQueue.TryDequeue(out image))
                        {
                            stDetectParam = DetectParam.GetSt();
                            AlarmRecord.SetRange(AlarmParam.PixelRange, AlarmParam.YRange);

                            App.Current?.Dispatcher?.Invoke(() =>
                            {
                                if (AlarmRecord.TotalLoopCount != AlarmParam.TotalLoopCount)
                                {
                                    AlarmRecord.TotalLoopCount = AlarmParam.TotalLoopCount;
                                    Alarms.Clear();
                                    AsyncSaveObject("Alarms", Alarms);
                                }
                            });
                            algorithmResults = Algorithm.DetectImage(image.Ptr, stDetectParam);
                            List <AlgorithmResult> results = new List <AlgorithmResult>(algorithmResults);
                            results.ForEach(result =>
                            {
                                if (result.bStop != 0 || result.bWidthReachStop != 0)
                                {
                                    DrawRectOnScreen(result.xPos, result.yPos);
                                    AddResultToStatistics(result.xPos, result.yPos, image.Clone());
                                }
                            });

                            lock (this)
                            {
                                if (detectResultStatistics.Count > 0)
                                {
                                    int avgX           = 0;
                                    int avgY           = 0;
                                    DateTime beginTime = DateTime.MinValue;
                                    DetectResultStatistic detectResultStatistic = null;
                                    TimeSpan maxDuration = FindMaxDuration(out avgX, out avgY, out beginTime, out detectResultStatistic);
                                    if (avgX == -1)
                                    {
                                        return;
                                    }
                                    float length        = (float)((maxDuration.Seconds + maxDuration.Milliseconds / 1000.0) * AlarmParam.Velocity);
                                    DateTime latestTime = FindLatestTime();

                                    if (DateTime.Now - latestTime > AlarmParam.MaxErrorTime)
                                    {
                                        DetectState            = DetectResultState.皮带正常;
                                        AlarmHeadFlag          = true;
                                        AlarmRecord.LoopOffset = LoopOffset;
                                        if (SaveFlag)
                                        {
                                            SaveFlag = false;
                                            SaveAlarmVideo();
                                        }
                                        detectResultStatistics.Clear();
                                    }
                                    else if (maxDuration > AlarmParam.MaxHurtTime)//逻辑判断有超过maxHurtTime时间,此时发生撕伤警报
                                    {
                                        DetectState = DetectResultState.撕伤;
                                        AddAlarmToStatistics(avgX, avgY, length, detectResultStatistic);
                                    }
                                    else if (maxDuration > AlarmParam.MaxDivTime)//逻辑判断有超过maxDivTime时间,此时发生撕裂警报
                                    {
                                        DetectState = DetectResultState.撕裂;
                                    }
                                }
                            }
                            FrameCount++;
                        }
                    });

                    Thread.Sleep(10);
                }
            });
        }
示例#9
0
 public static void init()
 {
     tq.init();
     ImageQueue.init();
 }