Repository navigation
V4L (V4L2): Refactoring. Added missed camera properties. Fixed getting INF for some properties. Singlethread as always - #12893
Conversation
INF for some properties
INF for some propertiesINF for some properties. Thread-safe
INF for some properties. Thread-safeINF for some properties. Singlethread as always
|
Unfortunately, I need this on 3.4. The main problem is a backward compatibility: [0,1] ranges for parameters. I could revert the ranges conversion and add the capture mode or a build option for using real parameters instead of converted. Would that be an acceptable compromise? |
8930bcd to
8303a27
Compare
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 migrated to use VideoCaptureProperties.
| // any other value greater than 32768 revert backward compatibility mode. | ||
| // Backward compatibility mode affects the following parameters: | ||
| // cv::CAP_PROP_*: BRIGHTNESS,CONTRAST,SATURATION,HUE,GAIN,EXPOSURE,FOCUS,AUTOFOCUS,AUTO_EXPOSURE. | ||
| bool compatibilityMode; |
There was a problem hiding this comment.
Comment is outdated.
CAP_PROP_MODE is already used, so behavior should not be changed.
Alternative variant via environment variables:
compatibilityMode = !utils::getConfigurationParameterBool("OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED", false);
There was a problem hiding this comment.
CAP_PROP_MODE was used for get - not for set
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.
| deviceName = _deviceName; | ||
| returnFrame = true; | ||
| compatibilityMode = utils::getConfigurationParameterBool("OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED", true); | ||
| compatibilityMode = !utils::getConfigurationParameterBool("OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED", false); |
There was a problem hiding this comment.
this was correct before:
compatibilityMode <=> "converted to/from [0,1) range" <=> OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED <=> 1
maybe either rename either compatibilityMode or OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED to match each other.
There was a problem hiding this comment.
Thanks!
Renamed to normalizePropRange.
There was a problem hiding this comment.
My bad, need to fix this again.
Done
|
|
||
| buffer() : start(NULL), length(0) | ||
| { | ||
| memset(&v4l2_buf, 0, sizeof(v4l2_buf)); |
There was a problem hiding this comment.
v4l2_buf = v4l2_buffer() this initialization style is used in this cpp file. Please, don't mix it.
There was a problem hiding this comment.
If you care about variable names, I could bring everything in this file to a single style, including renaming ambiguous entities
There was a problem hiding this comment.
Renamed type instead.
Using v4l2_buffer() initializer.
`v4l2-ctl --list-formats` should have 'MJPG' entry
to avoid "munmap: Invalid argument" messages
|
@paroj @aleksey-nikolaev I believe it should be fine now. Any comments? |
|
code style maybe. And what about the comments at the top of the file, they're no longer relevant, are they? |
|
I think this broke builds on kernels < 3.5 (at least that, maybe an even higher version is required). See #13335 |
The format of destination is BGR24. However, when it was NV[12|21], it was set to RGB24. Fixes: Commit 8396ae6 ("Merge pull request opencv#12893 from aleksey-nikolaev:cap-update")
The format of destination is BGR24. However, when it was NV[12|21], it was set to RGB24. Fixes: Commit 8396ae6 ("Merge pull request opencv#12893 from aleksey-nikolaev:cap-update")
| return; | ||
| case V4L2_PIX_FMT_NV12: | ||
| cv::cvtColor(cv::Mat(imageSize.height * 3 / 2, imageSize.width, CV_8U, currentBuffer.start), destination, | ||
| COLOR_YUV2RGB_NV12); |
There was a problem hiding this comment.
V4L (V4L2): Refactoring. Added missed camera properties. Fixed getting `INF` for some properties. Singlethread as always (opencv#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
I made this changes because when I tried to get the exposure property I got the
INF. Also, all values for my cam on windows are not same on linux.This pullrequest changes
OPENCV_VIDEOIO_V4L_RANGE_NORMALIZED.cv::CAP_PROP_MODE = 1(enable normalized properties).cv::CAP_PROP_MODE = 0.V4L2_CID_*tocv::CAP_PROP_*-1- the channels not changed.memcopyfor grab image.RGBfrom formats:NV12,NV21,Y8Some code refactoring:
autosetup_capture_mode_v4l2RGB, Set/Get of properties, frame capture initialization.{}.cvtColorI tried to keep the code format unchanged. It will be nice to have
.clang-formaton the OpenCV project.