Presently Iam working in finding disparity of stereo pair. I have got a situation in creating 20 channel data set, When I declare array of 3 dimension it was giving error, Instead can I create image of 20 channels so that I can store data. If I can what are the additional conditions I have to include to get results without any error of memory allocation or sort of .... Creating an Image of 20 channels will be even comfortable for me...
The C++ interface of OpenCV presents cv::Mat
, which replaces and improves the IplImage
type of the C interface. This new type provides several constructors, including the one below which can be used to specify the desired number of channels through the param type
:
Mat::Mat(int rows, int cols, int type)
Sample code:
#include <cv.h>
#include <highgui.h>
#include <iostream>
void test_mat(cv::Mat mat)
{
std::cout << "Channels: " << mat.channels() << std::endl;
}
int main(int argc, char* argv[])
{
cv::Mat mat20(1024, 768, CV_8UC(20));
test_mat(mat20);
return 0;
}
Opencv implements template class for small matrices whose type and size are known at compilation time:
template<typename _Tp, int m, int n> class Matx {...};
You can create a specified template of a partial case of Matx, which is cv::Vec like those already written in opencv for 1,2, or 3 "channels" like that:
typedef Vec<uchar, 3> Vec3b; // 3 channel -- written in opencv
typedef Vec<uchar, 20> Vec20b; // the one you need
And then, declare a Matrix of your new (20 channel of uchar) object:
cv::Mat_<Vec20b> myMat;
myMat.at<Vec20b>(i,j)(10) = .. // access to the 10 channel of pixel (i,j)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With