示例#1
0
 void CreateThreads()
 {
     for (int i = 0; i < n; i++)
     {
         ThreadReco t = new ThreadReco(this.mainWindow);
         t.tid = i;
         t.StartThread();
         threadparallel.Add(t);
     }
 }
示例#2
0
        public void ThreadTask()
        {
            while (!stop)
            {
                try
                {
                    ThreadEventDispatch.WaitOne(Timeout.Infinite);

                    Image <Bgr, byte> subImage = DetectEyes(frame);
                    mainWindow.ShowImg(frame.Bitmap);
                    if (subImage != null)
                    {
                        DispatchImage.Instance.findEye++;
                        DispatchImage.Instance.findEyeCount++;
                        ThreadReco p = DispatchImage.Instance.GetDispatchedThreadReco();
                        if (p != null)
                        {
                            DispatchImage.Instance.callAPI++;
                            p.frame = subImage;
                            p.ThreadEventReadToFight.Set();
                        }
                        else
                        {
                            DispatchImage.Instance.miss++;
                        }
                    }
                    else
                    {
                        //没找到眼睛
                        DispatchImage.Instance.findEyeCount = 0;
                        DispatchImage.Instance.recoEyeCount = 0;
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    isbusy = false;
                }
            }
        }
示例#3
0
        public ThreadReco GetDispatchedThreadReco()
        {
            bool       isDispatched = false;
            ThreadReco ret          = null;

            foreach (ThreadReco p in thp.threadparallel)
            {
                if (p.isbusy == false)
                {
                    p.isbusy     = true;
                    isDispatched = true;
                    ret          = p;
                    break;
                }
            }
            if (isDispatched == false)
            {
                return(null);
            }
            return(ret);
        }
示例#4
0
        public void Dispath(Image <Bgr, byte> frame_rgb)
        {
            total++;
            if (thSend.isbusy == false)
            {
                thSend.isbusy = true;
                thSend.ThreadEventReadToSend.Set();
            }
            //if (thHist.isbusy == false)
            //{
            //    thHist.isbusy = true;
            //    if (thHist.frame != null)
            //        thHist.frame.Dispose();
            //    thHist.frame = frame_rgb.Copy();
            //    thHist.ThreadEventReadToHist.Set();
            //    ThreadReceiveFromHist.WaitOne(Timeout.Infinite);


            //}


            Image <Bgr, byte> subImage = null;

            if (!mainWindow.ShowRecing)
            {
                subImage = DetectEyes(frame_rgb);
                mainWindow.ShowImg(frame_rgb.Bitmap);

                if (subImage != null)
                {
                    //Show eye
                    DispatchImage.Instance.IsReco = 1;
                    int rand = (new Random()).Next(1, 10);
                    mainWindow.ShowEyeImg(rand);

                    findEye++;
                    findEyeCount++;
                    ThreadReco p = GetDispatchedThreadReco();
                    if (p != null)
                    {
                        validHandle++;
                        p.frame = subImage;
                        p.ThreadEventReadToFight.Set();
                    }
                    else
                    {
                        DispatchImage.Instance.IsReco = 0;
                        mainWindow.ShowEyeImg(-1);
                        miss++;
                    }
                }
                else
                {
                    DispatchImage.Instance.IsReco = 0;
                    mainWindow.ShowEyeImg(-1);
                    //没找到眼睛
                    //findEyeCount = 0;
                    recoEyeCount = 0;
                }
            }
            else
            {
                mainWindow.ShowImg(frame_rgb.Bitmap);
            }
        }