Gaussian3D build_gaussian(std::string image_names[], int length, double **pixels) // Builds the initial hand and background gaussians from files. { int total_averaged_rgbs = 0; for (int index =0; index<length; index++) { std::string image = image_names[index]; cv::Mat img; img = cv::imread(image); int count = 0; double *sum = new double[3]; sum[0] = 0.0; sum[1] = 0.0; sum[2] = 0.0; for (int i=0; i<img.rows; i++) { for (int j=0; j<img.cols; j++) { cv::Vec3b bgrPixel = img.at<cv::Vec3b>(i,j); sum[0] += (double)bgrPixel[0]/255; sum[1] += (double)bgrPixel[1]/255; sum[2] += (double)bgrPixel[2]/255; count++; } } sum[0] = sum[0] / count; sum[1] = sum[1] / count; sum[2] = sum[2] / count; pixels[index] = sum; total_averaged_rgbs++; } Gaussian3D result = Gaussian3D(pixels, total_averaged_rgbs); return result; }
Gaussian3D get_gaussian_from_covariance(const IMP_Eigen::Matrix3d &covar, const Vector3D ¢er) { Rotation3D rot; Vector3D radii; // get eigen decomposition and sort by eigen vector IMP_Eigen::EigenSolver<IMP_Eigen::Matrix3d> es(covar); IMP_Eigen::Matrix3d evecs = es.eigenvectors().real(); IMP_Eigen::Vector3d evals = es.eigenvalues().real(); // fill in sorted stuff for (int i = 0; i < 3; i++) { radii[i] = evals[i]; } // reflect if necessary double det = evecs.determinant(); // std::cout<<"Determinant is "<<det<<std::endl; if (det < 0) { IMP_Eigen::Matrix3d reflect = IMP_Eigen::Vector3d(1, 1, -1).asDiagonal(); evecs = evecs * reflect; } // create rotation matrix and return IMP_Eigen::Quaterniond eq(evecs); rot = Rotation3D(eq.w(), eq.x(), eq.y(), eq.z()); return Gaussian3D(ReferenceFrame3D(Transformation3D(rot, center)), radii); }