Commit 2ac9c2d5d064c9aababd94a2097e60ee88e3e4b3
Fixed conflicts
Showing
5 changed files
with
177 additions
and
7 deletions
openbr/openbr_plugin.h
| ... | ... | @@ -1206,7 +1206,7 @@ public: |
| 1206 | 1206 | static QSharedPointer<Distance> fromAlgorithm(const QString &algorithm); /*!< \brief Retrieve an algorithm's distance. */ |
| 1207 | 1207 | virtual void train(const TemplateList &src) { (void) src; } /*!< \brief Train the distance. */ |
| 1208 | 1208 | virtual void compare(const TemplateList &target, const TemplateList &query, Output *output) const; /*!< \brief Compare two template lists. */ |
| 1209 | - QList<float> compare(const TemplateList &targets, const Template &query) const; /*!< \brief Compute the normalized distance between a template and a template list. */ | |
| 1209 | + virtual QList<float> compare(const TemplateList &targets, const Template &query) const; /*!< \brief Compute the normalized distance between a template and a template list. */ | |
| 1210 | 1210 | virtual float compare(const Template &a, const Template &b) const = 0; /*!< \brief Compute the distance between two templates. */ |
| 1211 | 1211 | |
| 1212 | 1212 | protected: | ... | ... |
openbr/plugins/draw.cpp
| ... | ... | @@ -25,7 +25,10 @@ namespace br |
| 25 | 25 | |
| 26 | 26 | /*! |
| 27 | 27 | * \ingroup transforms |
| 28 | - * \brief Renders metadata onto the image | |
| 28 | + * \brief Renders metadata onto the image. | |
| 29 | + * | |
| 30 | + * The inPlace argument controls whether or not the image is cloned before the metadata is drawn. | |
| 31 | + * | |
| 29 | 32 | * \author Josh Klontz \cite jklontz |
| 30 | 33 | */ |
| 31 | 34 | class DrawTransform : public UntrainableTransform |
| ... | ... | @@ -34,15 +37,17 @@ class DrawTransform : public UntrainableTransform |
| 34 | 37 | Q_PROPERTY(bool verbose READ get_verbose WRITE set_verbose RESET reset_verbose STORED false) |
| 35 | 38 | Q_PROPERTY(bool points READ get_points WRITE set_points RESET reset_points STORED false) |
| 36 | 39 | Q_PROPERTY(bool rects READ get_rects WRITE set_rects RESET reset_rects STORED false) |
| 40 | + Q_PROPERTY(bool inPlace READ get_inPlace WRITE set_inPlace RESET reset_inPlace STORED false) | |
| 37 | 41 | BR_PROPERTY(bool, verbose, false) |
| 38 | 42 | BR_PROPERTY(bool, points, true) |
| 39 | 43 | BR_PROPERTY(bool, rects, true) |
| 44 | + BR_PROPERTY(bool, inPlace, false) | |
| 40 | 45 | |
| 41 | 46 | void project(const Template &src, Template &dst) const |
| 42 | 47 | { |
| 43 | 48 | const Scalar color(0,255,0); |
| 44 | - const Scalar verboseColor(0, 0, 0); | |
| 45 | - dst = src.m().clone(); | |
| 49 | + const Scalar verboseColor(255, 255, 0); | |
| 50 | + dst.m() = inPlace ? src.m() : src.m().clone(); | |
| 46 | 51 | |
| 47 | 52 | if (points) { |
| 48 | 53 | const QList<Point2f> pointsList = OpenCVUtils::toPoints(src.file.namedPoints() + src.file.points()); |
| ... | ... | @@ -62,13 +67,23 @@ class DrawTransform : public UntrainableTransform |
| 62 | 67 | BR_REGISTER(Transform, DrawTransform) |
| 63 | 68 | |
| 64 | 69 | |
| 70 | +/*! | |
| 71 | + * \ingroup transforms | |
| 72 | + * \brief Draw the value of the specified property at the specified point on the image | |
| 73 | + * | |
| 74 | + * The inPlace argument controls whether or not the image is cloned before it is drawn on. | |
| 75 | + * | |
| 76 | + * \author Charles Otto \cite caotto | |
| 77 | + */ | |
| 65 | 78 | class DrawPropertyPointTransform : public UntrainableTransform |
| 66 | 79 | { |
| 67 | 80 | Q_OBJECT |
| 68 | 81 | Q_PROPERTY(QString propName READ get_propName WRITE set_propName RESET reset_propName STORED false) |
| 69 | 82 | Q_PROPERTY(QString pointName READ get_pointName WRITE set_pointName RESET reset_pointName STORED false) |
| 83 | + Q_PROPERTY(bool inPlace READ get_inPlace WRITE set_inPlace RESET reset_inPlace STORED false) | |
| 70 | 84 | BR_PROPERTY(QString, propName, "") |
| 71 | 85 | BR_PROPERTY(QString, pointName, "") |
| 86 | + BR_PROPERTY(bool, inPlace, false) | |
| 72 | 87 | |
| 73 | 88 | |
| 74 | 89 | void project(const Template &src, Template &dst) const |
| ... | ... | @@ -77,6 +92,8 @@ class DrawPropertyPointTransform : public UntrainableTransform |
| 77 | 92 | if (propName.isEmpty() || pointName.isEmpty()) |
| 78 | 93 | return; |
| 79 | 94 | |
| 95 | + dst.m() = inPlace ? src.m() : src.m().clone(); | |
| 96 | + | |
| 80 | 97 | const Scalar textColor(255, 255, 0); |
| 81 | 98 | |
| 82 | 99 | QVariant prop = dst.file.value(propName); |
| ... | ... | @@ -94,7 +111,9 @@ class DrawPropertyPointTransform : public UntrainableTransform |
| 94 | 111 | QPointF targetPoint = point.toPointF(); |
| 95 | 112 | |
| 96 | 113 | Point2f cvPoint =OpenCVUtils::toPoint(targetPoint); |
| 97 | - putText(dst, propString.toStdString(), cvPoint, FONT_HERSHEY_SIMPLEX, 0.5, textColor, 1); | |
| 114 | + | |
| 115 | + std::string text = propName.toStdString() + ": " + propString.toStdString(); | |
| 116 | + putText(dst, text, cvPoint, FONT_HERSHEY_SIMPLEX, 0.5, textColor, 1); | |
| 98 | 117 | } |
| 99 | 118 | |
| 100 | 119 | }; |
| ... | ... | @@ -102,6 +121,65 @@ BR_REGISTER(Transform, DrawPropertyPointTransform) |
| 102 | 121 | |
| 103 | 122 | /*! |
| 104 | 123 | * \ingroup transforms |
| 124 | + * \brief Draw the values of a list of properties at the specified point on the image | |
| 125 | + * | |
| 126 | + * The inPlace argument controls whether or not the image is cloned before it is drawn on. | |
| 127 | + * | |
| 128 | + * \author Charles Otto \cite caotto | |
| 129 | + */ | |
| 130 | +class DrawPropertiesPointTransform : public UntrainableTransform | |
| 131 | +{ | |
| 132 | + Q_OBJECT | |
| 133 | + Q_PROPERTY(QStringList propNames READ get_propNames WRITE set_propNames RESET reset_propNames STORED false) | |
| 134 | + Q_PROPERTY(QString pointName READ get_pointName WRITE set_pointName RESET reset_pointName STORED false) | |
| 135 | + Q_PROPERTY(bool inPlace READ get_inPlace WRITE set_inPlace RESET reset_inPlace STORED false) | |
| 136 | + BR_PROPERTY(QStringList, propNames, QStringList()) | |
| 137 | + BR_PROPERTY(QString, pointName, "") | |
| 138 | + BR_PROPERTY(bool, inPlace, false) | |
| 139 | + | |
| 140 | + void project(const Template &src, Template &dst) const | |
| 141 | + { | |
| 142 | + dst = src; | |
| 143 | + if (propNames.isEmpty() || pointName.isEmpty()) | |
| 144 | + return; | |
| 145 | + | |
| 146 | + dst.m() = inPlace ? src.m() : src.m().clone(); | |
| 147 | + | |
| 148 | + QVariant point = dst.file.value(pointName); | |
| 149 | + | |
| 150 | + if (!point.canConvert(QVariant::PointF)) | |
| 151 | + return; | |
| 152 | + | |
| 153 | + QPointF targetPoint = point.toPointF(); | |
| 154 | + | |
| 155 | + Point2f cvPoint =OpenCVUtils::toPoint(targetPoint); | |
| 156 | + | |
| 157 | + | |
| 158 | + const Scalar textColor(255, 255, 0); | |
| 159 | + | |
| 160 | + std::string outString = ""; | |
| 161 | + foreach (const QString & propName, propNames) | |
| 162 | + { | |
| 163 | + QVariant prop = dst.file.value(propName); | |
| 164 | + | |
| 165 | + if (!prop.canConvert(QVariant::String)) | |
| 166 | + continue; | |
| 167 | + QString propString = prop.toString(); | |
| 168 | + outString += propName.toStdString() + ": " + propString.toStdString() + " "; | |
| 169 | + | |
| 170 | + } | |
| 171 | + if (outString.empty()) | |
| 172 | + return; | |
| 173 | + | |
| 174 | + putText(dst, outString, cvPoint, FONT_HERSHEY_SIMPLEX, 0.5, textColor, 1); | |
| 175 | + } | |
| 176 | + | |
| 177 | +}; | |
| 178 | +BR_REGISTER(Transform, DrawPropertiesPointTransform) | |
| 179 | + | |
| 180 | + | |
| 181 | +/*! | |
| 182 | + * \ingroup transforms | |
| 105 | 183 | * \brief Draws a grid on the image |
| 106 | 184 | * \author Josh Klontz \cite jklontz |
| 107 | 185 | */ | ... | ... |
openbr/plugins/independent.cpp
| ... | ... | @@ -73,7 +73,7 @@ static TemplateList Downsample(const TemplateList &templates, const Transform *t |
| 73 | 73 | class IndependentTransform : public MetaTransform |
| 74 | 74 | { |
| 75 | 75 | Q_OBJECT |
| 76 | - Q_PROPERTY(br::Transform* transform READ get_transform WRITE set_transform STORED false) | |
| 76 | + Q_PROPERTY(br::Transform* transform READ get_transform WRITE set_transform RESET reset_transform STORED false) | |
| 77 | 77 | BR_PROPERTY(br::Transform*, transform, NULL) |
| 78 | 78 | |
| 79 | 79 | QList<Transform*> transforms; | ... | ... |
openbr/plugins/misc.cpp
| ... | ... | @@ -469,6 +469,98 @@ class RemoveMetadataTransform : public UntrainableMetaTransform |
| 469 | 469 | |
| 470 | 470 | BR_REGISTER(Transform, RemoveMetadataTransform) |
| 471 | 471 | |
| 472 | +/*! | |
| 473 | + * \ingroup transforms | |
| 474 | + * \brief Store the last matrix of the input template as a metadata key with input property name. | |
| 475 | + * \author Charles Otto \cite caotto | |
| 476 | + */ | |
| 477 | +class SaveMatTransform : public UntrainableMetaTransform | |
| 478 | +{ | |
| 479 | + Q_OBJECT | |
| 480 | + | |
| 481 | + Q_PROPERTY(QString propName READ get_propName WRITE set_propName RESET reset_propName STORED false) | |
| 482 | + BR_PROPERTY(QString, propName, "") | |
| 483 | + | |
| 484 | + void project(const Template &src, Template &dst) const | |
| 485 | + { | |
| 486 | + dst = src; | |
| 487 | + dst.file.set(propName, QVariant::fromValue(dst.m())); | |
| 488 | + } | |
| 489 | +}; | |
| 490 | +BR_REGISTER(Transform, SaveMatTransform) | |
| 491 | + | |
| 492 | +/*! | |
| 493 | + * \ingroup transforms | |
| 494 | + * \brief Set the last matrix of the input template to a matrix stored as metadata with input propName. | |
| 495 | + * | |
| 496 | + * Also removes the property from the templates metadata after restoring it. | |
| 497 | + * | |
| 498 | + * \author Charles Otto \cite caotto | |
| 499 | + */ | |
| 500 | +class RestoreMatTransform : public UntrainableMetaTransform | |
| 501 | +{ | |
| 502 | + Q_OBJECT | |
| 503 | + Q_PROPERTY(QString propName READ get_propName WRITE set_propName RESET reset_propName STORED false) | |
| 504 | + BR_PROPERTY(QString, propName, "") | |
| 505 | + | |
| 506 | + void project(const Template &src, Template &dst) const | |
| 507 | + { | |
| 508 | + dst = src; | |
| 509 | + if (dst.file.contains(propName)) { | |
| 510 | + dst.clear(); | |
| 511 | + dst.m() = dst.file.get<cv::Mat>(propName); | |
| 512 | + dst.file.remove(propName); | |
| 513 | + } | |
| 514 | + } | |
| 515 | +}; | |
| 516 | +BR_REGISTER(Transform, RestoreMatTransform) | |
| 517 | + | |
| 518 | +/*! | |
| 519 | + * \ingroup transforms | |
| 520 | + * \brief Expand the width and height of a template's rects by input width and height factors. | |
| 521 | + * \author Charles Otto \cite caotto | |
| 522 | + */ | |
| 523 | +class ExpandRectTransform : public UntrainableTransform | |
| 524 | +{ | |
| 525 | + Q_OBJECT | |
| 526 | + Q_PROPERTY(float widthExpand READ get_widthExpand WRITE set_widthExpand RESET reset_widthExpand STORED false) | |
| 527 | + Q_PROPERTY(float heightExpand READ get_heightExpand WRITE set_heightExpand RESET reset_heightExpand STORED false) | |
| 528 | + BR_PROPERTY(float, widthExpand, .5) | |
| 529 | + BR_PROPERTY(float, heightExpand, .5) | |
| 530 | + void project(const Template &src, Template &dst) const | |
| 531 | + { | |
| 532 | + dst = src; | |
| 533 | + QList<QRectF> rects = dst.file.rects(); | |
| 534 | + for (int i=0;i < rects.size(); i++) { | |
| 535 | + QRectF rect = rects[i]; | |
| 536 | + | |
| 537 | + qreal width = rect.width(); | |
| 538 | + qreal height = rect.height(); | |
| 539 | + float half_w_expansion = widthExpand / 2; | |
| 540 | + float half_h_expansion = heightExpand / 2; | |
| 541 | + | |
| 542 | + qreal half_width = width * widthExpand; | |
| 543 | + qreal quarter_width = width * half_w_expansion; | |
| 544 | + qreal half_height = height * heightExpand; | |
| 545 | + qreal quarter_height = height * half_h_expansion; | |
| 546 | + | |
| 547 | + rect.setX(std::max(qreal(0),(rect.x() - quarter_width))); | |
| 548 | + rect.setY(std::max(qreal(0),(rect.y() - quarter_height))); | |
| 549 | + | |
| 550 | + qreal x2 = std::min(rect.width() + half_width + rect.x(), qreal(src.m().cols) - 1); | |
| 551 | + qreal y2 = std::min(rect.height() + half_height + rect.y(), qreal(src.m().rows) - 1); | |
| 552 | + | |
| 553 | + rect.setWidth(x2 - rect.x()); | |
| 554 | + rect.setHeight(y2 - rect.y()); | |
| 555 | + | |
| 556 | + rects[i] = rect; | |
| 557 | + } | |
| 558 | + dst.file.setRects(rects); | |
| 559 | + } | |
| 560 | +}; | |
| 561 | + | |
| 562 | +BR_REGISTER(Transform, ExpandRectTransform) | |
| 563 | + | |
| 472 | 564 | } |
| 473 | 565 | |
| 474 | 566 | #include "misc.moc" | ... | ... |
openbr/plugins/pp5.cpp
| ... | ... | @@ -213,7 +213,7 @@ struct PP5Context |
| 213 | 213 | * \author Josh Klontz \cite jklontz |
| 214 | 214 | * \author E. Taborsky \cite mmtaborsky |
| 215 | 215 | */ |
| 216 | -class PP5EnrollTransform : public UntrainableTransform | |
| 216 | +class PP5EnrollTransform : public UntrainableMetaTransform | |
| 217 | 217 | { |
| 218 | 218 | Q_OBJECT |
| 219 | 219 | Q_PROPERTY(bool detectOnly READ get_detectOnly WRITE set_detectOnly RESET reset_detectOnly STORED false) | ... | ... |