You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
And it worked fine for the most part. But then about few days ago, My client reported that sometimes after the app loaded and the camera is initialized, The FPS dropped to basically 1-5FPS and look very choppy. I'm able to reproduced by repeatedly re-initialized VideoCapture and out of nowhere it just happened. There is a hack-y workaround and that is close the app and reopen it or repeatly re-initialized the VideoCapture. But i would like a more permanent solution. So i've been basically spending 2 full days trial & error my way to hunting them down. But no luck.
Although I found out that if i change my apiPreferences to VideoCaptureAPIs.MSMF the issue is basically solved. Plus the performance gain is very noticable. But it leads to another problem similar to issue #1663. So now i'm really ran out of options. I also not entirely sure that the API is the one causing the issue, and it might be on my part. But i'm basically hitting the real dead-end here.
I'll try to reproduced with an example. But in the meantime if you can, take a look at my snippet. You may know something that i don't.
Environment
Windows 11 64-Bit.
What did you do when you faced the problem?
Literally opening up the app and start the camera initialization. It happened randomly everytime the camera need to be initialize. Maybe it's memory issue?
videoCapturePresenter = recorderMainAppManager.CreateVideoCapture(
index: camera.Index,
resolution: resolution, //resolutions[resolutions.Count - 1],
fps: ProfilePresenter.CameraFps,
focus: ProfilePresenter.IsAutoFocus ?? (int)AutoFocusStatus.Off
);
captureTokenSource = new();
_captureThread = new Thread(() => CaptureFrame(videoCapturePresenter, captureTokenSource))
{
Name = "Capture Thread",
Priority = ThreadPriority.AboveNormal, ///This is not the cause because i added after i can reproduced the issues.
};
_captureThread.Start();
This is CaptureFrame. I used Cv2.Resize to resize the frame before bringing it to the UI layer. Without it PictureBox will attempted to resize each frame by itself and take half of my available RAM along with it.
This is UI layer. When my camera start producing a frame, it will be sent to PictureBox as video preview for my user.
public void UpdateCameraView(Bitmap img)
{
try
{
if (picRecord.InvokeRequired &&
WindowState != FormWindowState.Minimized)
{
using (picRecord.Image)
{
Invoke(() => picRecord.Image = img);
}
}
}
catch (ObjectDisposedException)
{
// This function throw everytime in debug mode, apparently because some video frame aren't being disposed yet
// But frmMain is already disposed. Happened only when i exit the app.
// For now, this is working. But if you know how to solve this. Feel free.
return;
}
}
Output:
video output that sometimes run fine. Sometimes FPS drop to 1. The log always output `30` however.
What did you intend to be?
Video start without any hitches or slowdown.
The text was updated successfully, but these errors were encountered:
Summary of your issue
My app is Winforms Desktop app using OpenCV to record and stored video files. I'm currently using
And it worked fine for the most part. But then about few days ago, My client reported that sometimes after the app loaded and the camera is initialized, The FPS dropped to basically 1-5FPS and look very choppy. I'm able to reproduced by repeatedly re-initialized VideoCapture and out of nowhere it just happened. There is a hack-y workaround and that is close the app and reopen it or repeatly re-initialized the VideoCapture. But i would like a more permanent solution. So i've been basically spending 2 full days trial & error my way to hunting them down. But no luck.
Although I found out that if i change my
apiPreferences
toVideoCaptureAPIs.MSMF
the issue is basically solved. Plus the performance gain is very noticable. But it leads to another problem similar to issue #1663. So now i'm really ran out of options. I also not entirely sure that the API is the one causing the issue, and it might be on my part. But i'm basically hitting the real dead-end here.I'll try to reproduced with an example. But in the meantime if you can, take a look at my snippet. You may know something that i don't.
Environment
Windows 11 64-Bit.
What did you do when you faced the problem?
Literally opening up the app and start the camera initialization. It happened randomly everytime the camera need to be initialize. Maybe it's memory issue?
Example code:
Create VideoCapture in OpenCVHelper.cs
Now in Presenter layer.
This is CaptureFrame. I used Cv2.Resize to resize the frame before bringing it to the UI layer. Without it PictureBox will attempted to resize each frame by itself and take half of my available RAM along with it.
This is UI layer. When my camera start producing a frame, it will be sent to PictureBox as video preview for my user.
Output:
What did you intend to be?
Video start without any hitches or slowdown.
The text was updated successfully, but these errors were encountered: