Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 5369

Camera board • Re: Extracting Chroma Data From Luminance Mat Object

$
0
0
So here's the good news

1) I took a step back and just focused on separating the luminance and the chroma/color data into three separate cv::Mat objects

The original luminance data window that I showed in my first post DIDN'T multiply the cfg.size.height * 3/2 as I originally posted, hence why the expected UV data at the bottom wasn't being displayed

So I made those changes, recompiled everything and saw the UV data the bottom of the luminanceData window, but the UV data was 'cut' into four separate squares which I didn't think was a big deal since if I didn't multiply cfg.size.height * 3/2 and done my pointer math correctly, I should be able to separate the YUV data into their perspective cv::Mat objects

Code:

cv::Mat luminanceData = cv::Mat(cfg.size.height * 3 / 2, cfg.size.width, CV_8U, ptr, cfg.stride);cv::Mat uData = cv::Mat(cfg.size.height / 2, cfg.size.width / 2, CV_8U, ptr + cfg.size.width * cfg.size.height);cv::Mat vData = cv::Mat(cfg.size.height / 2, cfg.size.width / 2, CV_8U, ptr + cfg.size.width * cfg.size.height + cfg.size.width / 2 * cfg.size.height / 2);cv::namedWindow("luminanceData", cv::WINDOW_AUTOSIZE);cv::imshow("luminanceData", luminanceData);cv::moveWindow("luminanceData", 100, 100);cv::namedWindow("uData", cv::WINDOW_AUTOSIZE);cv::imshow("uData", uData);cv::moveWindow("uData", 1600, 600);cv::namedWindow("vData", cv::WINDOW_AUTOSIZE);cv::imshow("vData", vData);cv::moveWindow("vData", 1600, 100);
Screenshot 2024-08-08 134231.jpg
2) I ran the python script and got the expected RGB frames as I was expecting and shooting for with using libcamera
Screenshot 2024-08-08 105325.jpeg

Here's the bad news.....

Kinda....

1) If I kept the luminanceData Mat object the way it is and apply the cv::cvtColor(luminanceData, rgb, cv::COLOR_YUV420p2RGB); everything seems still super washed out in comparison to the results I saw with the python script.

I'm under the heavy assumption that it's due to all the luminance data still being in the cv::Mat() object, hence everything seeming washed out
Screenshot 2024-08-08 131418.jpg

Moving forward; that's IF I'm heading in the right direction....

Since I have the YUV separated into their perspective cv::Mat objects() I'm now looking on how to encode the color either using Rec 709,601 or whatever else is out there.

If the pointer math I did was correct and I separated the YUV 'channels' correctly, is the correct path moving forward is to look into how to encode the color data in accordance to Rec 703,601 or whatever else is out there?

For what it's worth, I'll leave my Github repository here for those interested in looking further into he code : https://github.com/Digital1O1/simple-cam_libcamera

Statistics: Posted by Digital1O1 — Thu Aug 08, 2024 7:05 pm



Viewing all articles
Browse latest Browse all 5369

Trending Articles