Mat sample(sample_num,1,CV_32FC3);
for(int j=0;j<sample_num;++j){
int clusterIdx=labels.at<int>(j);
Mat temp_cov(sample.row(j)-curr[clusterIdx].center);
temp_cov=temp_cov.t()*temp_cov;
temp_cov.convertTo(temp_cov,CV_64FC1);
curr[clusterIdx].cov+=temp_cov;
++curr[clusterIdx].mass;
}
結果就是算出來的covariance非正定,導致馬氏距離出現了負值
更改後的結果:
for(int j=0;j<sample_num;++j){
int clusterIdx=labels.at<int>(j);
Vec3f xxx=sample.at<Vec3f>(j,0);
float ppp[3]={xxx[0],xxx[1],xxx[2]};
Mat cur_pix(1,3,CV_32FC1,ppp);
Mat temp_cov(cur_pix-curr[clusterIdx].center);
// cout<<temp_cov<<endl;
// cout<<cur_pix-curr[clusterIdx].center<<endl;
temp_cov=temp_cov.t()*temp_cov;
curr[clusterIdx].cov+=temp_cov;
++curr[clusterIdx].mass;
}