Commit f4b5c89c4197f2342e3182cc290b6d37a005f855
1 parent
54dfb088
Revert "remove check"
This reverts commit ab48a22f2a89b46a24e8e4999ba45f70deef9f36.
Showing
3 changed files
with
173 additions
and
0 deletions
openbr/plugins/metadata/check.cpp
0 โ 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
| 2 | + * Copyright 2012 The MITRE Corporation * | ||
| 3 | + * * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * | ||
| 5 | + * you may not use this file except in compliance with the License. * | ||
| 6 | + * You may obtain a copy of the License at * | ||
| 7 | + * * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * | ||
| 9 | + * * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software * | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
| 13 | + * See the License for the specific language governing permissions and * | ||
| 14 | + * limitations under the License. * | ||
| 15 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
| 16 | + | ||
| 17 | +#include <openbr/plugins/openbr_internal.h> | ||
| 18 | + | ||
| 19 | +using namespace cv; | ||
| 20 | + | ||
| 21 | +namespace br | ||
| 22 | +{ | ||
| 23 | + | ||
| 24 | +/*! | ||
| 25 | + * \ingroup transforms | ||
| 26 | + * \brief Checks the Template for NaN values. | ||
| 27 | + * \author Josh Klontz \cite jklontz | ||
| 28 | + */ | ||
| 29 | +class CheckTransform : public UntrainableMetaTransform | ||
| 30 | +{ | ||
| 31 | + Q_OBJECT | ||
| 32 | + static int count; | ||
| 33 | + int index; | ||
| 34 | + | ||
| 35 | + public: | ||
| 36 | + CheckTransform() : index(count++) {} | ||
| 37 | + | ||
| 38 | + void project(const Template &src, Template &dst) const | ||
| 39 | + { | ||
| 40 | + dst = src; | ||
| 41 | + foreach (const Mat &m, src) { | ||
| 42 | + Mat fm; | ||
| 43 | + m.convertTo(fm, CV_32F); | ||
| 44 | + const int elements = fm.rows * fm.cols * fm.channels(); | ||
| 45 | + const float *data = (const float*)fm.data; | ||
| 46 | + for (int i=0; i<elements; i++) | ||
| 47 | + if (data[i] != data[i]) | ||
| 48 | + qFatal("%s NaN check %d failed!", qPrintable(src.file.flat()), index); | ||
| 49 | + } | ||
| 50 | + } | ||
| 51 | +}; | ||
| 52 | + | ||
| 53 | +int CheckTransform::count = 0; | ||
| 54 | + | ||
| 55 | +BR_REGISTER(Transform, CheckTransform) | ||
| 56 | + | ||
| 57 | +} // namespace br | ||
| 58 | + | ||
| 59 | +#include "metadata/check.moc" |
openbr/plugins/metadata/checkpoints.cpp
0 โ 100644
| 1 | +#include <openbr/plugins/openbr_internal.h> | ||
| 2 | + | ||
| 3 | +namespace br | ||
| 4 | +{ | ||
| 5 | + | ||
| 6 | +/*! | ||
| 7 | + * \ingroup transforms | ||
| 8 | + * \brief Checks the points in a template for missing (-1,-1) values | ||
| 9 | + * \author Scott Klum \cite sklum | ||
| 10 | + * \br_property QList<int> indices Indices of points to check. | ||
| 11 | + */ | ||
| 12 | +class CheckPointsTransform : public UntrainableMetadataTransform | ||
| 13 | +{ | ||
| 14 | + Q_OBJECT | ||
| 15 | + | ||
| 16 | + Q_PROPERTY(QList<int> indices READ get_indices WRITE set_indices RESET reset_indices STORED false) | ||
| 17 | + Q_PROPERTY(int count READ get_count WRITE set_count RESET reset_count STORED false) | ||
| 18 | + BR_PROPERTY(QList<int>, indices, QList<int>()) | ||
| 19 | + BR_PROPERTY(int, count, 0) | ||
| 20 | + | ||
| 21 | + void projectMetadata(const File &src, File &dst) const | ||
| 22 | + { | ||
| 23 | + dst = src; | ||
| 24 | + | ||
| 25 | + const QList<QPointF> points = src.points(); | ||
| 26 | + if (count && points.size() < count) | ||
| 27 | + dst.fte = true; | ||
| 28 | + | ||
| 29 | + for (int i=0; i<indices.size(); i++) | ||
| 30 | + if (src.points()[indices[i]] == QPointF(-1,-1)) { | ||
| 31 | + dst.fte = true; | ||
| 32 | + break; | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | +}; | ||
| 36 | + | ||
| 37 | +BR_REGISTER(Transform, CheckPointsTransform) | ||
| 38 | + | ||
| 39 | +} // namespace br | ||
| 40 | + | ||
| 41 | +#include "metadata/checkpoints.moc" |
openbr/plugins/metadata/checkrects.cpp
0 โ 100644
| 1 | +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
| 2 | + * Copyright 2015 Rank One Computing Corporation * | ||
| 3 | + * * | ||
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); * | ||
| 5 | + * you may not use this file except in compliance with the License. * | ||
| 6 | + * You may obtain a copy of the License at * | ||
| 7 | + * * | ||
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 * | ||
| 9 | + * * | ||
| 10 | + * Unless required by applicable law or agreed to in writing, software * | ||
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, * | ||
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * | ||
| 13 | + * See the License for the specific language governing permissions and * | ||
| 14 | + * limitations under the License. * | ||
| 15 | + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | ||
| 16 | + | ||
| 17 | +#include <openbr/plugins/openbr_internal.h> | ||
| 18 | + | ||
| 19 | +namespace br | ||
| 20 | +{ | ||
| 21 | + | ||
| 22 | +/*! | ||
| 23 | + * \ingroup transforms | ||
| 24 | + * \brief Checks the rects in a template for invalid values. The user can specify to fix the rects or remove them. | ||
| 25 | + * \author Keyur Patel \cite kpatel | ||
| 26 | + */ | ||
| 27 | + | ||
| 28 | +class CheckRectsTransform : public UntrainableTransform | ||
| 29 | +{ | ||
| 30 | + Q_OBJECT | ||
| 31 | + Q_PROPERTY(bool fixRects READ get_fixRects WRITE set_fixRects RESET reset_fixRects STORED false) | ||
| 32 | + Q_PROPERTY(bool removeBadRect READ get_removeBadRect WRITE set_removeBadRect RESET reset_removeBadRect STORED false) | ||
| 33 | + BR_PROPERTY(bool, fixRects, false) | ||
| 34 | + BR_PROPERTY(bool, removeBadRect, true) | ||
| 35 | + | ||
| 36 | + void project(const Template &src, Template &dst) const | ||
| 37 | + { | ||
| 38 | + dst = src; | ||
| 39 | + dst.file.clearRects(); | ||
| 40 | + QList<QRectF> rects = src.file.rects(); | ||
| 41 | + | ||
| 42 | + if (fixRects) { | ||
| 43 | + foreach (QRectF r, rects) | ||
| 44 | + if ((r.height() <= src.m().rows) && (r.width() <= src.m().cols)) /* can't fix rects that don't fit the image */ { | ||
| 45 | + if (r.left() < 0) r.moveLeft(0); | ||
| 46 | + if (r.right() > src.m().cols-1) r.moveRight(src.m().cols-1); | ||
| 47 | + if (r.top() < 0) r.moveTop(0); | ||
| 48 | + if (r.bottom() > src.m().rows-1) r.moveBottom(src.m().rows-1); | ||
| 49 | + dst.file.appendRect(r); | ||
| 50 | + } | ||
| 51 | + } else { | ||
| 52 | + foreach (QRectF r, rects){ | ||
| 53 | + if ((r.left() < 0) || (r.right() > src.m().cols-1) || (r.top() < 0) || (r.bottom() > src.m().rows-1)){ | ||
| 54 | + if (removeBadRect){ | ||
| 55 | + rects.removeOne(r); | ||
| 56 | + } | ||
| 57 | + else { | ||
| 58 | + dst.file.fte = true; | ||
| 59 | + break; | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + dst.file.setRects(rects); | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | +}; | ||
| 67 | + | ||
| 68 | +BR_REGISTER(Transform, CheckRectsTransform) | ||
| 69 | + | ||
| 70 | +} // namespace br | ||
| 71 | + | ||
| 72 | +#include "metadata/checkrects.moc" | ||
| 73 | + |