我的应用程序从另一台计算机的套接字接收USB相机帧流:Windows 10 UWP应用程序从USB相机读取格式为ARGB32的帧。
我想在iPad上显示每一帧,以获得实时取景。
我认为ImageView控件是最好的。
框架的来源是Windows 10上的.NET UWP MediaFrameReader,它来自Logitech HD1080p USB网络摄像头。
有关在Windows计算机上创建框架并将其发送到iPad插槽之前的更多详细信息...
WINDOWS 10上的此代码从相机接收到帧...
private void Reader_FrameArrived(MediaFrameReader sender, MediaFrameArrivedEventArgs args)
{
// Update GUI frame count:
SDKTemplate.Scenario1_DisplayDepthColorIR.present_frame_count++;
// TryAcquireLatestFrame will return the latest frame that has not yet been acquired.
// This can return null if there is no such frame, or if the reader is not in the
// "Started" state. The latter can occur if a FrameArrived event was in flight
// when the reader was stopped.
//using (MediaFrameReference frame = sender.TryAcquireLatestFrame())
using (MediaFrameReference frame = sender.TryAcquireLatestFrame())
{
// Display locally:
_frameRenderer.ProcessFrame(frame);
}
}
此代码准备框架将从WINDOWS发送到IPAD插座...
public void ProcessFrame( MediaFrameReference frame)
{
var softwareBitmap = FrameRenderer.ConvertToDisplayableImage(frame?.VideoMediaFrame);
if (softwareBitmap != null)
{
++arrived_frames;
uint frame_size_bytes = frame.BufferMediaFrame.Buffer.Length;
// Swap the processed frame to _backBuffer and trigger UI thread to render it
softwareBitmap = Interlocked.Exchange(ref _backBuffer, softwareBitmap);
// UI thread always reset _backBuffer before using it. Unused bitmap should be disposed.
softwareBitmap?.Dispose();
//////////////////////// DISPLAY FRAME LOCALLY /////////////////////////
// Changes to xaml ImageElement must happen in UI thread through Dispatcher
var task = _imageElement.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
async () =>
{
// Don't let two copies of this task run at the same time.
if (_taskRunning)
{
return;
}
_taskRunning = true;
// Keep draining frames from the backbuffer until the backbuffer is empty.
SoftwareBitmap latestBitmap;
while ((latestBitmap = Interlocked.Exchange(ref _backBuffer, null)) != null)
{
var imageSource = (SoftwareBitmapSource)_imageElement.Source;
await imageSource.SetBitmapAsync(latestBitmap);
SDKTemplate.SOURCE.Frames_To_iPad.send_frame_packet( latestBitmap, frame_size_bytes );
latestBitmap.Dispose();
}
_taskRunning = false;
});
//////////////////////////// SEND TO IPAD //////////////////////////////
}
}
答案 0 :(得分:0)
您可以尝试在每次接收到新帧时设置UIImageView
的Image
属性,但是我怀疑这种转换是否能够足够快地进行以使视频流畅显示,因为您需要进行转换您可以将每个帧分配给UIImage
属性,然后才能将其分配给Image
属性。
我只是使用本地HD大小的图像进行了快速测试,它的跟踪似乎确实非常流畅。图像是存储在应用程序捆绑包中的PNG图像,我不确定从插槽中接收图像时将采用哪种格式。