int main(int argc, char** argv) { int nrows = 6; if (argc >= 2) sscanf(argv[1], "%d", &nrows); int ncols = 6; if (argc >= 3) sscanf(argv[2], "%d", &ncols); Cmatrix Md = Cmatrix::Random(nrows, ncols); MatrixXv Mv(Md); MatrixXl Ml(Md); MatrixXh Mh(Md); cout << Md.str(Dense()) << endl; cout << Mv.str(Dense()) << endl; cout << Ml.str(Dense()) << endl; cout << Mh.str(Dense()) << endl; cout << Mh.nnz() << endl; }
/** * Computes the parameters of an ellipse from contours */ bool Circular::getEllipseParameters(void){ // Transform from pixel coordinate to image frame coordinate int numel = this->contours_.size(); cv::Mat M(3, numel, CV_64F, 1.0); double ax = - this->cx_ / this->fx_ ; double ay = - this->cy_ / this->fy_ ; for (int j=0; j<numel; j++){ M.at<double>(0, j) = this->contours_.at(j).x / this->fx_ + ax ; M.at<double>(1, j) = this->contours_.at(j).y / this->fy_ + ay ; } // Find center of the oblique circular cone; this->xc_c_(0) = sum(M.row(0))[0]/numel; this->xc_c_(1) = sum(M.row(1))[0]/numel; this->xc_c_(2) = 1; // Computing ellipse parameters double alpha = -atan2(xc_c_(1), -xc_c_(2)); double beta = -atan2(xc_c_(0), -xc_c_(1)*sin(alpha)-xc_c_(2)*cos(alpha) ); cv::Mat R = (cv::Mat_<double>(3,3) << cos(beta), 0, -sin(beta),0, 1, 0, sin(beta), 0, cos(beta) ) * (cv::Mat_<double>(3,3) << 1, 0, 0, 0, cos(alpha), -sin(alpha), 0, sin(alpha), cos(alpha) ); cv::Mat Mh(R*M); std::vector<cv::Point2f> contours; for (int j=0; j<Mh.cols; j++){ contours.push_back(cv::Point2f( Mh.at<double>(0, j) / Mh.at<double>(2, j), Mh.at<double>(1, j) / Mh.at<double>(2, j) ) ); } this->ellipse_ = cv::fitEllipse(contours); return true; }