手動で画像を反復処理し、適切な場所に値をコピーするか、またはあなたがそうのような1でチャンネルを1つずつコピーするcv::extractChannel
のようなものを使用することができますすることができ、次のいずれかのcv ::スプリットを使用して
#include <opencv2/opencv.hpp>
int main()
{
//create dummy 3 channel float image
cv::Mat sourceRGB(cv::Size(100,100),CV_32FC3);
auto size = sourceRGB.size();
for (int y = 0; y < size.height; ++y)
{
for (int x = 0; x < size.width; ++x)
{
float* pxl = sourceRGB.ptr<float>(x, y);
*pxl = x/100.0f;
*(pxl+1) = y/100.0f;
*(pxl + 2) = (y/100.0f) * (x/100.0f);
}
}
cv::imshow("test", sourceRGB);
cv::waitKey(0);
//create single image with all 3 channels one after the other
cv::Size newsize(size.width,size.height*3);
cv::Mat destination(newsize,CV_32FC1);
//copy the channels from the source image to the destination
for (int i = 0; i < sourceRGB.channels(); ++i)
{
cv::extractChannel(
sourceRGB,
cv::Mat(
size.height,
size.width,
CV_32FC1,
&(destination.at<float>(size.height*size.width*i))),
i);
}
cv::imshow("test", destination);
cv::waitKey(0);
return 0;
}
と単一チャネルを単一のメモリ空間にコピーすると機能するはずですか?しかし、おそらくもっと簡単な方法があります – Micka