USB camera poor lighting and resolution on new Windows 10 install

I recently installed a fresh copy of Windows 10 on a NVMe. OpenCV on this Windows 10 install displays the frames in poor resolution and lighting. OpenCV worked just fine on my old Windows 10 on my SATA SSD.

OBS Studio can display my USB camera frame just fine on both Windows Install.

Only OpenCV 4.x PreBuild can display proper resolution and lighting on my Windows 10 NVMe install, but the frame rate is very low.

Can someone please help me with this issue? I’m running the same code on both Windows 10 install.

I already tried building and using prebuilds for OpenCV 3.x and 4.5.1.

#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

cv::VideoCapture cap(0);

int main() {

cap.set(cv::CAP_PROP_FRAME_WIDTH, 1280);
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 720);

cv::Mat frame;
while (true) {

  cap >> frame;
  cv::imshow("frame", frame);
  char c = (char)cv::waitKey(1);
  if (c == 27)
  	break;

}

cap.release();
cv::destroyAllWindows();

return 0;
}

It seems unlikely that the drive has any influence as you are not reading from or writing to it. It sounds like the whole computer is different, meaning perhaps a different camera, slightly different Windows configuration and so on. Reporting the exact model of the camera might help someone give advice about it.

I’m mainly use a ELP-USBFHD01M-L21, but I have the same problem for any camera I am using. For both my Windows 10 installs, all the hardware is the same. Both hard drives that contain my Windows 10 share all the same computer hardware. Removing my old SSD does not solve the problem.

you are sitting in a dark room. webcams will always have trouble with that.

some webcams have “low light compensation”, which increases the exposure time (drops frame rate) to gather more light, so the picture doesn’t have to be too noisy/grainy.

what’s going on is that OBS maybe sets those camera attributes, while OpenCV doesn’t know that it should.

you should look at the properties the VideoCapture class understands, and try some of them.

@crackwitz Thanks for the reply, but it doesn’t matter if the room is dark, because the video feed was still good on OpenCV on my old Windows 10 install. For my new Windows 10 install, here’s what I did to match the OpenCV settings to the OBS settings:

cap.set(cv::CAP_PROP_BRIGHTNESS, 0);
cap.set(cv::CAP_PROP_CONTRAST, 32);
cap.set(CV_CAP_PROP_HUE, 0);
cap.set(CV_CAP_PROP_SATURATION, 60);
cap.set(CV_CAP_PROP_SHARPNESS, 2);
cap.set(CV_CAP_PROP_GAMMA, 100);
cap.set(CV_CAP_PROP_BACKLIGHT, 1);
cap.set(CV_CAP_PROP_GAIN, 0);
cap.set(cv::CAP_PROP_AUTO_EXPOSURE, 1);

But the frames still look the same. The only thing that makes a difference is:

cap.set(cv::CAP_PROP_EXPOSURE, -5);

But still, the frames are not as good as on my old Windows 10 install or OBS studio.

This seems like an OpenCV backend problem. Because it views OK on 4.5.1 prebuild I would guess that it is using a different way to access the camera.

Can you set OPENCV_VIDEOIO_DEBUG=1 environment variable before launch to see what video backend is loading?

I’m having a hard time with ‘OPENCV_VIDEOIO_DEBUG=1’. In Google, I can’t find examples of OpenCV code using ‘OPENCV_VIDEOIO_DEBUG’, can you please tell me how to use this?

The only documentation I know is the opencv source class documents for cv::videoio_registry here:
https://docs.opencv.org/3.4/de/db1/group__videoio__registry.html

Looking here is how I found these variables.

There are 3 possible variables:
OPENCV_VIDEOIO_DEBUG, OPENCV_VIDEOCAPTURE_DEBUG, OPENCV_VIDEOWRITER_DEBUG

When they are set as environment variables in a debug version of OPENCV you get some debug output like this (yours will vary depending on how you write debug output. Mine is written using Qt message handler). It tells what back ends are available and what loads and if it load successfully.

[ INFO:0] global X:\some\path\420\source\modules\videoio\src\videoio_registry.cpp (187) cv::`anonymous-namespace’::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(7, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940)
[ WARN:0] global X:\some\path\420\source\modules\videoio\src\cap.cpp (92) cv::VideoCapture::open VIDEOIO(FFMPEG): trying capture filename=’’ …
[ INFO:0] global X:\some\path\420\source\modules\videoio\src\backend_plugin.cpp (353) cv::impl::getPluginCandidates Found 2 plugin(s) for FFMPEG
[ INFO:0] global X:\some\path\opencv\420\source\modules\videoio\src\backend_plugin.cpp (172) cv::impl::DynamicLib::libraryLoad load X:\some\path\420\build_msvc2017\x64\dynamic\bin\Debug\opencv_videoio_ffmpeg420_64.dll => OK
[ INFO:0] global X:\some\path\opencv\420\source\modules\videoio\src\backend_plugin.cpp (233) cv::impl::PluginBackend::PluginBackend Video I/O: loaded plugin ‘FFmpeg OpenCV Video I/O plugin’
[ WARN:0] global X:\some\path\opencv\420\source\modules\videoio\src\cap.cpp (104) cv::VideoCapture::open VIDEOIO(FFMPEG): created, isOpened=1

My OpenCV has always shown the [INFO:0], maybe because I always run in debug?

Here is what I get for OpenCV 3.4.2 Prebuild on both my new and old Windows 10 Install:

[ INFO:0] VIDEOIO: Enabled backends(6, sorted by priority): FFMPEG(1000); MSMF(990); DSHOW(980); VFW(970); CV_IMAGES(960); CV_MJPEG(950)

Here is what I get for OpenCV 4.5.1 PreBuild for my new Windows 10 Install:

[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\videoio_registry.cpp (197) cv::`anonymous-namespace’::VideoBackendRegistry::VideoBackendRegistry VIDEOIO: Enabled backends(8, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); MSMF(970); DSHOW(960); CV_IMAGES(950); CV_MJPEG(940); UEYE(930)
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (396) cv::impl::getPluginCandidates Found 2 plugin(s) for GSTREAMER
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (175) cv::impl::DynamicLib::libraryLoad load C:\OpenCV4.5.1-PreBuild\opencv\build\x64\vc14\bin\opencv_videoio_gstreamer451_64d.dll => FAILED
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (175) cv::impl::DynamicLib::libraryLoad load opencv_videoio_gstreamer451_64d.dll => FAILED
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (396) cv::impl::getPluginCandidates Found 2 plugin(s) for MSMF
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (175) cv::impl::DynamicLib::libraryLoad load C:\OpenCV4.5.1-PreBuild\opencv\build\x64\vc14\bin\opencv_videoio_msmf451_64d.dll => OK
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (245) cv::impl::PluginBackend::PluginBackend Video I/O: initialized ‘Microsoft Media Foundation OpenCV Video I/O plugin’: built with OpenCV 4.5 (ABI/API = 0/0), current OpenCV version is ‘4.5.1’ (ABI/API = 0/1)
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (256) cv::impl::PluginBackend::PluginBackend Video I/O: NOTE: plugin is supported, but there is API version mismath: plugin API level (0) != OpenCV API level (1)
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (259) cv::impl::PluginBackend::PluginBackend Video I/O: NOTE: some functionality may be unavailable due to lack of support by plugin implementation
[ INFO:0] global C:\build\master_winpack-build-win64-vc14\opencv\modules\videoio\src\backend_plugin.cpp (262) cv::impl::PluginBackend::PluginBackend Video I/O: plugin is ready to use ‘Microsoft Media Foundation OpenCV Video I/O plugin’