summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStéphane Lenclud <github@lenclud.com>2019-04-15 12:22:05 +0200
committerStéphane Lenclud <github@lenclud.com>2019-04-24 18:46:12 +0200
commit6ca96478ea4d8e6ba71ebf41a1f7d904f2c3df5d (patch)
tree85810bc2463bb5786817830cab89cd19c9241325
parent9830011866f0817d08c3e3f0bd26e98e54c523e7 (diff)
Easy Tracker: Removing point extractor interface. Using cv::Point instead of vec2.
-rw-r--r--tracker-easy/module.cpp4
-rw-r--r--tracker-easy/point-extractor.cpp14
-rw-r--r--tracker-easy/point-extractor.h13
-rw-r--r--tracker-easy/preview.cpp13
-rw-r--r--tracker-easy/preview.h4
-rw-r--r--tracker-easy/tracker-easy-api.h37
-rw-r--r--tracker-easy/tracker-easy-dialog.h3
-rw-r--r--tracker-easy/tracker-easy.cpp20
-rw-r--r--tracker-easy/tracker-easy.h8
9 files changed, 35 insertions, 81 deletions
diff --git a/tracker-easy/module.cpp b/tracker-easy/module.cpp
index b7b60fa8..9f5461d5 100644
--- a/tracker-easy/module.cpp
+++ b/tracker-easy/module.cpp
@@ -1,13 +1,9 @@
#include "tracker-easy.h"
#include "tracker-easy-dialog.h"
-#include "tracker-easy-api.h"
#include "module.hpp"
-#include "point-extractor.h"
#include <memory>
-
-
namespace EasyTracker
{
diff --git a/tracker-easy/point-extractor.cpp b/tracker-easy/point-extractor.cpp
index abaa0739..c1f525c9 100644
--- a/tracker-easy/point-extractor.cpp
+++ b/tracker-easy/point-extractor.cpp
@@ -31,7 +31,7 @@ namespace EasyTracker
}
- void PointExtractor::extract_points(const cv::Mat& aFrame, cv::Mat* aPreview, std::vector<vec2>& aPoints)
+ void PointExtractor::ExtractPoints(const cv::Mat& aFrame, cv::Mat* aPreview, std::vector<cv::Point>& aPoints)
{
//TODO: Assert if channel size is neither one nor two
// Make sure our frame channel is 8 bit
@@ -99,10 +99,10 @@ namespace EasyTracker
&& bBox.width <= s.max_point_size
&& bBox.height <= s.max_point_size)
{
- vec2 center;
- center[0] = bBox.x + bBox.width / 2;
- center[1] = bBox.y + bBox.height / 2;
- aPoints.push_back(vec2(center));
+ cv::Point center;
+ center.x = bBox.x + bBox.width / 2;
+ center.y = bBox.y + bBox.height / 2;
+ aPoints.push_back(center);
if (aPreview)
{
@@ -124,9 +124,9 @@ namespace EasyTracker
// Search for the point with highest Y coordinate
for (size_t i = 0; i < aPoints.size(); i++)
{
- if (aPoints[i][1] > maxY)
+ if (aPoints[i].y > maxY)
{
- maxY = aPoints[i][1];
+ maxY = aPoints[i].y;
index = i;
}
}
diff --git a/tracker-easy/point-extractor.h b/tracker-easy/point-extractor.h
index d6bbd241..7827bb30 100644
--- a/tracker-easy/point-extractor.h
+++ b/tracker-easy/point-extractor.h
@@ -8,27 +8,26 @@
#pragma once
-#include "tracker-easy-api.h"
-
+#include "settings.h"
#include <vector>
#include <opencv2/core.hpp>
#include <opencv2/imgproc.hpp>
-using namespace numeric_types;
-
namespace EasyTracker
{
+ const int KPointCount = 3;
- class PointExtractor final : public IPointExtractor
+ class PointExtractor
{
public:
+ PointExtractor();
// extracts points from frame and draws some processing info into frame, if draw_output is set
// dt: time since last call in seconds
- void extract_points(const cv::Mat& aFrame, cv::Mat* aPreview, std::vector<vec2>& aPoints) override;
- PointExtractor();
+ void ExtractPoints(const cv::Mat& aFrame, cv::Mat* aPreview, std::vector<cv::Point>& aPoints);
+
// Settings
Settings s;
// Our frame with a channel size of 8 bits
diff --git a/tracker-easy/preview.cpp b/tracker-easy/preview.cpp
index f5c239e9..364e45ca 100644
--- a/tracker-easy/preview.cpp
+++ b/tracker-easy/preview.cpp
@@ -11,6 +11,7 @@
#include "compat/math.hpp"
#include <opencv2/imgproc.hpp>
+#include <QDebug>
namespace EasyTracker
@@ -99,20 +100,18 @@ namespace EasyTracker
QImage::Format_ARGB32);
}
- void Preview::draw_head_center(numeric_types::f x, numeric_types::f y)
+ void Preview::DrawCross(cv::Point aPoint)
{
- int px = iround(x), py = iround(y);
-
constexpr int len = 9;
static const cv::Scalar color(0, 255, 255);
cv::line(iFrameRgb,
- cv::Point(px - len, py),
- cv::Point(px + len, py),
+ cv::Point(aPoint.x - len, aPoint.y),
+ cv::Point(aPoint.x + len, aPoint.y),
color, 2);
cv::line(iFrameRgb,
- cv::Point(px, py - len),
- cv::Point(px, py + len),
+ cv::Point(aPoint.x, aPoint.y - len),
+ cv::Point(aPoint.x, aPoint.y + len),
color, 2);
}
diff --git a/tracker-easy/preview.h b/tracker-easy/preview.h
index 785d76d4..979d272b 100644
--- a/tracker-easy/preview.h
+++ b/tracker-easy/preview.h
@@ -9,8 +9,6 @@
#pragma once
-#include "tracker-easy-api.h"
-
#include <opencv2/core.hpp>
#include <QImage>
@@ -23,7 +21,7 @@ namespace EasyTracker
Preview& operator=(const cv::Mat& frame);
QImage get_bitmap();
- void draw_head_center(numeric_types::f x, numeric_types::f y);
+ void DrawCross(cv::Point aPoint);
operator cv::Mat&() { return iFrameResized; }
operator cv::Mat const&() const { return iFrameResized; }
diff --git a/tracker-easy/tracker-easy-api.h b/tracker-easy/tracker-easy-api.h
deleted file mode 100644
index b50ce018..00000000
--- a/tracker-easy/tracker-easy-api.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* Copyright (c) 2019 Stephane Lenclud
- *
- * Permission to use, copy, modify, and/or distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- */
-
-#pragma once
-
-#include "settings.h"
-
-#include "cv/numeric.hpp"
-#include "options/options.hpp"
-#include "video/camera.hpp"
-
-#include <tuple>
-#include <type_traits>
-#include <memory>
-
-#include <opencv2/core.hpp>
-
-#include <QImage>
-#include <QString>
-
-
-const int KPointCount = 3;
-
-class IPointExtractor
-{
-public:
- using vec2 = numeric_types::vec2;
- using f = numeric_types::f;
-
- virtual void extract_points(const cv::Mat& image, cv::Mat* aPreview, std::vector<vec2>& aPoints) = 0;
-};
-
-
diff --git a/tracker-easy/tracker-easy-dialog.h b/tracker-easy/tracker-easy-dialog.h
index 861e0ff9..f5a52d0c 100644
--- a/tracker-easy/tracker-easy-dialog.h
+++ b/tracker-easy/tracker-easy-dialog.h
@@ -7,9 +7,8 @@
#pragma once
-#include "tracker-easy-api.h"
-
#include "tracker-easy.h"
+#include "settings.h"
#include "ui_tracker-easy-settings.h"
#include "cv/translation-calibrator.hpp"
#include "video/video-widget.hpp"
diff --git a/tracker-easy/tracker-easy.cpp b/tracker-easy/tracker-easy.cpp
index e69cbb92..d5bccc6b 100644
--- a/tracker-easy/tracker-easy.cpp
+++ b/tracker-easy/tracker-easy.cpp
@@ -12,7 +12,6 @@
#include "compat/math-imports.hpp"
#include "compat/check-visible.hpp"
#include "point-extractor.h"
-#include "tracker-easy-api.h"
#include <QHBoxLayout>
#include <QDebug>
@@ -36,7 +35,6 @@ namespace EasyTracker
Tracker::Tracker() :
s{ KModuleName },
- iPointExtractor{ std::make_unique<PointExtractor>() },
iPreview{ preview_width, preview_height }
{
cv::setBreakOnError(true);
@@ -141,7 +139,7 @@ namespace EasyTracker
}
iPoints.clear();
- iPointExtractor->extract_points(iMatFrame, (preview_visible ? &iPreview.iFrameRgb : nullptr), iPoints);
+ iPointExtractor.ExtractPoints(iMatFrame, (preview_visible ? &iPreview.iFrameRgb : nullptr), iPoints);
point_count.store(iPoints.size(), std::memory_order_relaxed);
const bool success = iPoints.size() >= KPointCount;
@@ -175,9 +173,9 @@ namespace EasyTracker
int minY = std::numeric_limits<int>::max();
for (int i = 0; i < 3; i++)
{
- if (iPoints[i][1] < minY)
+ if (iPoints[i].y < minY)
{
- minY = iPoints[i][1];
+ minY = iPoints[i].y;
topPointIndex = i;
}
}
@@ -189,9 +187,9 @@ namespace EasyTracker
for (int i = 0; i < 3; i++)
{
// Excluding top most point
- if (i != topPointIndex && iPoints[i][0] > maxX)
+ if (i != topPointIndex && iPoints[i].x > maxX)
{
- maxX = iPoints[i][0];
+ maxX = iPoints[i].x;
rightPointIndex = i;
}
}
@@ -209,9 +207,9 @@ namespace EasyTracker
}
//
- trackedPoints.push_back(cv::Point2f(iPoints[rightPointIndex][0], iPoints[rightPointIndex][1]));
- trackedPoints.push_back(cv::Point2f(iPoints[leftPointIndex][0], iPoints[leftPointIndex][1]));
- trackedPoints.push_back(cv::Point2f(iPoints[topPointIndex][0], iPoints[topPointIndex][1]));
+ trackedPoints.push_back(iPoints[rightPointIndex]);
+ trackedPoints.push_back(iPoints[leftPointIndex]);
+ trackedPoints.push_back(iPoints[topPointIndex]);
dbgout << "Object: " << objectPoints << "\n";
dbgout << "Points: " << trackedPoints << "\n";
@@ -303,7 +301,7 @@ namespace EasyTracker
if (topPointIndex != -1)
{
// Render a cross to indicate which point is the head
- iPreview.draw_head_center(iPoints[topPointIndex][0], iPoints[topPointIndex][1]);
+ iPreview.DrawCross(iPoints[topPointIndex]);
}
// Show full size preview pop-up
diff --git a/tracker-easy/tracker-easy.h b/tracker-easy/tracker-easy.h
index fe7fece7..8b771c67 100644
--- a/tracker-easy/tracker-easy.h
+++ b/tracker-easy/tracker-easy.h
@@ -9,11 +9,12 @@
#pragma once
#include "api/plugin-api.hpp"
-#include "tracker-easy-api.h"
#include "cv/numeric.hpp"
#include "video/video-widget.hpp"
#include "video/camera.hpp"
#include "preview.h"
+#include "settings.h"
+#include "point-extractor.h"
#include <atomic>
#include <memory>
@@ -58,11 +59,12 @@ namespace EasyTracker
Settings s;
std::unique_ptr<QLayout> layout;
- std::vector<vec2> iPoints;
+ std::vector<cv::Point> iPoints;
int preview_width = 320, preview_height = 240;
- std::unique_ptr<IPointExtractor> iPointExtractor;
+ PointExtractor iPointExtractor;
+
std::unique_ptr<video::impl::camera> camera;
video::impl::camera::info iCameraInfo;
std::unique_ptr<video_widget> widget;