EMGUCV MAT -Objekt ist immer null in .net maui androidC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 EMGUCV MAT -Objekt ist immer null in .net maui android

Post by Anonymous »

Ich möchte Kamera -Frames mit EMGU.cv in .NET MAUI erfassen, und ich habe die Runtime für Maui Android. Ich kann auf die Kamera zugreifen, aber ich konnte das Feed nicht auf MAT -Objekt übertragen. Es ist immer null. Der gleiche Code funktioniert unter Windows -Formularen und WPF, aber auf Maui ist dies nicht der Fall. Auch _capture.imageGrabbed += _capture_imageGrabbed; löst _capture_imageGrabbed Ereignis nicht aus.

Code: Select all




















MainPage.xaml.cs

Code: Select all

public partial class MainPage : ContentPage
{
private VideoCapture _capture = null;
//private bool _captureInProgress;
private Mat _frame;

public MainPage()
{
InitializeComponent();
//CvInvoke.UseOpenCL = false;
CvInvokeAndroid.Init();
_capture = new VideoCapture(0, VideoCapture.API.Android);
_capture.ImageGrabbed += _capture_ImageGrabbed;
_frame = new Mat();
}

private void captureButton_Clicked(object sender, EventArgs e)
{
_capture.Start();
}

private void _capture_ImageGrabbed(object sender, EventArgs e)
{
_capture.Retrieve(_frame, 0);
}

private void ManuelFrame_Clicked(object sender, EventArgs e)
{
_capture.Retrieve(_frame, 0);
if (_frame.IsEmpty)
{
statusLabel.Text = "frame is null";
}
else statusLabel.Text = "frame is not null";
}
}
Bilder



AFTER -BR/> AFTER AFTER REDREVE. /> Ich kann mit der Erfassung auf die Kamera zugreifen, aber ich kann die Erfassung nicht auf _Frame -Objekt übertragen. Ich habe versucht, Android -API in 33 (Android 13) zu wechseln. Es hat nicht funktioniert. Ich habe ein Manuel -Event für das Abrufen von Rahmen gesetzt. Es hat auch nicht funktioniert. Was kann ich tun? />

Code: Select all

public partial class MainPage : ContentPage
{
private VideoCapture _capture = null;
//private bool _captureInProgress;
private Mat _mat;
private Mat _renderMat;
private string _defaultButtonText = "Start Camera";
protected string _StopCameraButtonText = "Stop Camera";
private string _deaultImage;
ButtonTextImagePage buttonPage = new ButtonTextImagePage();

private IProcessAndRenderModel _model;

public MainPage()
{
InitializeComponent();
//CvInvoke.UseOpenCL = false;
CvInvokeAndroid.Init();
InitVideoCapture();
}

private void _capture_ImageGrabbed(object sender, EventArgs e)
{
if (_mat == null)
_mat = new Mat();
_capture.Retrieve(_mat);

if (_renderMat == null)
_renderMat = new Mat();

_mat.CopyTo(_renderMat);
}

protected virtual async void captureButton_Clicked(object sender, EventArgs e)
{
var button = buttonPage.GetButton();

if(captureButton.Text.Equals(_StopCameraButtonText))
{
#if __ANDROID__ && __USE_ANDROID_CAMERA2__
StopCapture();
//AndroidImageView.Visibility = ViewStates.Invisible;
#else
_capture.Stop();
_capture.Dispose();
_capture = null;
#endif
captureButton.Text = _defaultButtonText;
return;
}

Mat[] images;
if(_deaultImage == null)
{
images = new Mat[0];
}
else
{
images = await buttonPage.LoadImages(new string[] { _deaultImage });

if (images == null || (images.Length > 0 && images[0] == null)) return;
}

if(images.Length == 0)
{
#if __ANDROID__ && __USE_ANDROID_CAMERA2__

StartCapture(async delegate (Object captureSender, Mat m)
{
//Skip the frame if busy,
//Otherwise too many frames arriving and will eventually saturated the memory.
if (!_isBusy)
{
_isBusy = true;
try
{
String message = String.Empty;
await Task.Run(() =>
{
if (_renderMat == null)
_renderMat = new Mat();
using (InputArray iaImage = m.GetInputArray())
{
iaImage.CopyTo(_renderMat);
}
message = _model.ProcessAndRender(m, _renderMat);
});
SetImage(_renderMat);
SetMessage(message);

}
finally
{
_isBusy = false;
}
}
});
#else
//Handle video
if (_capture == null)
{
InitVideoCapture();
}

if (_capture != null)
_capture.Start();
#endif
captureButton.Text = _StopCameraButtonText;
}
else
{
if (_renderMat == null) _renderMat = new Mat();
images[0].CopyTo(_renderMat);
}

}

private void InitVideoCapture()
{
var openCVConfigDict = CvInvoke.ConfigDict;
bool haveVideoio = (openCVConfigDict["HAVE_OPENCV_VIDEOIO"] != 0);
if (haveVideoio && Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.Android)
{
#if __ANDROID__ && __USE_ANDROID_CAMERA2__
return true;
#else
if (CvInvoke.Backends.Length >  0)
{
if (Microsoft.Maui.Devices.DeviceInfo.Platform == DevicePlatform.Android)
{
_capture = new VideoCapture(0, VideoCapture.API.Android);
}
else
{
_capture = new VideoCapture();
}
if (_capture.IsOpened)
{
_capture.ImageGrabbed += _capture_ImageGrabbed;
return;
}
else
{
_capture.Dispose();
_capture = null;
}
}
#endif
}
return;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post