summaryrefslogtreecommitdiffhomepage
path: root/tracker-pt/tracker-wii/wii_frame.cpp
diff options
context:
space:
mode:
authorWei Shuai <cpuwolf@gmail.com>2018-01-15 17:08:48 +0800
committerWei Shuai <cpuwolf@gmail.com>2018-01-20 07:21:34 +0800
commit911e9deb712bafb5f622e215e286744696e90617 (patch)
tree9b6d365566a8a9934bb7b5dce7b924aa0bc8bbf4 /tracker-pt/tracker-wii/wii_frame.cpp
parentc49530ad99720fa638191db667610542bec3c696 (diff)
add Wiimote supporting in point tracker
1. extrack point from wii frame 2. wii_camera outputs wii raw data, wii_extractor create preview 3. wiimote fov is about 42 degree 4. wii:change block functions to non-block function "contains WiiYourself! wiimote code by gl.tter http://gl.tter.org"
Diffstat (limited to 'tracker-pt/tracker-wii/wii_frame.cpp')
-rw-r--r--tracker-pt/tracker-wii/wii_frame.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/tracker-pt/tracker-wii/wii_frame.cpp b/tracker-pt/tracker-wii/wii_frame.cpp
new file mode 100644
index 00000000..25228d57
--- /dev/null
+++ b/tracker-pt/tracker-wii/wii_frame.cpp
@@ -0,0 +1,88 @@
+/*
+* Copyright (c) 2015-2016 Stanislaw Halik <sthalik@misaki.pl>
+* Copyright (c) 2017-2018 Wei Shuai <cpuwolf@gmail.com>
+*/
+
+#include "wii_frame.hpp"
+
+#include "compat/math.hpp"
+
+#include <cstring>
+#include <tuple>
+
+#include <opencv2/imgproc.hpp>
+
+using namespace pt_module;
+
+WIIPreview& WIIPreview::operator=(const pt_frame& frame_)
+{
+ const cv::Mat& frame = frame_.as_const<const WIIFrame>()->mat;
+ ensure_size(frame_copy, frame_out.cols, frame_out.rows, CV_8UC3);
+
+ if (frame.channels() != 3)
+ {
+ once_only(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame.channels());
+ return *this;
+ }
+
+ const bool need_resize = frame.cols != frame_out.cols || frame.rows != frame_out.rows;
+ if (need_resize)
+ cv::resize(frame, frame_copy, cv::Size(frame_out.cols, frame_out.rows), 0, 0, cv::INTER_NEAREST);
+ else
+ frame.copyTo(frame_copy);
+
+ return *this;
+}
+
+WIIPreview::WIIPreview(int w, int h)
+{
+ ensure_size(frame_out, w, h, CV_8UC4);
+
+ frame_out.setTo(cv::Scalar(0, 0, 0, 0));
+}
+
+QImage WIIPreview::get_bitmap()
+{
+ int stride = frame_out.step.p[0];
+
+ if (stride < 64 || stride < frame_out.cols * 4)
+ {
+ once_only(qDebug() << "bad stride" << stride
+ << "for bitmap size" << frame_copy.cols << frame_copy.rows);
+ return QImage();
+ }
+
+ cv::cvtColor(frame_copy, frame_out, cv::COLOR_BGR2BGRA);
+
+ return QImage((const unsigned char*) frame_out.data,
+ frame_out.cols, frame_out.rows,
+ stride,
+ QImage::Format_ARGB32);
+}
+
+void WIIPreview::draw_head_center(double x, double y)
+{
+ double px_, py_;
+
+ std::tie(px_, py_) = to_pixel_pos(x, y, frame_copy.cols, frame_copy.rows);
+
+ int px = iround(px_), py = iround(py_);
+
+ constexpr int len = 9;
+
+ static const cv::Scalar color(0, 255, 255);
+ cv::line(frame_copy,
+ cv::Point(px - len, py),
+ cv::Point(px + len, py),
+ color, 1);
+ cv::line(frame_copy,
+ cv::Point(px, py - len),
+ cv::Point(px, py + len),
+ color, 1);
+}
+
+void WIIPreview::ensure_size(cv::Mat& frame, int w, int h, int type)
+{
+ if (frame.cols != w || frame.rows != h)
+ frame = cv::Mat(h, w, type);
+}