Beispiel #1
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            Filter filter  = listView1.SelectedItems[0].Tag as Filter;
            string strFile = null;

            btnStep.Enabled = false;
            btnPlay.Enabled = false;
            btnStop.Enabled = false;
            lblEnd.Visible  = false;

            if (filter == null)
            {
                if (!string.IsNullOrEmpty(m_strDefaultFolder))
                {
                    openFileDialog1.InitialDirectory = m_strDefaultFolder;
                }

                if (!string.IsNullOrEmpty(m_strDefaultFile))
                {
                    openFileDialog1.FileName = m_strDefaultFile;
                }

                if (openFileDialog1.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                btnStep.Enabled = true;
                btnPlay.Enabled = true;
                btnStop.Enabled = true;
                lblEnd.Visible  = true;

                strFile = openFileDialog1.FileName;
            }

            m_evtCancel.Reset();
            bool bCreated = false;

            if (chkCreateOnSeparateThread.Checked)
            {
                m_taskCreate = Task.Factory.StartNew(new Action <object>(createThread), new Tuple <Filter, string>(filter, strFile));
                bCreated     = true;
            }

            if (chkRunOnSeparateThread.Checked)
            {
                m_taskCmd = Task.Factory.StartNew(new Action(testThread));
            }

            if (!bCreated)
            {
                m_webCam.Open(filter, pictureBox1, strFile);
            }
        }
Beispiel #2
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();
        }
        /// <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);
                }
            }
        }