예제 #1
0
        private void DoStreaming_SaveData()
        {
            this.m_stopped = false;
            InitStreamState();

            // 设置Playback模式
            manager.captureManager.SetFileName(this.PlaybackFile, false);
            manager.captureManager.SetRealtime(false);

            int nOf = manager.captureManager.QueryNumberOfFrames();

            switch (m_algoOption)
            {
            // 面部算法
            case AlgoOption.Face:
                this.faceModule = manager.QueryFace();
                if (faceModule == null)
                {
                    MessageBox.Show("QueryFace failed"); return;
                }

                InitFaceState();

                this.faceData = this.faceModule.CreateOutput();
                if (faceData == null)
                {
                    MessageBox.Show("CreateOutput failed"); return;
                }

                break;
            }

            if (manager.Init() < pxcmStatus.PXCM_STATUS_NO_ERROR)
            {
#if DEBUG
                System.Windows.Forms.MessageBox.Show("init failed");
#endif
                return;
            }

            FacialLandmarks  fl;
            FacialExpression fe;

            while (!m_stopped)
            {
                if (manager.AcquireFrame(false).IsError())
                {
                    break;
                }

                this.sample = manager.QuerySample();
                //if (sample == null) { manager.ReleaseFrame(); continue; }


                if (sample.depth != null)
                {
                    this.m_timestamp = (sample.depth.timeStamp);
                }
                else if (sample.color != null)
                {
                    this.m_timestamp = sample.color.timeStamp;
                }
                else
                {
                    continue;
                }


                // 仅当下一秒时调用检测算法
                m_timestamp_sec = m_timestamp / 10000000;

                if (m_timestamp_sec_init != -1 && m_timestamp_sec - m_timestamp_sec_init >= nOf)
                {
                    break;
                }

                Console.WriteLine("curframe:" + m_timestamp_sec);

                if (m_timestamp_sec_init == -1)
                {
                    m_timestamp_sec_init = m_timestamp_sec;
                }
                if (m_timestamp_sec_last == -1)
                {
                    m_timestamp_sec_last = m_timestamp_sec - 1;
                }
                long interval = m_timestamp_sec - m_timestamp_sec_last;
                if (interval > 0)
                {
                    if (interval > 1)
                    {
                        for (int i = 1; i < interval; i++)
                        {
                            buffer += (m_timestamp_sec_last + i - m_timestamp_sec_init).ToString() + " ";
                            buffer += "\n";
                            Console.WriteLine((m_timestamp_sec_last + i - m_timestamp_sec_init).ToString());
                        }
                    }

                    buffer += (m_timestamp_sec - m_timestamp_sec_init).ToString() + " ";

                    // 原生算法调用处理,并缓存实时数据
                    faceData.Update();

                    fl = this.GetFaceLandmarks();
                    fe = this.GetExpression();

                    if (fl != null)
                    {
                        buffer += fl.ToString();
                    }
                    else
                    {
                        buffer += FacialLandmarks.generateBlank();
                    }
                    if (fe != null)
                    {
                        buffer += fe.ToString();
                    }
                    else
                    {
                        buffer += FacialExpression.generateBlank();
                    }

                    buffer += "\n";
                    m_timestamp_sec_last = m_timestamp_sec;
                    //Console.WriteLine((m_timestamp_sec- m_timestamp_sec_init).ToString());
                }

                //if(m_timestamp_sec>m_timestamp_sec_last)
                //{
                //    // 原生算法调用处理,并缓存实时数据
                //    faceData.Update();

                //    fl = this.GetFaceLandmarks();
                //    fe = this.GetExpression();
                //    if (fl != null)
                //        buffer += fl.ToString();
                //    if (fe != null)
                //        buffer += fe.ToString();
                //    buffer += "\n";
                //    m_timestamp_sec_last = m_timestamp_sec;
                //    Console.WriteLine(m_timestamp_sec.ToString());
                //}

                // 用于显示视频流功能
                if (m_display)
                {
                    this.DoRender();
                }

                manager.ReleaseFrame();
            }
            faceData.Dispose();
            manager.Dispose();

            Console.WriteLine("done!!!");
        }
