コード例 #1
0
        public void StartCaptureInit(int type, int camIndex, string filename)
        {
            if (MediaHandler != null)
            {
                Timer.Stop();
                MediaHandler.Dispose();
            }

            try
            {
                if (Connection.IsOpen())
                {
                    Connection.Close();
                    ResultUC.AppendServerMsg("Successfully disconnected from the server [" + NetworkOptionsWindow + "].");
                }

                IPAddress ip = IPAddress.Parse(NetworkOptionsWindow.ServerIp);
                Connection.Open(new IPEndPoint(ip, NetworkOptionsWindow.ServerPort));

                ResultUC.AppendServerMsg("A connection was successfully established with the server [" + NetworkOptionsWindow + "]");
            }
            catch (Exception e)
            {
                ResultUC.AppendServerMsg(e.Message);
            }


            if (type == 0)
            {
                MediaHandler = new MediaHandler(camIndex);

                MultimediaUC.VideoLengthSlider.Value = 0;

                CamZeroMenuItem.Header = "_Stop capture";
                MultimediaUC.StartCaptureButton.Content = "Stop";
                WindowMain.Title = Properties.Resources.MainWindowTitle + " - Webcam #" + camIndex;
            }
            else
            {
                MediaHandler = new MediaHandler(filename);

                MultimediaUC.VideoLengthSlider.Value = 0;

                CamZeroMenuItem.Header = "_Start capture";
                MultimediaUC.StartCaptureButton.Content = "Stop";
                WindowMain.Title = Properties.Resources.MainWindowTitle + " - " + filename;
            }

            Timer.Start();
        }
コード例 #2
0
        public void StopCaptureInit()
        {
            if (MediaHandler != null)
            {
                Timer.Stop();
                MediaHandler.Dispose();
            }

            Connection.Close();
            ResultUC.AppendServerMsg("Successfully disconnected from the server [" + NetworkOptionsWindow + "].");

            CamZeroMenuItem.Header = "_Start capture";
            MultimediaUC.StartCaptureButton.Content = "Start";
            MultimediaUC.VideoLengthSlider.Value    = 0;
            WindowMain.Title = Properties.Resources.MainWindowTitle;

            using (var multimediaBackground = new Image <Bgr, byte>(Properties.Resources.mf))
            {
                MultimediaUC.CurFrame.Source = multimediaBackground.Bitmap.ToWpfBitmap();
            }
        }
コード例 #3
0
        public void ProcessFrame(object sender, EventArgs et)
        {
            MemoryStream ms = null;

            try
            {
                Image <Bgr, byte> curFrame = MediaHandler.QueryFrame();

                if (curFrame == null)
                {
                    StopCaptureInit();
                    throw (new Exception("frame == NULL!"));
                }

                ms = curFrame.Bitmap.BitmapToStream();

                ImageInformation.control_ID  = 0xaa;
                ImageInformation.frame_count = UInt32.Parse(MediaHandler.FrameNo.ToString(CultureInfo.InvariantCulture));
                ImageInformation.depth       = (int)Image <Bgr, byte> .CvDepth;
                ImageInformation.nChannels   = curFrame.NumberOfChannels;
                ImageInformation.width       = curFrame.Width;
                ImageInformation.height      = curFrame.Height;
                ImageInformation.pTracking   = ProcessOptionsWindow.PTracking;
                ImageInformation.pExpression = ProcessOptionsWindow.PExpression;
                ImageInformation.size        = ms.GetBuffer().Length;

                // Küldés szervernek, erre a válasz "ACK1".
                byte[] data = RawSerializeEx(ImageInformation);
                Connection.Send(data, Marshal.SizeOf(ImageInformation));

                byte[] recv;
                if ((recv = Connection.Receive()) != null)
                {
                    string sRecv = Encoding.ASCII.GetString(recv);
                    if (sRecv == "ACK1")
                    {
                        Connection.Send(ms.GetBuffer());
                        //ResultUC.AppendServerMsg( sRecv );
                    }
                    else if (sRecv == "ERR1")
                    {
                        System.Threading.Thread.Sleep(10);
                        throw (new Exception("TCPIP recv() error - ERR1."));
                    }
                }
                else
                {
                    throw (new Exception("TCPIP recv() error #1 - recv() == NULL."));
                }

                ms.Flush();
                ms.Close();

                if ((recv = Connection.Receive()) != null)
                {
                    string sRecv = Encoding.ASCII.GetString(recv);
                    if (String.Compare(sRecv.Substring(0, 4), "ERR2") != 0)
                    {
                        if (String.CompareOrdinal(sRecv.Substring(0, 4), "####") != 0)
                        {
                            ResultUC.AppendServerMsg(sRecv);
                        }
                        else
                        {
                            Features = ResultUC.ProcessResults(sRecv, curFrame);
                        }

                        // Az aktuális frame kifeszítése a WPF Image controlra
                        MultimediaUC.CurFrame.Source = curFrame.Bitmap.ToWpfBitmap();
                    }
                    else
                    {
                        throw (new Exception("TCPIP recv() error - ERR2."));
                    }
                }
                else
                {
                    System.Threading.Thread.Sleep(10);
                    throw (new Exception("TCPIP recv() error #2 - recv() == NULL"));
                }
            }
            catch (Exception e)
            {
                Timer.Stop();

                if (ms != null)
                {
                    ms.Flush();
                    ms.Close();
                }

                ResultUC.AppendServerMsg(e.Message);
                StopCaptureInit();
            }

            double playRate = Math.Abs(MediaHandler.FrameCount - 0) > Double.Epsilon ? MediaHandler.FrameNo / MediaHandler.FrameCount : 0;

            MultimediaUC.VideoLengthSlider.Value = MultimediaUC.VideoLengthSlider.Maximum * playRate;
        }