Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

untested (bc. we don't know your context), but you probaby can't use dnn::blobFromImages here, but have to do it manually, we're going to use the same trick from here:

Mat img1; // bgr
Mat img2; // also, same size.

int W = img1.cols;
int H = img1.rows;
int sz[] = {1, 6, H, W}; // 1 (batch)img, 6 channels
Mat blob(4, sz, CV_32F); // allocate data

vector<Mat> ch1, ch2; // original image channels

// setup channel pointers:

// 1st image goes into planes [0,1,2]
ch1.push_back(Mat(H,W,1, blop.ptr<float>(0,0));
ch1.push_back(Mat(H,W,1, blop.ptr<float>(0,1));
ch1.push_back(Mat(H,W,1, blop.ptr<float>(0,2));
cv::split(img1, ch1); // this will handle the actual copy into our blob !)

// 2nd image goes into planes [3,4,5]
ch2.push_back(Mat(H,W,1, blop.ptr<float>(0,3));
ch2.push_back(Mat(H,W,1, blop.ptr<float>(0,4));
ch2.push_back(Mat(H,W,1, blop.ptr<float>(0,5));
cv::split(img2, ch2);

you'll have to apply your own scaling / resizing here (and order matters !)

untested (bc. we don't know your context), but you probaby probably can't use dnn::blobFromImages here, but have to do it manually, we're going to use the same trick from here:

Mat img1; // bgr
Mat img2; // also, same size.

int W = img1.cols;
int H = img1.rows;
int sz[] = {1, 6, H, W}; // 1 (batch)img, 6 channels
Mat blob(4, sz, CV_32F); // allocate data

vector<Mat> ch1, ch2; // original image channels

// setup channel pointers:

// 1st image goes into planes [0,1,2]
ch1.push_back(Mat(H,W,1, blop.ptr<float>(0,0));
ch1.push_back(Mat(H,W,1, blop.ptr<float>(0,1));
ch1.push_back(Mat(H,W,1, blop.ptr<float>(0,2));
cv::split(img1, ch1); // this will handle the actual copy into our blob !)

// 2nd image goes into planes [3,4,5]
ch2.push_back(Mat(H,W,1, blop.ptr<float>(0,3));
ch2.push_back(Mat(H,W,1, blop.ptr<float>(0,4));
ch2.push_back(Mat(H,W,1, blop.ptr<float>(0,5));
cv::split(img2, ch2);

you'll have to apply your own scaling / resizing here (and order matters !)

untested (bc. we don't know your context), but you probably can't use dnn::blobFromImages here, but have to do it manually, we're going to use the same trick from here:

Mat img1; // bgr
Mat img2; // also, same size.

int W = img1.cols;
int H = img1.rows;
int sz[] = {1, 6, H, W}; // 1 (batch)img, 6 channels
Mat blob(4, sz, CV_32F); // allocate data

vector<Mat> ch1, ch2; // original image channels

// setup channel pointers:

// 1st image goes into planes [0,1,2]
ch1.push_back(Mat(H,W,1, ch1.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,0));
ch1.push_back(Mat(H,W,1, ch1.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,1));
ch1.push_back(Mat(H,W,1, ch1.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,2));
cv::split(img1, ch1); // this will handle the actual copy into our blob !)

// 2nd image goes into planes [3,4,5]
ch2.push_back(Mat(H,W,1, ch2.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,3));
ch2.push_back(Mat(H,W,1, ch2.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,4));
ch2.push_back(Mat(H,W,1, ch2.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,5));
cv::split(img2, ch2);

you'll have to apply your own scaling / resizing here (and order matters !)

untested (bc. we don't know your context), but you probably can't use dnn::blobFromImages here, but have to do it manually,

we're going to use the same trick from here:

Mat img1; // bgr
Mat img2; // also, same size.

int W = img1.cols;
int H = img1.rows;
int sz[] = {1, 6, H, W}; // 1 (batch)img, 6 channels
Mat blob(4, sz, CV_32F); // allocate data

vector<Mat> ch1, ch2; // original image channels

// setup channel pointers:

// 1st image goes into planes [0,1,2]
ch1.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,0));
ch1.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,1));
ch1.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,2));
cv::split(img1, ch1); // this will handle the actual copy into our blob !)

// 2nd image goes into planes [3,4,5]
ch2.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,3));
ch2.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,4));
ch2.push_back(Mat(H, W, CV_32F, blop.ptr<float>(0,5));
cv::split(img2, ch2);

you'll have to apply your own scaling / resizing here (and order matters !)