This question is partially answered at how to convert an opencv cv::Mat to qimage
I use Qt 5.5, and opencv 2.4, mac yosemite 10.10.5.
I'm looking for an efficient way to display a color image with a QImage, whose color information come from 3 distinct cv::Mat objects which contain the 3 RGB channels of a color image. For my own "education" I need to understand how to originally work with the channels separated. It is unclear to me what will be the most efficient way to end up with the QImage from these 3 separated channels.
The cv::Mat objects are declared and assigned as follows:
imRed = new Mat(Size(naxis1, naxis2), CV_64F);
imGreen = new Mat(Size(naxis1, naxis2), CV_64F);
imBlue = new Mat(Size(naxis1, naxis2), CV_64F);
double* redP = imRed->ptr<double>(0);
double* greenP = imGreen->ptr<double>(0);
double* blueP = imBlue->ptr<double>(0);
for (long i = 0; i < nPixels; i++)
{
redP[i] = (double) rawProcess.imgdata.image[i][0];;
greenP[i] = (double) rawProcess.imgdata.image[i][1];
blueP[i] = (double) rawProcess.imgdata.image[i][2];
}
where rawProcess
is an object from the Libraw library which contains the image data. redP
, greenP
, blueP
are, as their name indicate, the pointer to the red, green and blue channel, and this code assumes (correct me if i'm wrong) that the cv::Mat
addresses of the pixel values are continuous in memory.
From here, how shall I efficiently pass the buffer of the color image to QImage, i.e, minimizing intermediate copy, loops etc... (if necessary, my system can use openMP, I have 4 threads available)?
Thanks