I have two questions. First one is why ncluster switch from 10 to 80 after the train function. Second: I am passing my code from C to C++ with OpenCV but it seems there are some problems with it. I am having an exception when I try to get the covs of my model, this is the code:
int nclusters = 10; // Here nclusters is 10
EM em_model(nclusters, EM::COV_MAT_GENERIC);
bool isTrained = em_model.train(samples);
// Here nclusters is 80
Mat means = em_model.get<Mat>("means");
Mat weights = em_model.get<Mat>("weights");
const vector<Mat>& covs = em_model.get<vector<Mat>>("covs"); // Here I have the exception. I have tried with and without &.
After debugging it the error shows after that last line. The system shows a window with myprogram.exe has triggered a breakpoint, and if I click continue I have the Microsoft Visual C++ Debug Library window with file: f:\dd\vctools\crt_bld\self_x86\crt\src\dbgheap.c; Line: 1322; Expression: _CrtIsValidHeapPointer(pUserData).
Almost the same code works for this guy: How to use the CV::EM class in OpenCV 2.4.2?
I already fixed it. I compiled the source libraries of OpenCV 2.4.6 with using VS2012 and it worked. It seems like there is a few bugs in the compiled one.