pangolin 绘制文字
void Visualizer::textToPoints(std::string text) { // string text = "box"; // int fontFace = FONT_HERSHEY_SCRIPT_SIMPLEX; //手写风格字体 int fontFace = 0; double fontScale = 1; // 字体缩放比 int thickness = 1; int baseline = 0; cv::Size textSize = cv::getTextSize(text, fontFace, fontScale, thickness, &baseline); baseline += thickness; cv::Mat img(textSize.height + 5, 100, CV_8UC1, cv::Scalar::all(0)); // pos the text cv::Point textOrg(0, textSize.height); cv::line(img, textOrg + cv::Point(0, thickness), textOrg + cv::Point(textSize.width, thickness), cv::Scalar(0, 0, 255)); cv::putText(img, text, textOrg, fontFace, fontScale, cv::Scalar::all(255), thickness, 8); std::vector<Point3DType> txtPoints; for (int i = 0, iend = img.rows; i < iend; i++) { for (int j = 0, jend = img.cols; j < jend; j++) { if ((int)img.at<uchar>(i, j) == 255) { Point3DType point(i, j, 0); txtPoints.push_back(point); } } } glPointSize(5.0f); glColor3f(0, 0, 1); glBegin(GL_POINTS); for (const auto& point : txtPoints) { glVertex3f(point.GetX(), point.GetY(), point.GetZ()); } glEnd(); }
显示效果: