shimat / opencvsharp

OpenCV wrapper for .NET
Apache License 2.0
5.39k stars 1.15k forks source link

VideoCapture Dispose long time. #1705

Open simphonydeveloper opened 4 weeks ago

simphonydeveloper commented 4 weeks ago

Summary of your issue

I dispose VideoCapture on my own computer is very fast, but it closes very slowly on a surface computer. Usually takes 6-7 seconds

Environment

.NET Version:4.8

NUGET:

  <package id="OpenCvSharp4" version="4.10.0.20240616" targetFramework="net48" />
  <package id="OpenCvSharp4.Extensions" version="4.10.0.20240616" targetFramework="net48" />
  <package id="OpenCvSharp4.runtime.win" version="4.10.0.20240616" targetFramework="net48" />
  <package id="OpenCvSharp4.WpfExtensions" version="4.10.0.20240616" targetFramework="net48" />

My PC: WIN10 CPU:Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz 2.59 GHz

Surface GO: WIN10 CPU:Intel(R)N200 1.00 GHZ

What did you do when you faced the problem?

I use task.factory.startnew(()=>{}) to dispose it. but this will cause my content to go white at some point.

Example code:

System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();

//capture.Release();
Task.Factory.StartNew(() =>
{
    capture.Dispose();
});
sw.Stop();
Console.WriteLine("capture" + sw.Elapsed.TotalSeconds);
logger.Info("capture" + sw.Elapsed.TotalSeconds);

Output:

StopCamera Info capture7.7534943

What did you intend to be?

simphonydeveloper commented 1 week ago

Find a possible reason, the Windows Camera Frame Server will occupy CPU 100% when opening the camera, and then VideoCapture Dispose will take a long time.