Ask Your Question

Revision history [back]

How to specify EM.trainE's covs0 param in Java

I'm having trouble calling EM.trainE() from Java. The parameter is defined to be of class Mat, but the documentation says to pass in a vector of Mat's, one for each component. I'm trying to use Converters.vector_Mat_to_Mat() but I can't get it to work.

My training data consists of a 50000x2 matrix (each row is an x,y coordinate) with 4 components. For my covariance matices I made an ArrayList<mat> of 4 2x2 identity matrices, and used vector_Mat_to_Mat() to convert it to a Mat. When I call EM.trainE(), it throws the following exception:

CvException [org.opencv.core.CvException: cv::Exception: ........\opencv\modules\ml\src\em.cpp:202: error: (-215) !m.empty() && m.size() == covSize && (m.channels() == 1) in function cv::checkTrainData

I've confirmed that each identity matrix has size 2x2 and has 1 channel, so I don't know what could be causing this to fail.