/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * Copyright 2012 The MITRE Corporation * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include #include #include "core/opencvutils.h" using namespace cv; using namespace br; /*! * \ingroup transforms * \brief Renders metadata onto the image * \author Josh Klontz \cite jklontz */ class Draw : public UntrainableTransform { Q_OBJECT Q_PROPERTY(bool verbose READ get_verbose WRITE set_verbose RESET reset_verbose STORED false) BR_PROPERTY(bool, verbose, false) void project(const Template &src, Template &dst) const { const Scalar color(0,255,0); const Scalar verboseColor(255, 255, 0); dst = src.m().clone(); QList landmarks = OpenCVUtils::toPoints(src.file.landmarks()); foreach (const Point2f &landmark, landmarks) circle(dst, landmark, 3, color, -1); QList ROIs = OpenCVUtils::toRects(src.file.ROIs()); foreach (const Rect ROI, ROIs) rectangle(dst, ROI, color); if (verbose) for (int i=0; isetProperty("parallelism", "0"); // Can only work in single threaded mode } void project(const Template &src, Template &dst) const { dst = src; if (Globals->parallelism) { qWarning("Edit::project() only works in single threaded mode."); return; } currentTemplateLock.lock(); currentTemplate = src; OpenCVUtils::showImage(src, "Edit", false); setMouseCallback("Edit", mouseCallback, (void*)this); mouseEvent(0, 0, 0, 0); waitKey(-1); dst = currentTemplate; currentTemplateLock.unlock(); } static void mouseCallback(int event, int x, int y, int flags, void *userdata) { ((const Edit*)userdata)->mouseEvent(event, x, y, flags); } void mouseEvent(int event, int x, int y, int flags) const { (void) event; if (flags) { QList ROIs = currentTemplate.file.ROIs(); for (int i=ROIs.size()-1; i>=0; i--) if (ROIs[i].contains(x,y)) ROIs.removeAt(i); currentTemplate.file.setROIs(ROIs); } Template temp; draw->project(currentTemplate, temp); OpenCVUtils::showImage(temp, "Edit", false); } }; Template Edit::currentTemplate; QMutex Edit::currentTemplateLock; BR_REGISTER(Transform, Edit) #include "draw.moc"