예제 #1
0
        private void createThread(object obj)
        {
            Tuple <Filter, string> args = obj as Tuple <Filter, string>;

            m_webCam             = new WebCam.WebCam();
            m_webCam.OnSnapshot += m_webCam_OnSnapshot;
            m_webCam.Open(args.Item1, null, args.Item2);
            m_evtCreateDone.Set();

            m_evtCancel.WaitOne();
            m_webCam.Close();
        }
        /** @copydoc Layer::dispose */
        protected override void dispose()
        {
            base.dispose();

            lock (m_objSync)
            {
                if (m_webcam != null)
                {
                    m_webcam.Close();
                    m_webcam.Dispose();
                    m_webcam = null;
                    m_filter = null;
                }
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (wCam == null)
     {
         wCam = new WebCam {
             Container = pictureBox1
         };
         wCam.OpenConnection();
         timer1.Start();
         button1.Text = "Stop WebCam";
     }
     else
     {
         timer1.Stop();
         wCam.Dispose();
         wCam         = null;
         button1.Text = "Start WebCam";
     }
 }
        /// <summary>
        /// Setup the DataLayer by starting up the pre-fetching.
        /// </summary>
        /// <param name="colBottom">Not used.</param>
        /// <param name="colTop">Specifies the collection of top (output) Blobs.</param>
        protected override void DataLayerSetUp(BlobCollection <T> colBottom, BlobCollection <T> colTop)
        {
            Bitmap bmp = null;

            int nBatchSize = (int)m_param.data_param.batch_size;

            m_videoType    = m_param.video_data_param.video_type;
            m_nSkipFrames  = (int)m_param.video_data_param.skip_frames;
            m_nVideoWidth  = (int)m_param.video_data_param.video_width;
            m_nVideoHeight = (int)m_param.video_data_param.video_height;

            // Read an image and use it to initialize the top blob.
            if (m_videoType == VideoDataParameter.VideoType.WEBCAM)
            {
                m_webcam             = new WebCam.WebCam();
                m_webcam.OnSnapshot += m_webcam_OnSnapshot;

                // Default 'source' is a Video File.
                if (m_webcam.VideoInputDevices.Count == 0)
                {
                    m_log.FAIL("Could not find a web-cam!");
                }

                if (m_param.video_data_param.device_id >= m_webcam.VideoInputDevices.Count)
                {
                    m_log.FAIL("The video device_id is greater than the number of web cam devices detected (" + m_webcam.VideoInputDevices.Count.ToString() + ").");
                }

                m_filter = m_webcam.VideoInputDevices[m_param.video_data_param.device_id];
                m_log.WriteLine("Using web-cam '" + m_filter.Name + "' for video input.");

                m_webcam.Open(m_filter, null, null);
                m_webcam.GetImage();
                if (!m_evtSnapshotReady.WaitOne(1000))
                {
                    m_log.FAIL("Failed to get a web-cam snapshot!");
                }

                bmp = m_bmpSnapshot;
            }
            else if (m_videoType == VideoDataParameter.VideoType.VIDEO)
            {
                m_webcam             = new WebCam.WebCam();
                m_webcam.OnSnapshot += m_webcam_OnSnapshot;

                if (!File.Exists(m_param.video_data_param.video_file))
                {
                    m_log.FAIL("The video file '" + m_param.video_data_param.video_file + "' does not exist!");
                }

                m_log.WriteLine("Using video source '" + m_param.video_data_param.video_file + "' for video input.");

                m_lDuration = m_webcam.Open(null, null, m_param.video_data_param.video_file);
                m_webcam.GetImage();
                if (!m_evtSnapshotReady.WaitOne(1000))
                {
                    m_log.FAIL("Failed to get a video snapshot!");
                }

                bmp = m_bmpSnapshot;
            }
            else
            {
                m_log.FAIL("Unknown video type!");
            }

            m_log.CHECK(bmp != null, "Could not load an image!");

            // Resize the image if needed.
            if (bmp.Width != m_nVideoWidth || bmp.Height != m_nVideoHeight)
            {
                Bitmap bmpNew = ImageTools.ResizeImage(bmp, m_nVideoWidth, m_nVideoHeight);
                bmp.Dispose();
                bmp = bmpNew;
            }

            // Use data_transformer to infer the expected blob shape from a bitmap.
            m_rgTopShape    = m_transformer.InferBlobShape(3, bmp.Width, bmp.Height);
            m_rgTopShape[0] = nBatchSize;
            colTop[0].Reshape(m_rgTopShape);

            for (int i = 0; i < m_rgPrefetch.Length; i++)
            {
                m_rgPrefetch[i].Data.Reshape(m_rgTopShape);
            }

            m_log.WriteLine("Output data size: " + colTop[0].shape_string);

            // Label.
            if (m_bOutputLabels)
            {
                List <int> rgLabelShape = MyCaffe.basecode.Utility.Create <int>(1, nBatchSize);
                colTop[1].Reshape(rgLabelShape);

                for (int i = 0; i < m_rgPrefetch.Length; i++)
                {
                    m_rgPrefetch[i].Label.Reshape(rgLabelShape);
                }
            }
        }
예제 #5
0
 public Form1()
 {
     InitializeComponent();
     webCam = new WebCam(pictureBox1);
 }