You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
jason_w
e8f94182f5
Merge pull request #24180 from MambaWong:4.x
Fixed the channels when capturing yuv422 with v4l2 backend #24180
example to reproduce the problem
```cpp
#include <iostream>
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/videoio.hpp>
using namespace cv;
using namespace std;
void help_func(VideoCapture& cap) {
int height = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
int width = cap.get(cv::CAP_PROP_FRAME_WIDTH);
int pixel_type = cap.get(cv::CAP_PROP_FORMAT);
int channels = CV_MAT_CN(pixel_type);
int pixel_bytes = CV_ELEM_SIZE(pixel_type);
bool to_bgr = static_cast<bool>(cap.get(cv::CAP_PROP_CONVERT_RGB));
std::cout << "backend: " << cap.getBackendName() << std::endl;
std::cout << std::hex << "fourcc: " << static_cast<int>(cap.get(cv::CAP_PROP_FOURCC)) << std::endl;
std::cout << std::boolalpha << "to_bgr: " << to_bgr << std::endl;
std::cout << std::dec << "height: " << height << " width: " << width << " channels: " << channels
<< " pixel_bytes: " << pixel_bytes << std::endl;
std::cout << "-----------------------------------------" << std::endl;
}
int main(int, char**) {
VideoCapture cap;
cap.open("/dev/video0");
if (!cap.isOpened()) {
cerr << "ERROR! Unable to open camera\n";
return -1;
}
{
help_func(cap);
}
{
cap.set(cv::CAP_PROP_FRAME_HEIGHT, 1080);
cap.set(cv::CAP_PROP_FRAME_WIDTH, 1920);
cap.set(cv::CAP_PROP_CONVERT_RGB, 0);
help_func(cap);
}
// {
// cap.set(cv::CAP_PROP_CONVERT_RGB, 0);
// cap.set(cv::CAP_PROP_FRAME_HEIGHT, 1080);
// cap.set(cv::CAP_PROP_FRAME_WIDTH, 1920);
// help_func(cap);
// }
Mat frame;
int frame_idx = 0;
while (cap.read(frame)) {
std::cout << "frame index: " << frame_idx++ << std::endl;
help_func(cap);
if (frame.empty()) {
cerr << "ERROR! blank frame grabbed\n";
break;
}
Mat bgr;
if (cap.get(cv::CAP_PROP_CONVERT_RGB)) {
bgr = frame;
} else {
cv::cvtColor(frame, bgr, cv::COLOR_YUV2BGR_YUYV);
}
imshow("frame", bgr);
if (waitKey(5) >= 0) {
break;
}
}
return 0;
}
```
The above code will get the wrong channels. By changing lines 41-45 like below, can get the correct channels.
<img width="747" alt="code" src="https://github.com/opencv/opencv/assets/16932438/55f44463-8465-4dba-a979-e71a50d58008">
This is because `cap.set(cv::CAP_PROP_FRAME_HEIGHT, 1080);` and `cap.set(cv::CAP_PROP_FRAME_WIDTH, 1920);` reinitialize the `frame`, but `cap.set(cv::CAP_PROP_CONVERT_RGB, 0);` not.
Log info.
<img width="691" alt="log" src="https://github.com/opencv/opencv/assets/16932438/236e3b26-f5b2-447a-b202-bcd607c71af6">
We can also observe that we get the correct channels in the while loop. This is because:
ca0bd70cde/modules/videoio/src/cap_v4l.cpp (L2309-L2310)
reinitialize the `frame`.
|
2 years ago |
.github
|
Add Ubuntu 22.04 to CI.
|
2 years ago |
3rdparty
|
imgcodecs: fix libtiff homepage
|
2 years ago |
apps
|
Add missing <sstream> includes
|
2 years ago |
cmake
|
Use STRING instead of PATH to fix #24141
|
2 years ago |
data
|
Merge pull request #22727 from su77ungr:patch-1
|
3 years ago |
doc
|
Merge pull request #24179 from Kumataro:fix24145
|
2 years ago |
include
|
exclude opencv_contrib modules
|
5 years ago |
modules
|
Merge pull request #24180 from MambaWong:4.x
|
2 years ago |
platforms
|
pre: OpenCV 4.8.0 (version++)
|
2 years ago |
samples
|
Merge pull request #24116 from chaebkimm/update-samples-python-tst_scene_render
|
2 years ago |
.editorconfig
|
add .editorconfig
|
7 years ago |
.gitattributes
|
cmake: generate and install ffmpeg-download.ps1
|
7 years ago |
.gitignore
|
Merge pull request #17165 from komakai:objc-binding
|
5 years ago |
CMakeLists.txt
|
Merge pull request #24122 from fengyuentau:remove_tengine
|
2 years ago |
CONTRIBUTING.md
|
migration: github.com/opencv/opencv
|
9 years ago |
COPYRIGHT
|
copyright: 2023 (update)
|
2 years ago |
LICENSE
|
Merge pull request #18073 from vpisarev:apache2_license
|
5 years ago |
README.md
|
fix 4.x links
|
3 years ago |
SECURITY.md
|
Updated PGP key for security reports
|
2 years ago |
OpenCV: Open Source Computer Vision Library
Resources
Contributing
Please read the contribution guidelines before starting work on a pull request.
Summary of the guidelines:
- One pull request per issue;
- Choose the right base branch;
- Include tests and documentation;
- Clean up "oops" commits before submitting;
- Follow the coding style guide.