summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStéphane Lenclud <github@lenclud.com>2019-04-13 00:19:18 +0200
committerStéphane Lenclud <github@lenclud.com>2019-04-24 18:46:12 +0200
commit12e7ec5bdac206a3072f24577e897c79d6b0189f (patch)
treea7a83eaf731b6850cc902b34670c91908f9528be
parent3e36ce6985399c74676d46beef73a282eacf4109 (diff)
Easy Tracker: Support for single channel camera frames.
-rw-r--r--tracker-easy/frame.cpp30
-rw-r--r--tracker-easy/frame.hpp1
-rw-r--r--tracker-easy/point_extractor.cpp10
-rw-r--r--tracker-kinect-face/camera_kinect_ir.cpp6
-rw-r--r--tracker-kinect-face/camera_kinect_ir.h1
5 files changed, 35 insertions, 13 deletions
diff --git a/tracker-easy/frame.cpp b/tracker-easy/frame.cpp
index 9243c6a1..2464f85f 100644
--- a/tracker-easy/frame.cpp
+++ b/tracker-easy/frame.cpp
@@ -5,21 +5,37 @@
#include <opencv2/imgproc.hpp>
-Preview& Preview::operator=(const cv::Mat& frame)
+Preview& Preview::operator=(const cv::Mat& aFrame)
{
- if (frame.channels() != 3)
+ // Make sure our frame is RGB
+ // Make an extra copy if needed
+ int channelCount = aFrame.channels();
+ if (channelCount == 1)
{
- eval_once(qDebug() << "tracker/pt: camera frame depth: 3 !=" << frame.channels());
+ // Convert to RGB
+ cv::cvtColor(aFrame, iFrameRgb, cv::COLOR_GRAY2BGR);
+ }
+ else if (channelCount == 3)
+ {
+ iFrameRgb = aFrame;
+ }
+ else
+ {
+ eval_once(qDebug() << "tracker/easy: camera frame depth not supported" << aFrame.channels());
return *this;
}
- const bool need_resize = frame.cols != frame_out.cols || frame.rows != frame_out.rows;
+ const bool need_resize = iFrameRgb.cols != frame_out.cols || iFrameRgb.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);
+ {
+ cv::resize(iFrameRgb, frame_copy, cv::Size(frame_out.cols, frame_out.rows), 0, 0, cv::INTER_NEAREST);
+ }
else
- frame.copyTo(frame_copy);
-
+ {
+ iFrameRgb.copyTo(frame_copy);
+ }
+
return *this;
}
diff --git a/tracker-easy/frame.hpp b/tracker-easy/frame.hpp
index 01e99977..2a221de3 100644
--- a/tracker-easy/frame.hpp
+++ b/tracker-easy/frame.hpp
@@ -22,6 +22,7 @@ private:
static void ensure_size(cv::Mat& frame, int w, int h, int type);
cv::Mat frame_copy, frame_out;
+ cv::Mat iFrameRgb;
};
diff --git a/tracker-easy/point_extractor.cpp b/tracker-easy/point_extractor.cpp
index ecd72f70..06bb6c9a 100644
--- a/tracker-easy/point_extractor.cpp
+++ b/tracker-easy/point_extractor.cpp
@@ -242,7 +242,15 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame
{
ensure_buffers(frame);
- color_to_grayscale(frame, frame_gray_unmasked);
+ if (frame.channels() != 1)
+ {
+ color_to_grayscale(frame, frame_gray_unmasked);
+ }
+ else
+ {
+ frame_gray_unmasked = frame;
+ }
+
#if defined PREVIEW
cv::imshow("capture", frame_gray);
diff --git a/tracker-kinect-face/camera_kinect_ir.cpp b/tracker-kinect-face/camera_kinect_ir.cpp
index 8499003b..b1856f47 100644
--- a/tracker-kinect-face/camera_kinect_ir.cpp
+++ b/tracker-kinect-face/camera_kinect_ir.cpp
@@ -99,7 +99,7 @@ std::tuple<const video::impl::frame&, bool> CameraKinectIr::get_frame()
iFrame.width = 512;
iFrame.height = 424;
iFrame.stride = cv::Mat::AUTO_STEP;
- iFrame.channels = 3;
+ iFrame.channels = iMatFrame.channels();
return { iFrame, new_frame };
}
@@ -280,9 +280,7 @@ bool CameraKinectIr::get_frame_(cv::Mat& frame)
// For scalling to have more precission in the range we are interrested in
min = max - 255;
// See: https://stackoverflow.com/questions/14539498/change-type-of-mat-object-from-cv-32f-to-cv-8u/14539652
- raw.convertTo(iRaw8, CV_8U, 255.0 / (max - min), -255.0*min / (max - min));
- // Second convert to RGB
- cv::cvtColor(iRaw8, frame, cv::COLOR_GRAY2BGR);
+ raw.convertTo(frame, CV_8U, 255.0 / (max - min), -255.0*min / (max - min));
//
success = true;
}
diff --git a/tracker-kinect-face/camera_kinect_ir.h b/tracker-kinect-face/camera_kinect_ir.h
index a2ddaf76..7cd24651 100644
--- a/tracker-kinect-face/camera_kinect_ir.h
+++ b/tracker-kinect-face/camera_kinect_ir.h
@@ -70,7 +70,6 @@ private:
video::frame iFrame;
cv::Mat iMatFrame;
- cv::Mat iRaw8;
float fov = 0;
int width = 0, height = 0;