-
Notifications
You must be signed in to change notification settings - Fork 640
Add support for NV12 encoding in cv_bridge #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: rolling
Are you sure you want to change the base?
Conversation
- Update getCvType to return CV_8UC1 for NV12 encoding. - Extend Encoding enum to include NV12. - Enhance getEncoding to recognize NV12. - Add conversion codes for NV12 to GRAY, RGB, BGR, RGBA, and BGRA. - Modify conversion logic to handle NV12 as a color format. - Adjust matFromImage to account for height scaling in NV12 images. Signed-off-by: Zhaoyuan Cheng <[email protected]>
- Corrected the error message to include height scaling in the size calculation. - Adjusted the formatting for better readability. Signed-off-by: Zhaoyuan Cheng <[email protected]>
|
@ahcorde could you please have a review for this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for the NV12 image encoding to the cv_bridge package, enabling conversion and proper handling of NV12-formatted data.
- Extended
getCvTypeandgetEncodingto recognize NV12. - Added NV12 conversion codes for GRAY, RGB, BGR, RGBA, and BGRA.
- Updated
matFromImageto apply height scaling for NV12’s planar layout.
Comments suppressed due to low confidence (2)
cv_bridge/src/cv_bridge.cpp:299
- NV12-specific logic was introduced here (height scaling check) and in conversion paths; please add unit tests that cover NV12
matFromImagebehavior andcvtColorconversions to ensure correctness.
if (source.height * source.step * enc::getHeightScaling(source.encoding) != source.data.size()) {
cv_bridge/src/cv_bridge.cpp:102
- [nitpick] Consider adding a comment explaining why NV12 is mapped to
CV_8UC1(i.e., single-channel Mat with interleaved Y and UV planes) to help future maintainers understand this choice.
if (encoding == enc::NV12) {return CV_8UC1;}
| ss << "Image is wrongly formed: height * step * HeightScaling != size or " << source.height << " * " << | ||
| source.step << "*" << enc::getHeightScaling(source.encoding) << " != " << source.data.size(); |
Copilot
AI
Jun 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the error message, HeightScaling is capitalized and concatenated; consider using a user-friendly phrase like "height scaling" (lowercase, with space) for clarity and consistency.
| ss << "Image is wrongly formed: height * step * HeightScaling != size or " << source.height << " * " << | |
| source.step << "*" << enc::getHeightScaling(source.encoding) << " != " << source.data.size(); | |
| ss << "Image is wrongly formed: height * step * height scaling != size or " << source.height << " * " << | |
| source.step << " * " << enc::getHeightScaling(source.encoding) << " != " << source.data.size(); |
|
Thanks for the PR, and sorry for the delay in reviewing. Could you please update |
Description
This PR adds support for the NV12 encoding in the
cv_bridgepackage. Change depends on common_interfaces PR: ros2/common_interfaces#264The following changes have been made:
getCvTypeandgetEncodingfunctions to handle NV12 encoding.matFromImageto correctly handle height scaling for NV12 encoding.Changes
Encoding Support:
NV12to theEncodingenum.getCvTypeandgetEncodingfunctions to recognizeNV12.Conversion Codes:
NV12toGRAY,RGB,BGR,RGBA, andBGRAingetConversionCodes.Height Scaling:
matFromImageto account for height scaling when the encoding isNV12.