private void CalculateLBP(object parameter)
        {
            LBPHistogrammThreadParameter input = parameter as LBPHistogrammThreadParameter;

            if (parameter == null)
            {
                throw new ArgumentException("Неправильный формат параметра потока.");
            }

            for (int i = input.From; i < input.To; ++i)
            {
                var feature = GetLBPFeature(input.List[i]);
                input.Result.Add(feature);
            }
            input.ResetEvent.Set();
        }
        private List <LBPFeature> GetSubfeatures()
        {
            var fragments   = GetFragments();
            int threadCount = Math.Min(fragments.Count, RecognitionParameters.FragmentProcessThreadCount);

            threadCount = (isMultithread) ? (threadCount) : (1);
            int threadPart       = fragments.Count / threadCount;
            var resetEvents      = new ManualResetEvent[threadCount];
            var threadParameters = new LBPHistogrammThreadParameter[threadCount];

            for (int i = 0; i < threadCount; ++i)
            {
                resetEvents[i]      = new ManualResetEvent(false);
                threadParameters[i] = new LBPHistogrammThreadParameter(
                    threadPart * i,
                    ((i + 1) < threadCount) ? (threadPart * (i + 1)) : (fragments.Count),
                    fragments, resetEvents[i]);
                if (threadCount > 1)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(CalculateLBP), threadParameters[i]);
                }
                else
                {
                    CalculateLBP(threadParameters[i]);
                }
            }
            WaitHandle.WaitAll(resetEvents);

            var list = new List <LBPFeature>();

            for (int i = 0; i < threadCount; ++i)
            {
                list.AddRange(threadParameters[i].Result);
            }
            return(list);
        }
예제 #3
0
        private List<LBPFeature> GetSubfeatures()
        {
            var fragments = GetFragments();
            int threadCount = Math.Min(fragments.Count, RecognitionParameters.FragmentProcessThreadCount);
            threadCount = (isMultithread) ? (threadCount) : (1);
            int threadPart = fragments.Count / threadCount;
            var resetEvents = new ManualResetEvent[threadCount];
            var threadParameters = new LBPHistogrammThreadParameter[threadCount];
            for (int i = 0; i < threadCount; ++i)
            {
                resetEvents[i] = new ManualResetEvent(false);
                threadParameters[i] = new LBPHistogrammThreadParameter(
                    threadPart * i,
                    ((i + 1) < threadCount) ? (threadPart * (i + 1)) : (fragments.Count),
                    fragments, resetEvents[i]);
                if (threadCount > 1)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(CalculateLBP), threadParameters[i]);
                }
                else
                {
                    CalculateLBP(threadParameters[i]);
                }
            }
            WaitHandle.WaitAll(resetEvents);

            var list = new List<LBPFeature>();
            for (int i = 0; i < threadCount; ++i)
            {
                list.AddRange(threadParameters[i].Result);
            }
            return list;
        }