VideoCapture/DSHOW : Allow to set CAP_PROP_CONVERT_RGB before FOURCC/FPS/CHANNEL/WIDTH/HEIGHT.#19370
Conversation
a6ecf9d to
dcfe6c0
Compare
|
I pushed a new commit OlivierLDff@2b415a3 that should fix every case. Something like that now works: cap.set(cv::CAP_PROP_CONVERT_RGB, false);
cap.set(cv::CAP_PROP_FPS, 60);
cap.set(cv::CAP_PROP_FRAME_WIDTH, 320 );
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 256);
cap.set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('Y', '1', '6', ' '));
|
dcfe6c0 to
2b415a3
Compare
alalek
left a comment
There was a problem hiding this comment.
Thank you for contribution!
Could you please add your usecase as "disabled" test into this file?
TEST(DISABLED_videoio_camera, dshow_fourcc_y16)
{
... initialize "cap" with properties ...
Mat lastFrame;
test_readFrames(capture, 100, &lastFrame);
ASSERT_FALSE(lastFrame.empty());
EXPECT_EQ(CV_16UC1, lastFrame.type()); // <== change actual value here
}
…olean value on first property set.
|
Test added b868c39. git clone https://github.com/OlivierLDff/opencv
cd opencv
git checkout patch-dshow-convertrgb
mkdir build && cd build
cmake -DBUILD_TESTS=ON ..
# Test Debug
cmake --build . --target opencv_test_videoio --config "Debug"
./bin/Debug/opencv_test_videoiod.exe --gtest_filter=*dshow_convert_rgb_persistency* --gtest_also_run_disabled_tests
# Test Release
cmake --build . --target opencv_test_videoio --config "Release"
./bin/Release/opencv_test_videoio.exe --gtest_filter=*dshow_convert_rgb_persistency* --gtest_also_run_disabled_testsIf you want the test to fail, simply restore opencv/modules/videoio/src/cap_dshow.cpp Lines 3482 to 3485 in 1363496 |
|
I see that |
alalek
left a comment
There was a problem hiding this comment.
Thank you for update!
You can ignore infrastructure (network) issues on China OpenCV CI. "default" is required to be green for now.
modules/videoio/test/test_camera.cpp
Outdated
| { | ||
| VideoCapture capture(CAP_DSHOW); | ||
| ASSERT_TRUE(capture.isOpened()); | ||
| ASSERT_TRUE(capture.set(CAP_PROP_CONVERT_RGB, false)); |
There was a problem hiding this comment.
Please avoid build warning here:
ASSERT_TRUE(capture.set(CAP_PROP_CONVERT_RGB, 0/*false*/));
bf6460c to
913739b
Compare
| std::cout << " height: " << capture.get(CAP_PROP_FRAME_HEIGHT) << std::endl; | ||
| std::cout << "Capturing FPS: " << capture.get(CAP_PROP_FPS) << std::endl; | ||
| ASSERT_DOUBLE_EQ(capture.get(CAP_PROP_CONVERT_RGB), 0); | ||
| capture.release(); |
There was a problem hiding this comment.
Please add lastFrame check (as proposed above).
Look like CAP_PROP_CONVERT_RGB=0 + CAP_PROP_FOURCC=Y16 still doesn't work: .type() is 8UC3, frame is in color.
You can add this for local experiments:
imshow("test", lastFrame);
waitKey();
There was a problem hiding this comment.
This is not the bug this PR is correcting.
This PR is correcting the fact that CONVERT_RGB once set to false should stay false no matters if width/height/fourcc/fps is set after.
This is what my test is doing. This is what my PR is merging. This is not related to the fact i'm opening my camera in Y16.
If you look implementation, it seems like convertRgb is used only with MEDIASUBTYPE_Y16, so yes it is linked a little bit with Y16.
The fact that CAP_PROP_CONVERT_RGB=0 + CAP_PROP_FOURCC=Y16 doesn't give 16U mat is another bug. If the camera support being opened in Y16 mode, then CV_16UC1 == lastFrame.type()
I tested with FLIR Boson320 i can confirm, the read frame is CV_16UC1.
When opening my webcam with the same code (just changing the id), the result mat is CV_8UC3.
This might be another bug, but this is unrelated to what my PR fix.
The code that doesn't open Y16 if camera doesn't support is there i believe:
opencv/modules/videoio/src/cap_dshow.cpp
Lines 2616 to 2623 in 900051c
From reading source code it also seems that CAP_PROP_CONVERT_RGB=1 + CAP_PROP_FOURCC=Y8 will give you CV_8UC1 as output
opencv/modules/videoio/src/cap_dshow.cpp
Lines 3562 to 3569 in 900051c
There was a problem hiding this comment.
This might be another bug, but this is unrelated to what my PR fix.
OK.
Please fix remaining coding style issue (check "Docs" builder logs) before merge.
There was a problem hiding this comment.
I'm not sure to understand, where in Docs builder? I'm not familiar with Jenkins.
There was a problem hiding this comment.
"default" entry: http://pullrequest.opencv.org/#/summary/opencv
|
Can you please retrigger |
|
This build is optional. Problem is infrastructure(network) related. Ignore this. |
VideoCapture/DSHOW : Allow to set CAP_PROP_CONVERT_RGB before FOURCC/FPS/CHANNEL/WIDTH/HEIGHT. * 🐛 cap_dshow : Allow to set CAP_PROP_CONVERT_RGB before FOURCC/FPS/CHANNEL * 🐛 cap_dshow : fix g_VI.setConvertRGB not being called with correct boolean value on first property set. * ✅ cap_dshow : Test CAP_PROP_CONVERT_RGB persistence * 🚨 Fix cast from bool to double * 🚨 Fix trailing whitespace
Related issue : #19367
The PR fixed it the case to set FOURCC/FPS/CHANNEL & CONVERT_RGB in any order.
Every time
stopDeviceis called,setConvertRgbshould be called again with correct value.For example settings
FPSafter CONVERT_RGB:opencv/modules/videoio/src/cap_dshow.cpp
Lines 3455 to 3467 in ea41f89
Same for
CHANNELopencv/modules/videoio/src/cap_dshow.cpp
Lines 3447 to 3453 in ea41f89
And when settings
FOURCC/WIDTH/HEIGHTopencv/modules/videoio/src/cap_dshow.cpp
Lines 3494 to 3500 in ea41f89
Detailed description
I'm using Boson camera from FLIR. I'm interested in Y16 format video. I'm using DSHOW backend on windows.
I noticed that setting
CAP_PROP_CONVERT_RGBthen something likeCAP_PROP_FOURCCwill revertCAP_PROP_CONVERT_RGBto the default value.Steps to reproduce
Proposed solution
I fixed it into a fork.
I introduced a
m_convertRGBSetboolean value insideVideoCapture_DShowthat is updated whenCAP_PROP_CONVERT_RGBis set.Then i call
g_VI.setConvertRGBwhen g_VI get reinitialized with the saved value.Current workaround
I believe what everyone is doing right now is first set
CAP_PROP_FOURCCthenCAP_PROP_CONVERT_RGB.Especially boson user, like it is shown on FLIR website
I believe it should work in both order. Or it should be documented somewhere.
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.