I have 3 matrices (R G B) in double precision format, so all I need is OpenCV version of matlab cat function to display image. If you have any sources or references please post, I would be grateful.
There is merge() for such tasks. I'm assuming that you're using C++ for the following example code, but this function is available for C and Python too (see docs).
// Suppose you have 3 matrices (instances of class cv::Mat)
// named channelR, channelG and channelB that hold your data
std::vector<cv::Mat> channels;
channels.push_back(channelR);
channels.push_back(channelG);
channels.push_back(channelB);
cv::Mat outputImage;
merge(channels, outputImage);
Related
I am using OpenCV and also want to add some of cool functions from mlpack, which is using Armadillo matrices.
Is there an easy way to convet between cv::Mat and arms::mat?
Thanks!
OpenCV's Mat has a pointer to its data. Armadillo has a constructor that is capable of reading from external data. It's easy to put them together. Remember that Armadillo stores in column-major order, whereas OpenCV uses row-major. I suppose you'll need to add another step for transformation, before or after.
cv::Mat opencv_mat; //opencv's mat, already transposed.
arma::mat arma_mat( reinterpret_cast<double*>opencv_mat.data, opencv_mat.rows, opencv_mat.cols )
The cv::Mat constructor has a form that accepts pointer to data, and arma::mat has a function for a double* pointer to its data called memptr().
So, if you'd like to convert from arma::mat to cv::Mat, this should work:
cv::Mat opencv_mat( rows, cols, CV_64FC1, arma_mat.memptr() )
i am working in opencv c++ api with matrices
I have 4 single channel Mat that i will like to merge into one 4 channel matrix. It is basically the rgba channels i have in 4 matrices and want to combine into one rgba image/matrix. Anyone who knows how to do that?
You can use cv::merge to do what you want. One possible usage:
cv::Mat r,g,b,a;
//Fill r,g,b,a with data
cv::Mat result;
std::vector<cv::Mat> channels;
channels.push_back(r);
channels.push_back(g);
channels.push_back(b);
channels.push_back(a);
cv::merge(channels, result);
I want to compare two images (number plate images). I already separated each character from number plate using ROI command. Now, I want to compare this with the stored templates or characters to recognize the character. I want to know how to compare their similarity.I am new to openCV. I am using the standard number plates.
Opencv implements the template matching function. Here is the prototype:
void matchTemplate(const Mat& image, const Mat& templ, Mat& result, int method);
Methods of comparison are mostly based on sum of squared differences with differents normalization terms.
In case of colored images each sum in the denominator is done over all of the channels (and separate mean values are used for each channel).
Use the OpenCV function minMaxLoc to find the maximum and minimum values.
try cvMatchTemplate
void cvMatchTemplate(const CvArr* image, const CvArr* templ, CvArr* result, int method);
http://opencv.willowgarage.com/documentation/c/object_detection.html
I am trying to implement a face recognition training function with opencv, using "eigenfaces". I have the sample data, but I can't find any info on CalcPCA function arguments. All I know is that it takes data matrix, reference to average eigenface matrix, reference to eigen vector, and reference to eigen values matrix.
My question is, how should I pass the data from several test image matrices into the first argument of CalcPCA so I can get the average eigenface and vectors?
This seems to be a good example: http://tech.groups.yahoo.com/group/OpenCV/message/47627
You can do in this way:
You have for example 10 Mat where each math represent an image.
Now you can create a new Mat that you can put into this new Mat the previus 10 Mat.
At this point use Mat.pushback(...) to insert the 10 Mat.
Hope this is helpful for you.
Marco
I've noticed in the O'rielly book that when using histograms it refers to a cvMatND data structure. However, the book does not explain what this data structure is used for and how its different then cvMat. Can someone please explain this to me? Thank you.
cvMat is two-dimensional (multi-channel) array, i.e., a matrix.
cvMatND is an n-dimensional (multi-channel) array.
See the Basic Structures section in the CXCORE reference manual.
Update:
A histogram can be computed in arbitrary dimensions, therefore the definition of
the CvHistogram structure uses CvMatND to store multidimensional histograms to
a dense multidimensional array structure.
typedef struct CvHistogram
{
int type;
CvArr* bins;
float thresh[CV_MAX_DIM][2]; // for uniform histograms
float** thresh2; // for nonuniform histograms
CvMatND mat; // embedded matrix header
// for array histograms
}
CvHistogram;
Maybe this helps: http://opencv.willowgarage.com/documentation/python/basic_structures.html