2using System.Collections.Generic;
6using System.Threading.Tasks;
37 object m_objSync =
new object();
38 WebCam.WebCam m_webcam =
null;
39 Bitmap m_bmpSnapshot =
null;
40 AutoResetEvent m_evtSnapshotReady =
new AutoResetEvent(
false);
41 Filter m_filter =
null;
45 List<int> m_rgTopShape;
62 private T[] m_rgTopData =
null;
63 private long m_lDuration = 0;
74 : base(cuda, log, p, db, evtCancel)
136 m_webcam =
new WebCam.WebCam();
137 m_webcam.OnSnapshot += m_webcam_OnSnapshot;
140 if (m_webcam.VideoInputDevices.Count == 0)
144 m_log.
FAIL(
"The video device_id is greater than the number of web cam devices detected (" + m_webcam.VideoInputDevices.Count.ToString() +
").");
147 m_log.
WriteLine(
"Using web-cam '" + m_filter.Name +
"' for video input.");
149 m_webcam.Open(m_filter,
null,
null);
151 if (!m_evtSnapshotReady.WaitOne(1000))
152 m_log.
FAIL(
"Failed to get a web-cam snapshot!");
158 m_webcam =
new WebCam.WebCam();
159 m_webcam.OnSnapshot += m_webcam_OnSnapshot;
168 if (!m_evtSnapshotReady.WaitOne(1000))
169 m_log.
FAIL(
"Failed to get a video snapshot!");
178 m_log.
CHECK(bmp !=
null,
"Could not load an image!");
181 if (bmp.Width != m_nVideoWidth || bmp.Height != m_nVideoHeight)
189 m_rgTopShape =
m_transformer.InferBlobShape(3, bmp.Width, bmp.Height);
190 m_rgTopShape[0] = nBatchSize;
191 colTop[0].
Reshape(m_rgTopShape);
204 colTop[1].
Reshape(rgLabelShape);
213 private void m_webcam_OnSnapshot(
object sender, ImageArgs e)
215 if (m_bmpSnapshot !=
null)
216 m_bmpSnapshot.Dispose();
218 m_bmpSnapshot = e.Image;
219 m_evtSnapshotReady.Set();
228 m_log.
CHECK(batch.
Data.count() > 0,
"There is no space allocated for data!");
232 m_rgTopShape[0] = nBatchSize;
233 batch.
Data.Reshape(m_rgTopShape);
235 T[] rgTopLabel =
null;
237 rgTopLabel = batch.
Label.mutable_cpu_data;
246 int nSkipFrames = m_nSkipFrames;
250 for (
int i = 0; i < nBatchSize; i++)
259 if (m_webcam ==
null)
263 if (!m_evtSnapshotReady.WaitOne(1000))
264 m_log.
FAIL(
"Failed to get web-cam snapshot!");
270 if (m_webcam ==
null)
277 m_webcam.Step(nSkipFrames);
281 if (!m_evtSnapshotReady.WaitOne(1000))
282 m_log.
FAIL(
"Failed to get video file snapshot!");
284 if (m_webcam.IsAtEnd)
285 m_webcam.SetPosition(0);
294 m_log.
CHECK(bmp !=
null,
"Could not load image!");
297 if (bmp.Width != m_nVideoWidth || bmp.Height != m_nVideoHeight)
322 rgTopShape[0] = nBatchSize;
323 batch.
Data.Reshape(rgTopShape);
326 for (
int k = 1; k < rgTopShape.Count; k++)
328 nDim *= rgTopShape[k];
331 int nTopLen = nDim * nBatchSize;
332 if (m_rgTopData ==
null || m_rgTopData.Length != nTopLen)
333 m_rgTopData =
new T[nTopLen];
336 nSkipFrames = m_nSkipFrames;
343 Array.Copy(rgTrans, 0, m_rgTopData, nDim * i, nDim);
347 rgTopLabel[i] = (T)Convert.ChangeType(datum.
Label, typeof(T));
354 batch.
Data.SetCPUData(m_rgTopData);
357 batch.
Label.SetCPUData(rgTopLabel);
The CancelEvent provides an extension to the manual cancel event that allows for overriding the manua...
The ImageData class is a helper class used to convert between Datum, other raw data,...
static Datum GetImageDataD(Bitmap bmp, int nChannels, bool bDataIsReal, int nLabel, bool bUseLockBitmap=true, int[] rgFocusMap=null)
The GetImageDataD function converts a Bitmap into a Datum using the double type for real data.
The Log class provides general output in text form.
void CHECK(bool b, string str)
Test a flag for true.
void WriteLine(string str, bool bOverrideEnabled=false, bool bHeader=false, bool bError=false, bool bDisable=false)
Write a line of output.
void FAIL(string str)
Causes a failure which throws an exception with the desciptive text.
The SimpleDatum class holds a data input within host memory.
int Label
Return the known label of the data.
The Utility class provides general utility funtions.
static List< int > Create(int nCount, int nStart, int nInc)
Create a new List and fill it with values starting with start and incrementing by inc.
The BlobCollection contains a list of Blobs.
void Reshape(int[] rgShape)
Reshapes all blobs in the collection to the given shape.
The CudaDnn object is the main interface to the Low-Level Cuda C++ DLL.
bool m_bOutputLabels
Specifies whether or not the Layer should output labels.
DataTransformer< T > m_transformer
Specifies the DataTransformer used to transform each data item as it loaded.
The BasePrefetchingDataLayer is the base class for data Layers that pre-fetch data before feeding the...
Batch< T >[] m_rgPrefetch
Specifies the pre-fetch cache.
The Batch contains both the data and label Blobs of the batch.
Blob< T > Label
Returns the label Blob of the batch.
Blob< T > Data
Returns the data Blob of the batch.
Log m_log
Specifies the Log for output.
LayerParameter m_param
Specifies the LayerParameter describing the Layer.
LayerParameter.LayerType m_type
Specifies the Layer type.
The VideoDataLayer provides data to the Net from a WebCam or Video file. This layer is initialized wi...
override void load_batch(Batch< T > batch)
Load a batch of data in the background (this is run on an internal thread within the BasePrefetchingD...
override void DataLayerSetUp(BlobCollection< T > colBottom, BlobCollection< T > colTop)
Setup the DataLayer by starting up the pre-fetching.
override void dispose()
Releases all GPU and host resources used by the Layer.
VideoDataLayer(CudaDnn< T > cuda, Log log, LayerParameter p, IXDatabaseBase db, CancelEvent evtCancel)
The VideoDataLayer constructor.
Stopwatch m_swTimerBatch
Specifies a first timer used to calcualte the batch time.
override int ExactNumBottomBlobs
No bottom blobs are used by this layer.
double m_dfTransTime
Specifies the transaction time.
double m_dfReadTime
Specifies the read time.
Stopwatch m_swTimerTransaction
Specfies a second timer used to calculate the transaction time.
override int MinTopBlobs
Specifies the minimum number of required top (output) Blobs: data
virtual uint batch_size
Specifies the batch size.
bool display_timing
(optional, default = false) Specifies whether or not to display the timing of each image read.
Specifies the base parameter for all layers.
DataParameter data_param
Returns the parameter set when initialized with LayerType.DATA
VideoDataParameter video_data_param
Returns the parameter set when initialized with LayerType.VIDEO_DATA
LayerType
Specifies the layer type.
Specifies the parameters for the VideoDataLayer.
uint video_width
Optionally, specifies the video width (default = 400).
VideoType
Defines the video type.
uint skip_frames
Optionally, specifies the number of frames to be skipped before processing a frame (default = 0).
string video_file
Specifies the video file when using the VIDEO type.
int device_id
Specifies the device ID (default = 0).
uint video_height
Optionally, specifies the video height (default = 300).
VideoType video_type
Specifies the video type (default = WEBCAM).
The IXDatabaseBase interface defines the general interface to the in-memory database.
The MyCaffe.basecode contains all generic types used throughout MyCaffe.
The MyCaffe.common namespace contains common MyCaffe classes.
The MyCaffe.data namespace contains dataset creators used to create common testing datasets such as M...
The MyCaffe.db.image namespace contains all image database related classes.
The MyCaffe.layers.ssd namespace contains all Single-Shot MultiBox (SSD) related layers.
The MyCaffe.param.ssd namespace contains all SSD related parameter objects that correspond to the nat...
The MyCaffe.param namespace contains parameters used to create models.
The MyCaffe namespace contains the main body of MyCaffe code that closesly tracks the C++ Caffe open-...