/// <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); } } }
public VideoDataLayerTest(VideoDataParameter.VideoType videoType) : base("VideoData Layer Test") { m_videoType = videoType; }