0

I am currently trying to concatenate cv::Mat objects using cv::hconcat(std::vector<cv::Mat> vector_of_mats, cv::Mat dest). However, I need the destination cv::Mat to be of type CV_32FC1 rather than the default CV_8UC1.

I tried constructing the destination cv::Mat as:

 descriptor = cv::Mat::zeros(tmp.size(), 256, CV_32FC1); cv::hconcat(vec, descriptor); 

But that still produces a CV_8UC1 cv::Mat for descriptor. The type of cv::Mat in the vector is CV_8UC1. Is that where my problem lies?

Thanks in advance!

1 Answer 1

1

Your suspicions are correct! The type of the cv::Mat is taken from the source.

A quick look at the source code of cv::hconcat confirms this:

void cv::hconcat(const Mat* src, size_t nsrc, OutputArray _dst) { .... _dst.create( src[0].rows, totalCols, src[0].type()); // Type taken from src .... } void cv::hconcat(InputArray _src, OutputArray dst) { std::vector<Mat> src; _src.getMatVector(src); hconcat(!src.empty() ? &src[0] : 0, src.size(), dst); } 
Sign up to request clarification or add additional context in comments.

2 Comments

Is it possible to declare a cv::Mat with a type without specifying a size? I looked at the long list of constructors and couldn't find one, but I thought perhaps there may be some way.
@marcman Absolutely, I assume you know the number of columns (256), so you can simply do descriptors = cv::Mat(0, 256, CV_32FC1), and then call descriptors.push_back(vec), assuming vec also has 256 columns. Note: I'm not sure what sort of trouble you could run in to here if they are different types, never tried it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.