Skip to content

Add V4L2_PIX_FMT_Y16_BE pixel format#18498

Merged
asmorkalov merged 7 commits intoopencv:4.xfrom
firebladed:patch-1
Jul 14, 2023
Merged

Add V4L2_PIX_FMT_Y16_BE pixel format#18498
asmorkalov merged 7 commits intoopencv:4.xfrom
firebladed:patch-1

Conversation

@firebladed
Copy link
Copy Markdown
Contributor

@firebladed firebladed commented Oct 2, 2020

Add V4L2_PIX_FMT_Y16_BE pixel format
#18495

swaps byte order then treats as V4L2_PIX_FMT_Y16
relates to #23944

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 other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to 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.
  • The feature is well documented and sample code can be built with the project CMake
  • Test using Melexis MLX90640

Add V4L2_PIX_FMT_Y16_BE pixel format

swaps byte order then treats as V4L2_PIX_FMT_Y16
change local variable "frame" to "temp2"
Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contribution!

Please make builds green.

};
temp2.ForEach(<uint16_t>(Operator());

temp2.convertTo(temp, CV_8U, 1.0 / 256);
Copy link
Copy Markdown
Member

@alalek alalek Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

temp2.ForEach

Extraction through cv::split() from CV_8UC2 should perform better.

@asmorkalov
Copy link
Copy Markdown
Contributor

@firebladed Do you have chance to finish the PR? Also it'll be great if you add list of know cameras that are enabled by the patch to the PR description. It becomes merge commit message and is very useful for git history.

@firebladed
Copy link
Copy Markdown
Contributor Author

@asmorkalov sorry, had issue an get it to work and been busy with other things recently, will try to look at again a soon as i can.

@asmorkalov
Copy link
Copy Markdown
Contributor

@firebladed Do you have chance to finish the patch? There are changes in GStreamer support that introduces conflicts.

@firebladed firebladed closed this Mar 4, 2021
@firebladed firebladed deleted the patch-1 branch March 4, 2021 13:36
@firebladed firebladed restored the patch-1 branch March 4, 2021 13:38
@firebladed firebladed reopened this Mar 4, 2021
@firebladed
Copy link
Copy Markdown
Contributor Author

I have a version that appears to work however i need to do some more tests and i don't know why the OpenCV CN Windows 10 x64 build failed

@alalek
Copy link
Copy Markdown
Member

alalek commented Mar 6, 2021

OpenCV CN

Ignore, there builders are optional for now.

@firebladed
Copy link
Copy Markdown
Contributor Author

Ive tested visually using the MLX90640 on ubuntu on a raspberypi and it appears to give the same output as
ffmpeg -f rawvideo -pixel_format y16be -video_size "32x26" -i /dev/video0 -vf scale=288:234 -f fbdev -pix_fmt bgra /dev/fb0

there appears to be some delay between running python script and getting an image which i cant currently account for

Id like to test using a stream that doesn't use the camera but so far i haven't found anything that can produce a raw y16be stream, ffmpeg doesn't appear to convert to y16be, that i can send to the videoloopback

For anyone wanting to use the MLX90640 ive also discovered that this method of obtaining video is of limited use, as the MLX90640 image correction requires data embedded in the video stream and implicit scaling to 8bit corrupts this data.

have to set fourcc and disable rgb conversion before doing image correction and then convert to desired format

vs.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc('Y','1','6',' '))
vs.set(cv2.CAP_PROP_CONVERT_RGB, 0)

@firebladed firebladed marked this pull request as ready for review March 26, 2021 13:12
@asenyaev
Copy link
Copy Markdown
Contributor

asenyaev commented Apr 8, 2021

jenkins cn please retry a build

@asmorkalov
Copy link
Copy Markdown
Contributor

Thanks for the patch! OpenCV runs on Big-Endian platforms too (like PPC), so the patch with bytes swap does not work there. please add endianess check.

@firebladed
Copy link
Copy Markdown
Contributor Author

Thanks for the patch! OpenCV runs on Big-Endian platforms too (like PPC), so the patch with bytes swap does not work there. please add endianess check.

sorry for slow reply

im not sure exactly what you mean, im also not familiar with PPC

unless im missing something

V4L2_PIX_FMT_Y16 and V4L2_PIX_FMT_Y16_BE

are the same except that the MSB and LSB are swapped for each pixel

so to convert between them i just swap the MSB and LSB, processor endianess is irrelevent

what should i be checking for endianess?

does

       cv::split(temp,channels);
        cv::addWeighted(channels[0],256,channels[1],1,0,temp2,CV_16UC1);

not work on big endian platforms?

are you saying that i need to use this on big endian platforms?

       cv::split(temp,channels);
        cv::addWeighted(channels[1],256,channels[0],1,0,temp2,CV_16UC1);

@mshabunin
Copy link
Copy Markdown
Contributor

To check current platform you can copy this function to cap_v4l.cpp:

CV_INLINE bool isBigEndian( void )
{
return (((const int*)"\0\x1\x2\x3\x4\x5\x6\x7")[0] & 255) != 0;
}

On BE platform we don't need to swap bytes of V4L2_PIX_FMT_Y16_BE image, while V4L2_PIX_FMT_Y16 image should be transformed. So, perhaps your code should be extracted to a function and applied to either of the formats depending on the platform.

@opencv-alalek
Copy link
Copy Markdown
Contributor

According to documentation:

Implementation has been updated for using cv::extractChannel() call (no need to perform LE/BE checks for arithmetic operations)

@mshabunin
Copy link
Copy Markdown
Contributor

Maybe we should also add a new test case to the videoio_v4l2.formats with Y16_BE type?

@mshabunin
Copy link
Copy Markdown
Contributor

I've added this case to the test, it passes for me.

@asmorkalov asmorkalov requested a review from opencv-alalek July 14, 2023 07:08
Copy link
Copy Markdown
Contributor

@asmorkalov asmorkalov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍
Tested manually with Ubuntu 18.04 + vivid driver

@asmorkalov asmorkalov added this to the 4.9.0 milestone Jul 14, 2023
@asmorkalov asmorkalov self-assigned this Jul 14, 2023
@asmorkalov asmorkalov merged commit 7819ec7 into opencv:4.x Jul 14, 2023
std::string res = fourccToString(fourcc);
std::replace_if(res.begin(), res.end(), [](uint8_t c){ return c < '0' || c > 'z'; }, '_');
// TODO: return hex values for invalid characters
std::transform(res.begin(), res.end(), res.begin(), [](uint8_t c) { return (c >= '0' && c <= 'z') ? c : (c == ' ' ? '_' : 'x'); });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related CI issue: opencv/ci-gha-workflow#108

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created PR #24087

@asmorkalov asmorkalov mentioned this pull request Jul 27, 2023
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
Add V4L2_PIX_FMT_Y16_BE pixel format opencv#18498

Address opencv#18495
relates to opencv#23944

### 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 other license that is incompatible with OpenCV
- [ ] The PR is proposed to proper branch
- [x] There is reference to 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
- [ ] Test using Melexis MLX90640
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
Add V4L2_PIX_FMT_Y16_BE pixel format opencv#18498

Address opencv#18495
relates to opencv#23944

### 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 other license that is incompatible with OpenCV
- [ ] The PR is proposed to proper branch
- [x] There is reference to 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.
- [ ] The feature is well documented and sample code can be built with the project CMake
- [ ] Test using Melexis MLX90640
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.

6 participants