public partial class Main_View
{
public Main_View()
{
DataContext = new Main_ViewModel();
InitializeComponent();
}
}
Main_ViewModel.cs
public partial class Main_ViewModel : ObservableObject
{
private OpenCv_Model _model;
[ObservableProperty]
private Mat _camera;
public Main_ViewModel()
{
_model = new(0);
GetCamera();
}
void GetCamera()
{
while (true)
{
Camera = _model.GetFrame();
Cv2.WaitKey(50);
Camera.Dispose();
}
}
}
OpenCv_Model.cs
internal class OpenCv_Model
{
VideoCapture capture;
public OpenCv_Model(int nb_device)
{
capture = new VideoCapture(nb_device);
}
public Mat GetFrame()
{
Mat image = new Mat();
capture.Read(image);
return image;
}
}
Output:
Nothing ....
Just want a basic windows with my webcam ....
Summary of your issue
Hi ! I try to devellop an app with OpenCvsharp, in wpf with community toolkit mvvm.
When I try to launch a basic windows with only an image for stream acquisition, the windows doesn't display...
I think it's when I set my VideoCapture, because when I remove it, the windows display normaly.
So, if someone can help me, or show me an exemple code who work ...
Thanks !
Environment
I Use .net 8.0 Visual Studio community 2022![image](https://github.com/shimat/opencvsharp/assets/48790575/69a26bcc-5d28-4572-a246-5244a5f0f24b)
Example code:
main_view.xaml
main_view.xaml.cs
Main_ViewModel.cs
OpenCv_Model.cs
Output:
Nothing .... Just want a basic windows with my webcam ....
Thanks again !!