Modify the outputVideoFormat after changing the output format in MSMF backend #24142
After changing the output format, need to modify the outputVideoFormat, otherwise the outputVideoFormat is always CV_CAP_MODE_BGR, and an error will occur when converting the format in retrieveVideoFrame(), and will always enter "case CV_CAP_MODE_BGR:" process.
### Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
- [ ] I agree to contribute to the project under Apache 2 License.
- [ ] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [ ] The PR is proposed to the proper branch
- [ ] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
Co-authored-by: 李龙 <lilong@sobey.com>
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
add video capture parameters
* add parameters
* videoio: revert unnecessary massive changes
* videoio: support capture parameters in backends API
- add tests
- FFmpeg backend sample code
- StaticBackend API is done
- support through PluginBackend API will be added later
Co-authored-by: Milashchenko <maksim.milashchenko@intel.com>
Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
Enable frame timestamp tests for MSMF
Add functional test for camera live timestamps
Remove trailing whitespace
Add timestamp test to all functional tests. Protect div by 0
Add Timestamps to MSMF Video Capture by index
Implement Camera Multiplexing API
* IdideoCapture + two wrong function
function waitAny
Add errors catcher
Stub for Python added.
Sifting warnings
One test added
Two tests for camera and Perf tests added
* Perf sync and async tests for waitAny() added, waitAnyInterior() deleted, getDeviceHandle() deleted
* Variable OPENCV_TEST_CAMERA_LIST added
* Without fps set
* ASSERT_FAILED for environment variable
* Perf tests is DISABLED_
* --Trailing whitespace
* Return false from cap.cpp deleted
* Two functions deleted from interface, +range for, +environment variable in test_camera
* Space deleted
* printf deleted, perror added
* CV_WRAP deleted, cv2 cleared from stubs
* -- space
* default timeout added
* @param changed
* place of waitAny changed
* --whitespace
* ++function description
* function description changed
* revert unused changes
* videoio: rework API for VideoCapture::waitAny()
V4L (V4L2): Refactoring. Added missed camera properties. Fixed getting `INF` for some properties. Singlethread as always (#12893)
* cap_v4l:
1 Added cap_properties verbalization.
2 Set Get of properties elementary refactoring.
3 Removed converting parameters to/from [0,1] range.
4 Added all known conversion from V4L2_CID_* to CV_CAP_PROP_*
* cap_v4l:
1. Removed all query for parameters range.
2. Refactored capture initialization.
3. Added selecting input channel by CV_CAP_PROP_MODE. Default value -1 the channels not changed.
* cap_v4l:
1. Refactoring of Convert To RGB
* cap_v4l:
1. Fixed use of video buffer index.
2. Removed extra memcopy for grab image.
3. Removed device closing from autosetup_capture_mode_v4l2
* cap_v4l:
1. The `goto` was eliminated
2. Fixed use of temporary buffer index for V4L2_PIX_FMT_SN9C10X
3. Fixed use of the bufferIndex
4. Removed trailing spaces and unused variables.
* cap_v4l:
1. Alias for capture->buffers[capture->bufferIndex]
2. Reduced size of data for memcpy: bytesused instead of length
3. Refactoring. Code duplication. More info for debug
* cap_v4l:
1. Added the ability to grab and retrieveFrame independently several times
* cap_v4l:
1. Not need to close/open device for new capture parameters applying.
2. Removed using of device name as a flag that the capture is closed. Added sufficient function.
3. Refactoring. Added requestBuffers and createBuffers
* cap_v4l:
1. Added tryIoctl with `select` like was in mainloop_v4l2.
2. Fixed buffer request for device without closing the device.
3. Some static function moved to CvCaptureCAM_V4L
4. Removed unused defines
* cap_v4l:
1. Thread-safe now
* cap_v4l:
1. Fixed thread-safe destructor
2. Fixed FPS setting
* Missed brake
* Removed thread-safety
* cap_v4l:
1. Reverted conversion parameters to/from [0,1] by default for backward compatibility.
2. Added setting for turn off compatibility mode: set CV_CAP_PROP_MODE to 65536
3. Most static functions moved to CvCaptureCAM_V4L
4. Refactoring of icvRetrieveFrameCAM_V4L and using of frame_allocated flag
* cap_v4l:
1. Added conversion to RGB from NV12, NV21
2. Refactoring. Removed wrappers for known format conversions.
* Added `CAP_PROP_CHANNEL` to the enum VideoCaptureProperties.
CAP_V4L migrated to use VideoCaptureProperties.
* 1. Update comments.
2. Environment variable `OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED` for setting default backward compatibility mode.
3. Revert getting of `CAP_PROP_MODE` as fourcc code in backward compatibility mode.
* videoio: update cap_v4l - compatibilityMode => normalizePropRange
* videoio(test): V4L2 MJPEG test
`v4l2-ctl --list-formats` should have 'MJPG' entry
* videoio: fix buffer initialization
to avoid "munmap: Invalid argument" messages
* Update videoio.hpp
add VideoCapturePropertie for clossbar input pin setting
* Update cap_dshow.cpp
For some kind of capture card, such as "avermedia cv710 " , it use SerialDigital as input pin and so it can not work.
Here added new PhysicalConnectorType enumeration: PhysConn_Video_YRYBY and PhysConn_Video_SerialDigital to support it.
And also provide new property parameter CAP_CROSSBAR_INPIN_TYPE to set the crossbar input pin type which will be used in videoInput::start(int deviceID, videoDevice *VD):
" if(VD->useCrossbar)
{
DebugPrintOut("SETUP: Checking crossbar\n");
routeCrossbar(&VD->pCaptureGraph, &VD->pVideoInputFilter, VD->connection, CAPTURE_MODE);
}
"
And at last ,fixed one issue for function setSizeAndSubtype, added code
pVih->rcSource.top = pVih->rcSource.left = pVih->rcTarget.top =pVih->rcTarget.left=0;
pVih->rcSource.right = pVih->rcTarget.right= attemptWidth;
pVih->rcSource.bottom = pVih->rcTarget.bottom = attemptHeight;
without these code , rcSource and rcTarget will keeping use default resolution and cause fail in hr = VD->streamConf->SetFormat(VD->pAmMediaType) and cannot find suitable MediaType.
Tested with python3 and mfc (Avermedia cv710)
Python3 code:
import cv2
print("test cv")
cap=cv2.VideoCapture(0)
cap.set(5,60)
cap.set(3,1920)
cap.set(4,1080)
cap.set(31,6)
ret,img=cap.read()
cv2.namedWindow("cap",cv2.WINDOW_NORMAL)
cv2.resizeWindow("cap",960,640);
while True:
ret,img=cap.read()
if ret==False:
continue
cv2.imshow("cap",img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
MFC code:
void CcvtestDlg::OnBnClickedButton1()
{
VideoCapture cap(0);
cap.set(CAP_PROP_FRAME_WIDTH, 1920);
cap.set(CAP_PROP_FRAME_HEIGHT, 1080);
cap.set(CAP_CROSSBAR_INPIN_TYPE , 6);
Mat img;
namedWindow("test", WINDOW_NORMAL);
resizeWindow("test", 960, 640);
while (1)
{
if (cap.read(img))
{
imshow("test", img);
if ('q' ==waitKey(1))
break;
}
}
destroyAllWindows();
cap.release();
}
* Update cap_dshow.cpp
* Update videoio.hpp
move enum value of CAP_CROSSBAR_INPIN_TYPE to the end of list
* Update videoio.hpp
* Update cap_dshow.cpp
removed trailing whitespace
* Update test_camera.cpp
Add test for capture device using PhysConn_Video_SerialDigital as crossbar input pin
* Update test_camera.cpp
Correction of misunderstanding about how to add test case.