In OpenCV what is CvMatND structure used for? - opencv

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

Related

Header and pointer of the Mat object in Open CV?

What does the Header and pointer term means in Mat, please elaborate me on each one through some example.
After some googling I found answer to your question in this article:
Mat is basically a class having two data parts: the matrix header
(containing information such as the size of the matrix, the method
used for storing, at which address is the matrix stored and so on) and
a pointer to the matrix containing the pixel values (may take any
dimensionality depending on the method chosen for storing) .

How to display an image represented by three matrices in OpenCV

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);

How does opencv store matrix value in Gaussian mixture? In which order?

I've searched the "bgfg_gaussmix2.cpp" code, it says in gaussian mixture model, it stores mixture weight (w), mean ( nchannels values ) and covariance for each gaussian mixture of each pixel background model. I want to know the order of its storage, for instance, is it "weight, mean, covariance", or " mean, covariance, weight", or something else?
Thanks in advance.
If you are speeking about the gaussian mixture structure CvPBGMMGaussian, the storing order is
Weight
mean dimension 1
mean dimension 2
mean dimension 3
Variance
The three dimensions are packed in a float array.
Here is the definition of this structure :
#define CV_BGFG_MOG2_NDMAX 3
typedef struct CvPBGMMGaussian
{
float weight;
float mean[CV_BGFG_MOG2_NDMAX];
float variance;
}CvPBGMMGaussian
If you are not speeking about this structure, please be more precise in your question.

How to normalize OpenCV feature descriptors to an integer scale?

OpenCV SURF implementation returns a sequence of 64/128 32 bit float values (descriptor) for each feature point found in the image. Is there a way to normalize this float values and take them to an integer scale (for example, [0, 255])?. That would save important space (1 or 2 bytes per value, instead of 4). Besides, the conversion should ensure that the descriptors remain meaningful for other uses, such as clustering.
Thanks!
There are other feature extractors than SURF. The BRIEF extractor uses only 32 bytes per descriptor. It uses 32 unsigned bytes [0-255] as its elements. You can create one like this: Ptr ptrExtractor = DescriptorExtractor::create("BRIEF");
Be aware that a lot of image processing routines in OpenCV need or assume that the data is stored as floating-point numbers.
You can treat the float features as an ordinary image (Mat or cvmat) and then use cv::normalize(). Another option is using cv::norm() to find the range of descriptor values and then cv::convertTo() to convert to CV_8U. Look up the OpenCV documentation for these functions.
The descriptor returned by cv::SurfFeatureDetector is already normalized. You can verify this by taking the L2 Norm of the cv::Mat returned, or refer to the paper.

OpenCV CalcPca input data

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

Resources