@@ -47,15 +47,22 @@ public AppViewModel()
4747 private List < MediaFrameSourceGroup > _mediaFrameSourceGroupList ;
4848 private MediaFrameSourceGroup _selectedMediaFrameSourceGroup ;
4949 private MediaFrameSource _selectedMediaFrameSource ;
50+ public int dummyFPS = 10 ;
5051
5152 // Style transfer effect properties
5253 private LearningModel m_model = null ;
5354 private LearningModelDeviceKind m_inferenceDeviceSelected = LearningModelDeviceKind . Default ;
5455 private LearningModelSession m_session ;
5556 private LearningModelBinding m_binding ;
56- string m_inputImageDescription ;
57- string m_outputImageDescription ;
58- IMediaExtension videoEffect ;
57+ private string m_inputImageDescription ;
58+ private string m_outputImageDescription ;
59+ private IMediaExtension videoEffect ;
60+ public readonly List < string > modelFileNames = new List < string >
61+ { "candy" ,
62+ "mosaic" ,
63+ "la_muse" ,
64+ "udnie"
65+ } ;
5966
6067 // Image style transfer properties
6168 uint m_inWidth , m_inHeight , m_outWidth , m_outHeight ;
@@ -66,19 +73,12 @@ public AppViewModel()
6673 private SolidColorBrush _successColor = new SolidColorBrush ( Windows . UI . Colors . Green ) ;
6774 private SolidColorBrush _failColor = new SolidColorBrush ( Windows . UI . Colors . Red ) ;
6875
69-
7076 private AppModel _appModel ;
7177 public AppModel CurrentApp
7278 {
7379 get { return _appModel ; }
7480 }
7581
76- // Command defintions
77- public ICommand SaveCommand { get ; set ; }
78- public ICommand SetMediaSourceCommand { get ; set ; }
79- public ICommand ChangeLiveStreamCommand { get ; set ; }
80- public ICommand SetModelSourceCommand { get ; set ; }
81-
8282 private SoftwareBitmapSource _inputSoftwareBitmapSource ;
8383 public SoftwareBitmapSource InputSoftwareBitmapSource
8484 {
@@ -110,34 +110,22 @@ public string StatusMessage
110110 set { _notifyMessage = value ; OnPropertyChanged ( ) ; OnPropertyChanged ( "StatusBarColor" ) ; }
111111 }
112112
113+ // Command defintions
114+ public ICommand SaveCommand { get ; set ; }
115+ public ICommand SetMediaSourceCommand { get ; set ; }
116+ public ICommand ChangeLiveStreamCommand { get ; set ; }
117+ public ICommand SetModelSourceCommand { get ; set ; }
118+
113119 public async void SaveOutput ( )
114120 {
115121 Debug . WriteLine ( "UIButtonSaveImage_Click" ) ;
116- if ( _appModel . InputMedia == "LiveStream" )
117- {
118-
119- var previewProperties = _mediaCapture . VideoDeviceController . GetMediaStreamProperties ( MediaStreamType . VideoPreview ) as VideoEncodingProperties ;
120-
121- // Create the video frame to request a SoftwareBitmap preview frame
122- var videoFrame = new VideoFrame ( BitmapPixelFormat . Bgra8 , ( int ) previewProperties . Width , ( int ) previewProperties . Height ) ;
123-
124- // Capture the preview frame
125- using ( var currentFrame = await _mediaCapture . GetPreviewFrameAsync ( videoFrame ) )
126- {
127- SoftwareBitmap previewFrame = currentFrame . SoftwareBitmap ;
128- await ImageHelper . SaveVideoFrameToFilePickedAsync ( videoFrame ) ;
129- }
130- }
131- else await ImageHelper . SaveVideoFrameToFilePickedAsync ( _appModel . OutputFrame ) ;
132-
133- return ;
122+ if ( _appModel . InputMedia != "LiveStream" ) await ImageHelper . SaveVideoFrameToFilePickedAsync ( _appModel . OutputFrame ) ;
134123 }
135124
136- public async Task SetMediaSource ( string obj )
125+ public async Task SetMediaSource ( string src )
137126 {
138- _appModel . InputMedia = obj ;
127+ _appModel . InputMedia = src ;
139128
140- // TODO: Reset media source stuff: set Camera input controls visibility to 0, etc.
141129 CleanupCameraAsync ( ) ;
142130 CleanupInputImage ( ) ;
143131 NotifyUser ( true ) ;
@@ -167,7 +155,6 @@ public async Task SetMediaSource(string obj)
167155
168156 public async Task SetModelSource ( )
169157 {
170- // Clean up model, etc. by setting to null?
171158 await LoadModelAsync ( ) ;
172159
173160 switch ( _appModel . InputMedia )
@@ -199,7 +186,6 @@ private async Task StartAcquireImage()
199186 if ( file != null )
200187 {
201188 _appModel . InputFrame = await ImageHelper . LoadVideoFrameFromStorageFileAsync ( file ) ;
202-
203189 }
204190 else
205191 {
@@ -226,8 +212,6 @@ public async Task StartFilePick()
226212 {
227213 }
228214 await ChangeImage ( ) ;
229-
230-
231215 }
232216 catch ( Exception ex )
233217 {
@@ -251,6 +235,7 @@ public async Task ChangeImage()
251235
252236 private async Task EvaluateVideoFrameAsync ( )
253237 {
238+ Debug . WriteLine ( "EvaluateVideoFrameAsync" ) ;
254239 Debug . WriteLine ( "Has Direct3dsurface" , _appModel . InputFrame . Direct3DSurface != null ) ;
255240 if ( ( _appModel . InputFrame != null ) &&
256241 ( _appModel . InputFrame . SoftwareBitmap != null || _appModel . InputFrame . Direct3DSurface != null ) )
@@ -308,9 +293,8 @@ public async Task ChangeLiveStream()
308293 Debug . WriteLine ( "ChangeLiveStream" ) ;
309294 SaveEnabled = false ;
310295
311-
312296 // If webcam hasn't been initialized, bail.
313- if ( _mediaFrameSourceGroupList == null ) { return ; }
297+ if ( _mediaFrameSourceGroupList == null ) return ;
314298
315299 try
316300 {
@@ -375,15 +359,13 @@ private async Task LoadModelAsync()
375359 StorageFile modelFile = await StorageFile . GetFileFromApplicationUriAsync ( new Uri ( $ "ms-appx:///Assets/{ _appModel . ModelSource } .onnx") ) ;
376360 m_model = await LearningModel . LoadFromStorageFileAsync ( modelFile ) ;
377361
378- // TODO: Pass in useGPU as well.
379362 m_inferenceDeviceSelected = _appModel . UseGPU ? LearningModelDeviceKind . DirectX : LearningModelDeviceKind . Cpu ;
380363 m_session = new LearningModelSession ( m_model , new LearningModelDevice ( m_inferenceDeviceSelected ) ) ;
381364 m_binding = new LearningModelBinding ( m_session ) ;
382365
383366 debugModelIO ( ) ;
384367
385368 m_inputImageDescription = m_model . InputFeatures . ToList ( ) . First ( ) . Name ;
386-
387369 m_outputImageDescription = m_model . OutputFeatures . ToList ( ) . First ( ) . Name ;
388370 }
389371
@@ -437,7 +419,6 @@ private void CleanupCameraAsync()
437419 {
438420 videoEffect = null ;
439421 }
440- // TODO: Add inputmediasource once can show both at the same time
441422 }
442423
443424 catch ( Exception ex )
0 commit comments