Quantcast
Channel: OpenCV Q&A Forum - Latest question feed
Viewing all articles
Browse latest Browse all 19555

How to merge multi RGB channel to a new Mat

$
0
0
I am trying to grab a frame from my camera which provides raw image in Bayer 8bit format, I am converting it to RGB 8bit channel using cvtColor and make red, green, blue Mat using CV_8UC3 as splitting Bayer 8 bit gives me grayscale image, which I don't require. I then loop through every pixel and add RGB info to provide it to unity3d texture2d RGB24. Here is the code: Bayer2RGB(byte* rawImage, byte encodedImage[]) { cv::Mat bayer8BitMat(3288, 4608, CV_8UC1, rawImage); cv::Mat rgb8BitMat(3288, 4608, CV_8UC3); cv::cvtColor(bayer8BitMat, rgb8BitMat, CV_BayerGR2RGB); cv::Mat red = cv::Mat::zeros(rgb8BitMat.rows, rgb8BitMat.cols, CV_8UC3 ); cv::Mat green = cv::Mat::zeros(rgb8BitMat.rows, rgb8BitMat.cols, CV_8UC3 ); cv::Mat blue = cv::Mat::zeros(rgb8BitMat.rows, rgb8BitMat.cols, CV_8UC3 ); cv::Mat channels[] = { red, green, blue }; int from_to[] = {0,2, 1,4, 2,6 }; cv::mixChannels( &rgb8BitMat, 1, channels, 3, from_to, 3); int i,j; uchar* p0; uchar* p1; uchar* p2; std::vector v; for( i = 0; i < rgb8BitMat.rows; ++i) { p0 = channels[2].ptr(i); p1 = channels[1].ptr(i); p2 = channels[0].ptr(i); for ( j = 0; j < rgb8BitMat.cols; ++j) { v.push_back(p0[j]); v.push_back(p1[j]); v.push_back(p2[j]); } } std::copy(v.begin(), v.end(), encodedImage); } As you can see I am making encodedImage to resolution*3, this is what TextureFormat.RGB24 of unity3d expects. But the image I am getting in unity has separate RGB channels (Please view attached 2nd image), do I need any interpolation ? or am I mistaking somewhere in conversions ? [C:\fakepath\1.png](/upfiles/14615654393654609.png) [C:\fakepath\2.png](/upfiles/14615654697975422.png)

Viewing all articles
Browse latest Browse all 19555

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>