admin管理员组文章数量:1123793
I need to collect video streams from a microscope and used SDL's library to obtain the data frameData. However, I didn't know how to parse the video stream data in frameData to create videos that Unity could use。
public class CameraStreamManager : MonoBehaviour
{
private Thread cameraThread;
private bool isRunning = false;
private SLcamNet.NetCamera _camera;
private Texture2D videoTexture;
public RawImage videoImage;
private List<NetInfo> _infos;
private CameraInfo _cameraInfo;
private SDLPanel sdlPanel;
private Task _task;
private int width = 1920;
private int height = 1080;
private bool frameReady = false;
public void InitializeCamera()
{
SLcamNet.NetCamera.InitNet();
_infos = SLcamNet.NetCamera.SearchAvailableCameras();
if (_infos.Count < 1)
{
Thread.Sleep(100);
_infos = SLcamNet.NetCamera.SearchAvailableCameras();
}
}
public void OpenCamera()
{
sdlPanel?.Dispose();
sdlPanel = new SDLPanel
{
Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right
};
Debug.LogError("_infos>>>> " + _infos.Count);
if (_infos.Count < 1)
{
Thread.Sleep(100);
_infos = SLcamNet.NetCamera.SearchAvailableCameras();
return;
}
CameraSettings settings = new CameraSettings
{
netInfo = _infos[0],
resolution = new CameraResolution(1920, 1080),
streamFormat = StreamFormat.kMJPEG,
pixFormat = PixFormat.kRGBA8888,
rcMode = "cbr",
quality = "high",
frameRate = 25,
bitrate = 86000,
keyFrameInterval = 90
};
settingsInfo.Username = "admin";
settingsInfo.Password = "123456";
_camera = SLcamNet.NetCamera.Create(settingsInfo.Model);
_camera.SetCameraSettings(settings);
_camera.Login();
_cameraInfo = _camera.GetNetCameraAllInfo();
_camera.Open();
isRunning = true;
_task = Task.Run(() => StartCameraCapture());
}
private void StartCameraCapture()
{
Task.Run(() =>
{
Thread.Sleep(500);
IntPtr frameDataPtr = IntPtr.Zero;
while (isRunning)
{
try
{
if (!_camera.GetVideoFrameData(ref frameDataPtr))
continue;
SLcamNet.l_md_data_t frameData = SLcamNet.l_md_data_t.FromIntPtr(frameDataPtr);
Debug.LogError("frameData>>>>>" + frameData.p_rgb);
}
catch (Exception ex)
{
Debug.LogError($"Error in StartCameraCapture: {ex.Message}");
}
}
});
}
private void OnApplicationQuit()
{
isRunning = false;
_task = null;
if (sdlPanel != null)
{
sdlPanel.Dispose(true);
sdlPanel = null;
}
_camera?.Close();
}
}
本文标签: cUnity obtains sdl and collects RGB raw dataStack Overflow
版权声明:本文标题:c# - Unity obtains sdl and collects RGB raw data - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736596938a1945162.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论