Commit d2d6134faa2dc89497a341ffee79ab9e240831a0

Authored by Charles Otto
1 parent bbd30628

Add a transform to draw a properties value at some point

Showing 1 changed file with 39 additions and 0 deletions
openbr/plugins/draw.cpp
@@ -61,6 +61,45 @@ class DrawTransform : public UntrainableTransform @@ -61,6 +61,45 @@ class DrawTransform : public UntrainableTransform
61 61
62 BR_REGISTER(Transform, DrawTransform) 62 BR_REGISTER(Transform, DrawTransform)
63 63
  64 +
  65 +class DrawPropertyPointTransform : public UntrainableTransform
  66 +{
  67 + Q_OBJECT
  68 + Q_PROPERTY(QString propName READ get_propName WRITE set_propName RESET reset_propName STORED false)
  69 + Q_PROPERTY(QString pointName READ get_pointName WRITE set_pointName RESET reset_pointName STORED false)
  70 + BR_PROPERTY(QString, propName, "")
  71 + BR_PROPERTY(QString, pointName, "")
  72 +
  73 +
  74 + void project(const Template &src, Template &dst) const
  75 + {
  76 + dst = src;
  77 + if (propName.isEmpty() || pointName.isEmpty())
  78 + return;
  79 +
  80 + const Scalar textColor(255, 255, 0);
  81 +
  82 + QVariant prop = dst.file.value(propName);
  83 +
  84 +
  85 + if (!prop.canConvert(QVariant::String))
  86 + return;
  87 + QString propString = prop.toString();
  88 +
  89 + QVariant point = dst.file.value(pointName);
  90 +
  91 + if (!point.canConvert(QVariant::PointF))
  92 + return;
  93 +
  94 + QPointF targetPoint = point.toPointF();
  95 +
  96 + Point2f cvPoint =OpenCVUtils::toPoint(targetPoint);
  97 + putText(dst, propString.toStdString(), cvPoint, FONT_HERSHEY_SIMPLEX, 0.5, textColor, 1);
  98 + }
  99 +
  100 +};
  101 +BR_REGISTER(Transform, DrawPropertyPointTransform)
  102 +
64 /*! 103 /*!
65 * \ingroup transforms 104 * \ingroup transforms
66 * \brief Draws a grid on the image 105 * \brief Draws a grid on the image