Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@definitelyuncertain
Copy link
Contributor

@definitelyuncertain definitelyuncertain commented Sep 27, 2023

Related PR for extra: opencv/opencv_extra#1104

Hi,

This patch provides CPU and OpenCL implementations of color conversions from RGB/BGR to YUV422 family (such as UYVY and YUY2).

These features would come in useful for enabling standard RGB images to be supplied as input to algorithms or networks that make use of images in YUV422 format directly (for example, on resource constrained devices working with camera images captured in YUV422).

The code, tests and perf tests are all written following the existing pattern. There is also an example bin/example_cpp_cvtColor_RGB2YUV422 that loads an image from disk, converts it from BGR to UYVY and then back to BGR, and displays the result as a visual check that the conversion works.

The OpenCL performance for the forward conversion implemented here is the same as the existing backward conversion on my hardware. The CPU implementation, unfortunately, isn't very optimized as I am not yet familiar with the SIMD code.

Please let me know if I need to fix something or can make other modifications.

Thanks!

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
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Win64 OpenCL

@definitelyuncertain
Copy link
Contributor Author

@opencv-alalek : Thanks for taking a look!

I've changed the sample filename to lowercase, and have removed the OpenCL parts from the sample code.

I'll be happy to work on a separate sample code in the tapi folder that does the same thing with OpenCL if it'll be helpful.

Do let me know if you have more comments!

@definitelyuncertain
Copy link
Contributor Author

definitelyuncertain commented Sep 29, 2023

It looks like I misunderstood what test data means for performance tests.

I've sent in a PR to opencv/extra with the updated sanity check data.

With this updated data, the perf tests are able to run successfully on my machine using the command from the presently unsuccessful CI run.

Edit: I also realized that I'd missed having the same name for my branch on opencv_extra. I've renamed the branch, and linked a new pull request here.

Would it be possible to retry the CI build with the updated sanity check data?

@opencv-alalek
Copy link
Contributor

Please take a look on issues from OpenCL build configuration: https://pullrequest.opencv.org/buildbot/builders/precommit_opencl/builds/100210

@definitelyuncertain
Copy link
Contributor Author

@opencv-alalek Found the problem, it was a wrong step length that never executed on my machine due to the rows per OpenCL work item being set to 1, but did so on the build server.

@definitelyuncertain
Copy link
Contributor Author

@asmorkalov @opencv-alalek I took a look at the errors from the recent run.

I've pushed a fix for the warning about the double incrementing that appeared in the MacOS builds.

For Ubuntu 22.04 and Android, it just says

Error: tar: command not found

during the initial setup. Not sure what that is, but let me know if there's anything I can do about it.

@asmorkalov
Copy link
Contributor

We have troubles with one of CI servers. Please ignore the issue right now. OpenCV team works on it.

@asmorkalov asmorkalov added this to the 4.9.0 milestone Oct 4, 2023
@asmorkalov
Copy link
Contributor

I extended sample locally. Attached image is 30*absdiff(original, reconstructed):
yuv_sample

@definitelyuncertain
Copy link
Contributor Author

@asmorkalov @opencv-alalek Thanks for reviewing!

I cleaned up the code and made the sample code display the scaled diff as you did.

I've also mentioned my source for the coefficients where they appear and adjusted them to more rigorously derived values.

As for the results, I'm getting a visually similar scaled diff as above with the new coefficients as well:
image

IIUC, conversion from RGB to YUV422 isn't an invertible transformation on account of using 1 byte less per pixel, so some difference is unavoidable to begin with. Added to that, the values are clipped to 0-255 with finite precision, which is likely causing further losses.

Perhaps it'll work better with float images, but I'm not sure if anything can be done at all about integer images.

Let me know if you have any suggestions or other comments.

@definitelyuncertain
Copy link
Contributor Author

It looks like the imgproc tests are passing everywhere. Both the failures in Win64 and Win64 OpenCL seem to be in different modules: one is in test_umat_optical_flow from test_python2-ippicv-opencl and the other in test_videoio with

[ERROR:[email protected]] global cap_ffmpeg_impl.hpp:1286 open VIDEOIO/FFMPEG: Failed to initialize VideoCapture

Both of these seem to be unrelated, but let me know if I can check anything in the PR.

@definitelyuncertain
Copy link
Contributor Author

@asmorkalov

FYI, I updated the perf sanity data due to the change in coefficients for good measure, even though it was passing with the previous data.

@definitelyuncertain
Copy link
Contributor Author

@asmorkalov Just checking in to see if you're waiting on anything to get done. The builds are all passing so I'm assuming it's good to go.

@asmorkalov asmorkalov merged commit a1028ef into opencv:4.x Oct 12, 2023
@asmorkalov asmorkalov mentioned this pull request Oct 17, 2023
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Implement color conversion from RGB to YUV422 family opencv#24333

Related PR for extra: opencv/opencv_extra#1104

Hi,

This patch provides CPU and OpenCL implementations of color conversions from RGB/BGR to YUV422 family (such as UYVY and YUY2).

These features would come in useful for enabling standard RGB images to be supplied as input to algorithms or networks that make use of images in YUV422 format directly (for example, on resource constrained devices working with camera images captured in YUV422).

The code, tests and perf tests are all written following the existing pattern. There is also an example `bin/example_cpp_cvtColor_RGB2YUV422` that loads an image from disk, converts it from BGR to UYVY and then back to BGR, and displays the result as a visual check that the conversion works.

The OpenCL performance for the forward conversion implemented here is the same as the existing backward conversion on my hardware. The CPU implementation, unfortunately, isn't very optimized as I am not yet familiar with the SIMD code.

Please let me know if I need to fix something or can make other modifications.

Thanks!

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
- [x] The feature is well documented and sample code can be built with the project CMake
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Implement color conversion from RGB to YUV422 family opencv#24333

Related PR for extra: opencv/opencv_extra#1104

Hi,

This patch provides CPU and OpenCL implementations of color conversions from RGB/BGR to YUV422 family (such as UYVY and YUY2).

These features would come in useful for enabling standard RGB images to be supplied as input to algorithms or networks that make use of images in YUV422 format directly (for example, on resource constrained devices working with camera images captured in YUV422).

The code, tests and perf tests are all written following the existing pattern. There is also an example `bin/example_cpp_cvtColor_RGB2YUV422` that loads an image from disk, converts it from BGR to UYVY and then back to BGR, and displays the result as a visual check that the conversion works.

The OpenCL performance for the forward conversion implemented here is the same as the existing backward conversion on my hardware. The CPU implementation, unfortunately, isn't very optimized as I am not yet familiar with the SIMD code.

Please let me know if I need to fix something or can make other modifications.

Thanks!

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] 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
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
- [x] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants