public static string GetFacePath(Frame frame, DateTime timeStamp, int sequence)
        {
            string folderFace = FileSystemStorage.FolderForFaces(frame.cameraID, timeStamp);

            string faceFileName = FileSystemStorage.GetFaceFileName(frame.GetFileName(), sequence);

            string facePath = Path.Combine(folderFace, faceFileName);
            return facePath;
        }
        public static bool PreProcessFrame(Frame frame, ref Frame lastFrame)
        {
            OpenCvSharp.IplImage ipl = new OpenCvSharp.IplImage(frame.image);
            ipl.IsEnabledDispose = false;

            lastFrame = frame;
            lastFrame.searchRect = new CvRect(0, 0, ipl.Width, ipl.Height);

            return true;
        }
        public static void SaveFrame(Frame frame)
        {
            IplImage ipl = new IplImage(frame.image);
            ipl.IsEnabledDispose = false;

            string path = frame.GetFileName();
            DateTime dt = DateTime.FromBinary(frame.timeStamp);

            string root = Path.Combine(Properties.Settings.Default.OutputPath,
                      frame.cameraID.ToString("d2"));

            string folder = FileSystemStorage.BuildDestDirectory(root, dt, Properties.Settings.Default.BigImageDirectoryName);
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            path = Path.Combine(folder, path);
            ipl.SaveImage(path);
        }
示例#4
0
 public static extern bool PreProcessFrame(Frame frame, ref Frame lastFrame);
        public static void SaveFrame(Frame frame)
        {
            IplImage ipl = frame.image;
            ipl.IsEnabledDispose = false;

            string path = frame.GetFileName();
            DateTime dt = DateTime.FromBinary(frame.timeStamp);

            string root = RootStoragePathForCamera(frame.cameraID);
            string folder = BuildBigImgPath(root, dt);
            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            path = Path.Combine(folder, path);
            ipl.SaveImage(path);
        }
        public static string PathForFaceImage(Frame frame, int sequence)
        {
            DateTime dt = DateTime.FromBinary(frame.timeStamp);

            string folderFace = FileSystemStorage.EnsureFolderForFacesAt(frame.cameraID, dt);

            string faceFileName = FileSystemStorage.FaceImageFileNameOf(frame.GetFileName(), sequence);

            string facePath = Path.Combine(folderFace, faceFileName);
            return facePath;
        }
 public List<Portrait> ProcessFrame(Frame motionFrame, System.Threading.CancellationToken cancellationToken)
 {
     _cancellationToken = cancellationToken;
     var portraits = HandleMotionFrame(motionFrame);
     return portraits;
 }
 public List<Portrait> HandleMotionFrame(Frame motionFrame)
 {
     return this.SearchIn(motionFrame);
 }
        private List<Portrait> SearchIn(Frame motionFrame)
        {
            var faces = this.searcher.SearchFace(motionFrame.GetImage());

            if (faces.Length == 0)
            {
                motionFrame.Dispose();
                return new List<Portrait>(0);
            }

            var portraitQuery = from f in faces
                                let faceImg = motionFrame.GetImage().GetSub(f.Bounds)
                                select new Portrait(faceImg)
                                {
                                    FaceBounds = f.FaceBoundsInPortrait,
                                    Frame = motionFrame.Clone(),
                                    CapturedAt = motionFrame.CapturedAt,
                                    DeviceId = motionFrame.DeviceId,
                                };

            return portraitQuery.ToList();
        }
示例#10
0
        private void QueryRawFrame()
        {
            byte[] image = camera.CaptureImageBytes();

            MemoryStream memStream = new MemoryStream(image);
            Bitmap bmp = null;
            try
            {
                bmp = (Bitmap)Image.FromStream(memStream);
            }
            catch (System.ArgumentException)//图片格式出错
            {
                return;
            }

            Frame f = new Frame();
            f.timeStamp = DateTime.Now.Ticks;
            f.image = IntPtr.Zero;
            f.cameraID = 2;

            IplImage ipl = BitmapConverter.ToIplImage(bmp);
            ipl.IsEnabledDispose = false;
            f.image = ipl.CvPtr;

            screen.LiveImage = bmp;

            lock (this.rawFrameLocker) rawFrames.Enqueue(f);

            goDetectMotion.Set();
        }
示例#11
0
        private Frame GetNewFrame()
        {
            Frame newFrame = new Frame();

            lock (this.rawFrameLocker)
            {
                if (rawFrames.Count > 0)
                {
                    newFrame = rawFrames.Dequeue();
                }
            }
            return newFrame;
        }
示例#12
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();

            }
        }
示例#13
0
 private static bool IsStaticFrame(Frame aFrame)
 {
     return aFrame.image != null
             && (aFrame.searchRect.Width == 0 || aFrame.searchRect.Height == 0);
 }
示例#14
0
        private static unsafe string GetFacePath(Frame frame, DateTime dt, int j)
        {
            string folderFace = FolderForFaces(frame.cameraID, dt);

            string faceFileName = GetFaceFileName(frame.GetFileName(), j);

            string facePath = Path.Combine(folderFace, faceFileName);
            return facePath;
        }
 public static extern void AddInFrame(Frame frame);
示例#16
0
        private void DetectMotion()
        {
            while (true)
            {
                Frame newFrame = GetNewFrame();
                if (newFrame.image != IntPtr.Zero)
                {
                    Frame frameToProcess = new Frame();

                    bool groupCaptured = MotionDetect.MotionDetect.PreProcessFrame(newFrame, ref frameToProcess);

                    Debug.WriteLine(DateTime.FromBinary(frameToProcess.timeStamp));

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

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

                        if (frames.Length <= 0) continue;

                        lock (locker) framesQueue.Enqueue(frames);

                        goSearch.Set();

                    }

                }
                else
                    goDetectMotion.WaitOne();

            }
        }