summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-10-08 13:17:13 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-10-08 13:17:13 +0200
commitbf167d28bc496d80cc391d3cb47e76d7b6974394 (patch)
tree997baf2a8a3a88792ed35a5a4e7563bcb461fbbd
parent5c2627ec26aeae563cbaaaa7e5b68caf6f2e929f (diff)
tracker/pt: grayscale methods work
- fix a braino (don't divide by two) - default to exact averaging, not perceptual weighted - use more specific cv::addWeighted
-rw-r--r--tracker-pt/FTNoIR_PT_Controls.ui7
-rw-r--r--tracker-pt/ftnoir_tracker_pt_dialog.cpp3
-rw-r--r--tracker-pt/ftnoir_tracker_pt_settings.h5
-rw-r--r--tracker-pt/point_extractor.cpp78
4 files changed, 49 insertions, 44 deletions
diff --git a/tracker-pt/FTNoIR_PT_Controls.ui b/tracker-pt/FTNoIR_PT_Controls.ui
index a88db4b3..1132d156 100644
--- a/tracker-pt/FTNoIR_PT_Controls.ui
+++ b/tracker-pt/FTNoIR_PT_Controls.ui
@@ -423,7 +423,12 @@
</property>
<item>
<property name="text">
- <string>Normal</string>
+ <string>Average</string>
+ </property>
+ </item>
+ <item>
+ <property name="text">
+ <string>Natural</string>
</property>
</item>
<item>
diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp
index 2f554cbf..6b31ac8a 100644
--- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp
+++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp
@@ -83,7 +83,8 @@ TrackerDialog_PT::TrackerDialog_PT()
connect(this, &TrackerDialog_PT::poll_tracker_info, this, &TrackerDialog_PT::poll_tracker_info_impl, Qt::DirectConnection);
static constexpr pt_color_type color_types[] = {
- pt_color_normal,
+ pt_color_average,
+ pt_color_natural,
pt_color_floppy_filter,
pt_color_red_only,
};
diff --git a/tracker-pt/ftnoir_tracker_pt_settings.h b/tracker-pt/ftnoir_tracker_pt_settings.h
index 265d382e..6bbba16b 100644
--- a/tracker-pt/ftnoir_tracker_pt_settings.h
+++ b/tracker-pt/ftnoir_tracker_pt_settings.h
@@ -15,9 +15,10 @@ enum pt_color_type
{
// explicit values, gotta preserve the numbering in .ini
// don't reuse when removing some of the modes
- pt_color_normal = 2,
+ pt_color_natural = 2,
pt_color_red_only = 3,
pt_color_floppy_filter = 4,
+ pt_color_average = 5,
};
struct settings_pt : opts
@@ -74,6 +75,6 @@ struct settings_pt : opts
dynamic_pose(b, "dynamic-pose-resolution", true),
init_phase_timeout(b, "init-phase-timeout", 250),
auto_threshold(b, "automatic-threshold", true),
- blob_color(b, "blob-color", pt_color_normal)
+ blob_color(b, "blob-color", pt_color_average)
{}
};
diff --git a/tracker-pt/point_extractor.cpp b/tracker-pt/point_extractor.cpp
index 7ffbed7a..07c0b1aa 100644
--- a/tracker-pt/point_extractor.cpp
+++ b/tracker-pt/point_extractor.cpp
@@ -12,6 +12,7 @@
#include <QDebug>
#include <opencv2/videoio.hpp>
+#include <opencv2/highgui.hpp>
#include <cmath>
#include <algorithm>
@@ -115,55 +116,52 @@ void PointExtractor::extract_points(const cv::Mat& frame, cv::Mat& preview_frame
}
const pt_color_type color = s.blob_color;
- if (color == pt_color_normal)
+
+ switch (color)
{
- // convert to grayscale
- // this operation is optimized
- cv::cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY);
- }
- else
+ case pt_color_floppy_filter:
{
- switch (color)
- {
- case pt_color_floppy_filter:
- {
- // weight for blue color
- static constexpr float B = .8;
- // single channel weight
- static constexpr float A = 1./2;
-
- static constexpr int from_to[] = {
- 0, 0,
- 1, 1
- };
+ // weight for blue color
+ static constexpr float B = .8;
- separate_channels(frame, from_to, 2);
+ static constexpr int from_to[] = {
+ 0, 0,
+ 1, 1
+ };
- ch_float[2] = ch_float[0] * B * A // blue
- + ch_float[1] * (1 - B) * A; // green
- ch_float[2].convertTo(frame_gray, CV_8U);
+ separate_channels(frame, from_to, 2);
- break;
- }
- case pt_color_red_only:
- {
- static constexpr int from_to[] = {
- 2, 0 // red
- };
+ cv::addWeighted(ch_float[0], B, ch_float[1], 1-B, 0, ch_float[2], 1);
+ ch_float[2].convertTo(frame_gray, CV_8U);
- separate_channels(frame, from_to, 1);
+ break;
+ }
+ case pt_color_red_only:
+ {
+ static constexpr int from_to[] = {
+ 2, 0 // red
+ };
- ch_float[0].convertTo(frame_gray, CV_8U);
+ separate_channels(frame, from_to, 1);
- break;
- }
- default:
- once_only(qDebug() << "wrong pt_color_type enum value" << int(color));
- // don't violate POLA
- cv::cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY);
- break;
- }
+ ch_float[0].convertTo(frame_gray, CV_8U);
+ break;
}
+ default:
+ once_only(qDebug() << "wrong pt_color_type enum value" << int(color));
+ /*FALLTHROUGH*/
+ case pt_color_average:
+ {
+ separate_channels(frame, nullptr);
+ ch_float[3] = (ch_float[0] + ch_float[1] + ch_float[2]) * (1./3);
+ ch_float[3].convertTo(frame_gray, CV_8U);
+ break;
+ }
+ case pt_color_natural:
+ cv::cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY);
+ break;
+ }
+
const double region_size_min = s.min_point_size;
const double region_size_max = s.max_point_size;