예제 #2
0
        private void DoStreaming_SaveData_Do(string file)
        {
            manager.captureManager.SetRealtime(false);
            manager.captureManager.SetFileName(file, true);
            //manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR, 640, 480, 30);

            //manager.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH, 320, 240, 30);

            Console.WriteLine("handling file:\t" + file);

            Console.WriteLine(manager.captureManager.QueryNumberOfFrames().ToString());

            FacialLandmarks  fl;
            FacialExpression fe;


            while (!m_stopped)
            {
                if (manager.AcquireFrame(true).IsError())
                {
                    break;
                }
                //Console.WriteLine(sps.ToString()+"\t"+ manager.captureManager.QueryFrameIndex().ToString());

                this.sample = manager.QuerySample();
                //if (sample == null) { manager.ReleaseFrame(); continue; }



                /******************************************************
                *
                * 1.获取当前Frame
                * 2.判断当前Frame是否有深度或者颜色信息
                *     2.1 如果两者都有,判断时间是否为下一秒
                *         2.1.1 如果是下一秒,处理当前Frame
                *         2.1.2 如果不是,结束本次循环
                *     2.2 如果没有,则结束本次循环
                * ****************************************************/


                if (sample.color != null)
                {
                    this.m_timestamp = sample.color.timeStamp;
                }
                else
                {
                    continue;
                }
                //if (sample.depth != null)
                //    this.m_timestamp = (sample.depth.timeStamp);
                //else if (sample.color != null)
                //    this.m_timestamp = sample.color.timeStamp;
                //else
                //    continue;

                Console.WriteLine(m_timestamp.ToString());

                if (sample.depth != null || sample.color != null)
                {
                    //if (m_timestamp == m_timestamp_last)
                    //{
                    //    break;
                    //}
                    m_timestamp_last = m_timestamp;
                }

                // 仅当下一秒时调用检测算法
                m_timestamp_sec = m_timestamp / 10000000;
                Console.WriteLine("Curframe time :" + m_timestamp_sec);

                if (m_timestamp_sec_init == -1)
                {
                    m_timestamp_sec_init = m_timestamp_sec;
                }
                if (m_timestamp_sec_last == -1)
                {
                    m_timestamp_sec_last = m_timestamp_sec - 1;
                }
                long interval = m_timestamp_sec - m_timestamp_sec_last;
                //if(interval==0)
                //{
                //    break;
                //}
                if (interval > 0)
                {
                    if (interval > 1)
                    {
                        for (int i = 1; i < interval; i++)
                        {
                            buffer += (m_timestamp_sec_last + i - m_timestamp_sec_init).ToString() + " ";
                            buffer += "\n";
                            Console.WriteLine((m_timestamp_sec_last + i - m_timestamp_sec_init).ToString());
                        }
                    }

                    buffer += (m_timestamp_sec - m_timestamp_sec_init).ToString() + " ";

                    // 原生算法调用处理,并缓存实时数据
                    faceData.Update();

                    fl = this.GetFaceLandmarks();
                    fe = this.GetExpression();

                    if (fl != null)
                    {
                        buffer += fl.ToString();
                    }
                    else
                    {
                        buffer += FacialLandmarks.generateBlank();
                    }
                    if (fe != null)
                    {
                        buffer += fe.ToString();
                    }
                    else
                    {
                        buffer += FacialExpression.generateBlank();
                    }

                    buffer += "\n";
                    m_timestamp_sec_last = m_timestamp_sec;


                    //Console.WriteLine((m_timestamp_sec- m_timestamp_sec_init).ToString());
                }

                //if(m_timestamp_sec>m_timestamp_sec_last)
                //{
                //    // 原生算法调用处理,并缓存实时数据
                //    faceData.Update();

                //    fl = this.GetFaceLandmarks();
                //    fe = this.GetExpression();
                //    if (fl != null)
                //        buffer += fl.ToString();
                //    if (fe != null)
                //        buffer += fe.ToString();
                //    buffer += "\n";
                //    m_timestamp_sec_last = m_timestamp_sec;
                //    Console.WriteLine(m_timestamp_sec.ToString());
                //}

                // 用于显示视频流功能
                if (m_display)
                {
                    this.DoRender();
                }

                manager.ReleaseFrame();
            }
        }