opencvsharp icon indicating copy to clipboard operation
opencvsharp copied to clipboard

`VideoCapture.Open()` is significantly slower on x64 as compared to x86.

Open xytec opened this issue 4 years ago • 4 comments

Summary of your issue

VideoCapture.Open() is significantly slower on x64 as compared to x86. x64: 5 to 10 seconds x86: 1 to 2 seconds

I noticed this issue was raised but there wasn't a solution.

Environment

OpenCvSharp-4.5.3-20210821 .NET Framework 4.7.2 Windows 10 64-bit

What did you do when you faced the problem?

I ran the sample project provided (Added a x64 configuration).

  • \Sample-4.5.3-20210821\VideoCaptureForm

Example code:

paste your core code

Output:

paste your output

What did you intend to be?

xytec avatar Nov 05 '21 10:11 xytec

What Capture API do you use? You haven't posted any sample code to reproduce. But i also noticed that - when getting webcam streams - camera.Set(OpenCvSharp.VideoCaptureProperties.FourCC, OpenCvSharp.VideoWriter.FourCC("MJPG")) and VideoCaptureAPIs.MSMF takes a very long time to load (10 seconds) compared to VideoCapturesAPIs.DSHOW which loads instantly. Set the Capture API manually, instead of VideoCaptureAPIs.ANY. This will also remove weird webcam artifacts!

Timocop avatar Nov 10 '21 04:11 Timocop

Thanks! Setting it to VideoCapturesAPIs.DSHOW solved the issue.

I was running the sample code provided (The exact project was mentioned in my post above, so I did not think it was necessary to post the code).

xytec avatar Nov 12 '21 02:11 xytec

It seems to be this issue opencv/opencv#17687 Adding Environment.SetEnvironmentVariable("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0"); will fix it. Using VideoCapturesAPIs.DSHOW also works but it gave me a much choppier stream

bryansiebert avatar Feb 21 '22 09:02 bryansiebert

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Sep 21 '22 00:09 stale[bot]

I have the same issue when i run the application using any cpu it take 2sec to laod the camera. when using x64 it takes 14sec!

alexSmail avatar Feb 02 '23 15:02 alexSmail

It seems to be this issue opencv/opencv#17687 Adding Environment.SetEnvironmentVariable("OPENCV_VIDEOIO_MSMF_ENABLE_HW_TRANSFORMS", "0"); will fix it. Using VideoCapturesAPIs.DSHOW also works but it gave me a much choppier stream

It work!

ucool-wu avatar Jan 15 '24 10:01 ucool-wu