Пример #1
0
        private unsafe Target[] SearchFaces()
        {
            IntPtr retTarget = IntPtr.Zero;

            int count = NativeIconExtractor.SearchFaces(ref retTarget);

            if (count <= 0)
            {
                return(new Target[0]);
            }

            Target *pTarget = (Target *)retTarget;

            IList <Target> targets = new List <Target>();

            for (int i = 0; i < count; i++)
            {
                Target face = pTarget[i];
                targets.Add(face);
            }

            Target[] tgArr = new Target[targets.Count];
            targets.CopyTo(tgArr, 0);

            return(tgArr);
        }
Пример #2
0
        private static void SetupExtractor(int envMode, float leftRatio,
                                           float rightRatio,
                                           float topRatio,
                                           float bottomRatio,
                                           int minFaceWidth,
                                           float maxFaceWidthRatio,
                                           Rectangle SearchRectangle)
        {
            NativeIconExtractor.SetExRatio(topRatio,
                                           bottomRatio,
                                           leftRatio,
                                           rightRatio);

            NativeIconExtractor.SetROI(SearchRectangle.Left,
                                       SearchRectangle.Top,
                                       SearchRectangle.Width - 1,
                                       SearchRectangle.Height - 1);

            NativeIconExtractor.SetFaceParas(minFaceWidth, maxFaceWidthRatio);

            NativeIconExtractor.SetLightMode(envMode);
        }
Пример #3
0
        unsafe void SearchFace()
        {
            while (true)
            {
                Frame[] frames = null;
                lock (locker)
                {
                    if (framesQueue.Count > 0)
                    {
                        frames = framesQueue.Dequeue();
                    }
                }

                if (frames != null)
                {
                    for (int i = 0; i < frames.Length; ++i)
                    {
                        DateTime dt = DateTime.FromBinary(frames[i].timeStamp);

                        NativeIconExtractor.AddInFrame(frames[i]);
                    }

                    IntPtr target = IntPtr.Zero;

                    int count = NativeIconExtractor.SearchFaces(ref target);
                    if (count > 0)
                    {
                        Target *pTarget = (Target *)target;

                        IList <Target> targets = new List <Target>();

                        int upLimit = count;

                        if (frames.Length > 1 && Properties.Settings.Default.DetectMotion &&
                            Properties.Settings.Default.removeDuplicatedFace)
                        {
                            upLimit = Math.Min(count, Properties.Settings.Default.MaxDupFaces);
                        }

                        for (int i = 0; i < upLimit; i++)
                        {
                            Target face = pTarget[i];

                            Frame frm = face.BaseFrame;

                            int idx = Array.FindIndex(frames, fm => fm.cameraID == frm.cameraID &&
                                                      fm.image == frm.image &&
                                                      fm.timeStamp == frm.timeStamp);

                            Debug.Assert(idx != -1);

                            targets.Add(face);
                        }

                        Target[] tgArr = new Target[targets.Count];

                        targets.CopyTo(tgArr, 0);


                        ImageDetail[] imgs = this.SaveImage(tgArr);
                        this.screen.ShowImages(imgs);
                    }


                    NativeIconExtractor.ReleaseMem();

                    Array.ForEach(frames, f => Cv.Release(ref f.image));
                }
                else
                {
                    goSearch.WaitOne();
                }
            }
        }
Пример #4
0
        private void DetectSuspecious(Target[] targets)
        {
            foreach (var t in targets)
            {
                for (int i = 0; i < t.Faces.Length; ++i)
                {
                    IplImage normalized = Program.faceSearch.NormalizeImage(t.BaseFrame.image, t.FacesRectsForCompare[i]);

                    float[] imgData = NativeIconExtractor.ResizeIplTo(normalized, 100, 100, BitDepth.U8, 1);

                    if (IsGoodGuy(imgData))
                    {
                        return;
                    }

                    FaceRecognition.RecognizeResult[] results = new
                                                                FaceRecognition.RecognizeResult[Program.ImageSampleCount];


                    FaceRecognition.FaceRecognizer.Recognize(
                        imgData,
                        Program.ImageSampleCount,
                        results,
                        Program.ImageLen, Program.EigenNum);


                    FaceRecognition.RecognizeResult[] filtered =
                        Array.FindAll(results, r => r.similarity > 0.85);


                    if (filtered.Length == 0)
                    {
                        return;
                    }

                    int j = 0;

                    IList <ImportantPersonDetail> details =
                        new List <ImportantPersonDetail>();

                    foreach (PersonInfo p in SuspectsRepositoryManager.Instance.Peoples)
                    {
                        foreach (FaceRecognition.RecognizeResult result in filtered)
                        {
                            string fileName = System.IO.Path.GetFileName(result.fileName);

                            int idx = fileName.IndexOf('_');
                            fileName = fileName.Remove(idx, 5);

                            if (string.Compare(fileName, p.FileName, true) == 0)
                            {
                                details.Add(new ImportantPersonDetail(p, result));
                            }
                        }
                    }

                    ImportantPersonDetail[] distinct = details.Distinct(new ImportantPersonComparer()).ToArray();

                    if (distinct.Length == 0)
                    {
                        return;
                    }

                    screen.ShowSuspects(distinct, t.Faces[i].ToBitmap());
                }
            }
        }
Пример #5
0
        private void DetectMotion()
        {
            DateTime      lastTime    = DateTime.Now.AddMinutes(-3);
            CvVideoWriter videoWriter = null;
            uint          count       = 0;

            while (true)
            {
                Frame newFrame = GetNewFrame();
                if (newFrame.image != IntPtr.Zero)
                {
                    DateTime dtFrame = DateTime.FromBinary(newFrame.timeStamp);

                    IplImage ipl = new IplImage(newFrame.image);
                    ipl.IsEnabledDispose = false;

                    //new minute start, create new vide file
                    if (dtFrame.Minute != lastTime.Minute)
                    {
                        if (videoWriter != null)
                        {
                            Cv.ReleaseVideoWriter(videoWriter);
                            videoWriter = null;
                        }


                        videoWriter = Cv.CreateVideoWriter(
                            @"d:\" + dtFrame.Minute + ".avi",
                            "XVID",
                            10,
                            ipl.Size
                            );

                        System.Diagnostics.Debug.WriteLine(@"d:\" + dtFrame.Minute + ".avi");
                    }

                    videoWriter.WriteFrame(ipl);

                    lastTime = dtFrame;

                    Frame frameToProcess = new Frame();

                    bool groupCaptured = false;

                    count++;

                    if (count % 5 == 0)
                    {
                        if (Properties.Settings.Default.DetectMotion)
                        {
                            groupCaptured =
                                MotionDetect.MotionDetect.PreProcessFrame(newFrame, ref frameToProcess);
                        }
                        else
                        {
                            groupCaptured = NoneMotionDetect.PreProcessFrame(newFrame, ref frameToProcess);
                        }
                    }
                    else
                    {
                        Cv.Release(ref newFrame.image);
                    }

                    count %= uint.MaxValue;

                    if (IsStaticFrame(frameToProcess))
                    {
                        Cv.Release(ref frameToProcess.image);
                    }
                    else
                    {
                        SaveFrame(frameToProcess);
                        NativeIconExtractor.AddInFrame(frameToProcess);
                        motionFrames.Enqueue(frameToProcess);
                    }

                    if (groupCaptured)
                    {
                        Target[] tgts = SearchFaces();

                        //remove duplicated faces
                        int upLimit = tgts.Length;

                        if (Properties.Settings.Default.DetectMotion &&
                            Properties.Settings.Default.removeDuplicatedFace)
                        {
                            upLimit = Math.Min(upLimit, Properties.Settings.Default.MaxDupFaces);
                        }

                        Target[] removed = new Target[upLimit];
                        Array.ConstrainedCopy(tgts, 0, removed, 0, upLimit);

                        ImageDetail[] details = this.SaveImage(removed);
                        this.screen.ShowImages(details);

                        Frame[] frames = motionFrames.ToArray();
                        motionFrames.Clear();

                        //release memory
                        Array.ForEach(frames, f => Cv.Release(ref f.image));
                    }
                }
                else
                {
                    goDetectMotion.WaitOne();
                }
            }
        }