From c3148df41d2c540acc0a6f72aa0f2088147848ee Mon Sep 17 00:00:00 2001 From: Andy Sloane Date: Thu, 4 Jun 2020 18:48:51 -0700 Subject: Add proper color keying to tracker-pt Instead of just selecting the red/green/blue channels, also subtract the other channels. This allows for point tracking with just colored spots, rather than IR LEDs -- green and magenta work particularly well for this. This keeps the existing "Red/Green/Blue only" options, but adds "Red/Green/Blue/Cyan/Yellow/Magenta filter" options, which do a better job of isolating those colors. --- spline/spline-widget.cpp | 1 + tracker-pt/FTNoIR_PT_Controls.ui | 30 +++++++++++++++++++++++ tracker-pt/ftnoir_tracker_pt_dialog.cpp | 6 +++++ tracker-pt/lang/nl_NL.ts | 24 ++++++++++++++++++ tracker-pt/lang/ru_RU.ts | 24 ++++++++++++++++++ tracker-pt/lang/stub.ts | 24 ++++++++++++++++++ tracker-pt/lang/zh_CN.ts | 24 ++++++++++++++++++ tracker-pt/module/point_extractor.cpp | 43 ++++++++++++++++++++++++++++++--- tracker-pt/module/point_extractor.h | 1 + tracker-pt/pt-settings.hpp | 6 +++++ 10 files changed, 180 insertions(+), 3 deletions(-) diff --git a/spline/spline-widget.cpp b/spline/spline-widget.cpp index 1e95aba6..8a5612d8 100644 --- a/spline/spline-widget.cpp +++ b/spline/spline-widget.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include diff --git a/tracker-pt/FTNoIR_PT_Controls.ui b/tracker-pt/FTNoIR_PT_Controls.ui index 061f5351..113e4f49 100644 --- a/tracker-pt/FTNoIR_PT_Controls.ui +++ b/tracker-pt/FTNoIR_PT_Controls.ui @@ -420,6 +420,36 @@ Blue only + + + Red filter + + + + + Green filter + + + + + Blue filter + + + + + Cyan filter + + + + + Yellow filter + + + + + Magenta filter + + diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index edf689a9..6c284381 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp +++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp @@ -100,6 +100,12 @@ TrackerDialog_PT::TrackerDialog_PT(const QString& module_name) : pt_color_red_only, pt_color_green_only, pt_color_blue_only, + pt_color_red_filter, + pt_color_green_filter, + pt_color_blue_filter, + pt_color_cyan_filter, + pt_color_yellow_filter, + pt_color_magenta_filter, }; for (unsigned k = 0; k < std::size(color_types); k++) diff --git a/tracker-pt/lang/nl_NL.ts b/tracker-pt/lang/nl_NL.ts index 1456157c..4802dba5 100644 --- a/tracker-pt/lang/nl_NL.ts +++ b/tracker-pt/lang/nl_NL.ts @@ -232,6 +232,30 @@ Don't roll or change position. Green only + + Red filter + + + + Green filter + + + + Blue filter + + + + Cyan filter + + + + Yellow filter + + + + Magenta filter + + pt_impl::TrackerDialog_PT diff --git a/tracker-pt/lang/ru_RU.ts b/tracker-pt/lang/ru_RU.ts index c91dd087..363d2061 100644 --- a/tracker-pt/lang/ru_RU.ts +++ b/tracker-pt/lang/ru_RU.ts @@ -237,6 +237,30 @@ ROLL или X/Y-смещения. Green only + + Red filter + + + + Green filter + + + + Blue filter + + + + Cyan filter + + + + Yellow filter + + + + Magenta filter + + pt_impl::TrackerDialog_PT diff --git a/tracker-pt/lang/stub.ts b/tracker-pt/lang/stub.ts index 36090e5e..e2085052 100644 --- a/tracker-pt/lang/stub.ts +++ b/tracker-pt/lang/stub.ts @@ -232,6 +232,30 @@ Don't roll or change position. Green only + + Red filter + + + + Green filter + + + + Blue filter + + + + Cyan filter + + + + Yellow filter + + + + Magenta filter + + pt_impl::TrackerDialog_PT diff --git a/tracker-pt/lang/zh_CN.ts b/tracker-pt/lang/zh_CN.ts index 667c2811..e51484ca 100644 --- a/tracker-pt/lang/zh_CN.ts +++ b/tracker-pt/lang/zh_CN.ts @@ -232,6 +232,30 @@ Don't roll or change position. Green only + + Red filter + + + + Green filter + + + + Blue filter + + + + Cyan filter + + + + Yellow filter + + + + Magenta filter + + pt_impl::TrackerDialog_PT diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index 7ad9925a..766a9364 100644 --- a/tracker-pt/module/point_extractor.cpp +++ b/tracker-pt/module/point_extractor.cpp @@ -33,7 +33,7 @@ using namespace numeric_types; /* http://en.wikipedia.org/wiki/Mean-shift -In this application the idea, is to eliminate any bias of the point estimate +In this application the idea, is to eliminate any bias of the point estimate which is introduced by the rather arbitrary thresholded area. One must recognize that the thresholded area can only move in one pixel increments since it is binary. Thus, its center of mass might make "jumps" as pixels are added/removed @@ -42,9 +42,9 @@ With mean-shift, a moving "window" or kernel is multiplied with the gray-scale image, and the COM is calculated of the result. This is iterated where the kernel center is set the previously computed COM. Thus, peaks in the image intensity distribution "pull" the kernel towards themselves. Eventually it stops moving, i.e. -then the computed COM coincides with the kernel center. We hope that the +then the computed COM coincides with the kernel center. We hope that the corresponding location is a good candidate for the extracted point. -The idea similar to the window scaling suggested in Berglund et al. "Fast, bias-free +The idea similar to the window scaling suggested in Berglund et al. "Fast, bias-free algorithm for tracking single particles with variable size and shape." (2008). */ static vec2 MeanShiftIteration(const cv::Mat1b &frame_gray, const vec2 ¤t_center, f filter_width) @@ -115,6 +115,13 @@ void PointExtractor::extract_single_channel(const cv::Mat& orig_frame, int idx, cv::mixChannels(&orig_frame, 1, &dest, 1, from_to, 1); } +void PointExtractor::filter_single_channel(const cv::Mat& orig_frame, float r, float g, float b, cv::Mat1b& dest) +{ + ensure_channel_buffers(orig_frame); + + cv::transform(orig_frame, dest, cv::Mat(cv::Matx13f(r, g, b))); +} + void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) { switch (s.blob_color) @@ -134,6 +141,36 @@ void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) extract_single_channel(frame, 2, output); break; } + case pt_color_red_filter: + { + filter_single_channel(frame, -0.5, -0.5, 1, output); + break; + } + case pt_color_green_filter: + { + filter_single_channel(frame, -0.5, 1, -0.5, output); + break; + } + case pt_color_blue_filter: + { + filter_single_channel(frame, 1, -0.5, -0.5, output); + break; + } + case pt_color_cyan_filter: + { + filter_single_channel(frame, 0.5, 0.5, -1, output); + break; + } + case pt_color_yellow_filter: + { + filter_single_channel(frame, -1, 0.5, 0.5, output); + break; + } + case pt_color_magenta_filter: + { + filter_single_channel(frame, 0.5, -1, 0.5, output); + break; + } case pt_color_average: { const int W = frame.cols, H = frame.rows, sz = W*H; diff --git a/tracker-pt/module/point_extractor.h b/tracker-pt/module/point_extractor.h index a6103667..9c97b6ce 100644 --- a/tracker-pt/module/point_extractor.h +++ b/tracker-pt/module/point_extractor.h @@ -49,6 +49,7 @@ private: void ensure_buffers(const cv::Mat& frame); void extract_single_channel(const cv::Mat& orig_frame, int idx, cv::Mat1b& dest); + void filter_single_channel(const cv::Mat& orig_frame, float r, float g, float b, cv::Mat1b& dest); void color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output); void threshold_image(const cv::Mat& frame_gray, cv::Mat1b& output); diff --git a/tracker-pt/pt-settings.hpp b/tracker-pt/pt-settings.hpp index 723ee08d..1016d17e 100644 --- a/tracker-pt/pt-settings.hpp +++ b/tracker-pt/pt-settings.hpp @@ -13,6 +13,12 @@ enum pt_color_type pt_color_average = 5, pt_color_blue_only = 6, pt_color_green_only = 7, + pt_color_red_filter = 8, + pt_color_green_filter = 9, + pt_color_blue_filter = 10, + pt_color_cyan_filter = 11, + pt_color_yellow_filter = 12, + pt_color_magenta_filter = 13, }; namespace pt_impl { -- cgit v1.2.3 From 9d9f42c35044bd4cbd40eea1b670b7a5114b7344 Mon Sep 17 00:00:00 2001 From: Andy Sloane Date: Fri, 5 Jun 2020 08:13:24 -0700 Subject: fix some RGB/BGR confusion --- tracker-pt/module/point_extractor.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index 766a9364..8fea1742 100644 --- a/tracker-pt/module/point_extractor.cpp +++ b/tracker-pt/module/point_extractor.cpp @@ -119,7 +119,7 @@ void PointExtractor::filter_single_channel(const cv::Mat& orig_frame, float r, f { ensure_channel_buffers(orig_frame); - cv::transform(orig_frame, dest, cv::Mat(cv::Matx13f(r, g, b))); + cv::transform(orig_frame, dest, cv::Mat(cv::Matx13f(b, g, r))); } void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) @@ -143,7 +143,7 @@ void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) } case pt_color_red_filter: { - filter_single_channel(frame, -0.5, -0.5, 1, output); + filter_single_channel(frame, 1, -0.5, -0.5, output); break; } case pt_color_green_filter: @@ -153,17 +153,17 @@ void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) } case pt_color_blue_filter: { - filter_single_channel(frame, 1, -0.5, -0.5, output); + filter_single_channel(frame, -0.5, -0.5, 1, output); break; } case pt_color_cyan_filter: { - filter_single_channel(frame, 0.5, 0.5, -1, output); + filter_single_channel(frame, -1, 0.5, 0.5, output); break; } case pt_color_yellow_filter: { - filter_single_channel(frame, -1, 0.5, 0.5, output); + filter_single_channel(frame, 0.5, 0.5, -1, output); break; } case pt_color_magenta_filter: -- cgit v1.2.3 From c5d6ace1295ca93e42962c93742c62d56222bee8 Mon Sep 17 00:00:00 2001 From: Andy Sloane Date: Fri, 5 Jun 2020 08:26:57 -0700 Subject: rename "filter" -> "chroma key" --- tracker-pt/FTNoIR_PT_Controls.ui | 12 ++++++------ tracker-pt/ftnoir_tracker_pt_dialog.cpp | 12 ++++++------ tracker-pt/lang/nl_NL.ts | 12 ++++++------ tracker-pt/lang/ru_RU.ts | 12 ++++++------ tracker-pt/lang/stub.ts | 12 ++++++------ tracker-pt/lang/zh_CN.ts | 12 ++++++------ tracker-pt/module/point_extractor.cpp | 12 ++++++------ tracker-pt/pt-settings.hpp | 12 ++++++------ 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/tracker-pt/FTNoIR_PT_Controls.ui b/tracker-pt/FTNoIR_PT_Controls.ui index 113e4f49..f683d7c3 100644 --- a/tracker-pt/FTNoIR_PT_Controls.ui +++ b/tracker-pt/FTNoIR_PT_Controls.ui @@ -422,32 +422,32 @@ - Red filter + Red chroma key - Green filter + Green chroma key - Blue filter + Blue chroma key - Cyan filter + Cyan chroma key - Yellow filter + Yellow chroma key - Magenta filter + Magenta chroma key diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index 6c284381..32916cc5 100644 --- a/tracker-pt/ftnoir_tracker_pt_dialog.cpp +++ b/tracker-pt/ftnoir_tracker_pt_dialog.cpp @@ -100,12 +100,12 @@ TrackerDialog_PT::TrackerDialog_PT(const QString& module_name) : pt_color_red_only, pt_color_green_only, pt_color_blue_only, - pt_color_red_filter, - pt_color_green_filter, - pt_color_blue_filter, - pt_color_cyan_filter, - pt_color_yellow_filter, - pt_color_magenta_filter, + pt_color_red_chromakey, + pt_color_green_chromakey, + pt_color_blue_chromakey, + pt_color_cyan_chromakey, + pt_color_yellow_chromakey, + pt_color_magenta_chromakey, }; for (unsigned k = 0; k < std::size(color_types); k++) diff --git a/tracker-pt/lang/nl_NL.ts b/tracker-pt/lang/nl_NL.ts index 4802dba5..3d12a7ea 100644 --- a/tracker-pt/lang/nl_NL.ts +++ b/tracker-pt/lang/nl_NL.ts @@ -233,27 +233,27 @@ Don't roll or change position. - Red filter + Red chroma key - Green filter + Green chroma key - Blue filter + Blue chroma key - Cyan filter + Cyan chroma key - Yellow filter + Yellow chroma key - Magenta filter + Magenta chroma key diff --git a/tracker-pt/lang/ru_RU.ts b/tracker-pt/lang/ru_RU.ts index 363d2061..0315d493 100644 --- a/tracker-pt/lang/ru_RU.ts +++ b/tracker-pt/lang/ru_RU.ts @@ -238,27 +238,27 @@ ROLL или X/Y-смещения. - Red filter + Red chroma key - Green filter + Green chroma key - Blue filter + Blue chroma key - Cyan filter + Cyan chroma key - Yellow filter + Yellow chroma key - Magenta filter + Magenta chroma key diff --git a/tracker-pt/lang/stub.ts b/tracker-pt/lang/stub.ts index e2085052..4c8c4f82 100644 --- a/tracker-pt/lang/stub.ts +++ b/tracker-pt/lang/stub.ts @@ -233,27 +233,27 @@ Don't roll or change position. - Red filter + Red chroma key - Green filter + Green chroma key - Blue filter + Blue chroma key - Cyan filter + Cyan chroma key - Yellow filter + Yellow chroma key - Magenta filter + Magenta chroma key diff --git a/tracker-pt/lang/zh_CN.ts b/tracker-pt/lang/zh_CN.ts index e51484ca..bbbc7f8d 100644 --- a/tracker-pt/lang/zh_CN.ts +++ b/tracker-pt/lang/zh_CN.ts @@ -233,27 +233,27 @@ Don't roll or change position. - Red filter + Red chroma key - Green filter + Green chroma key - Blue filter + Blue chroma key - Cyan filter + Cyan chroma key - Yellow filter + Yellow chroma key - Magenta filter + Magenta chroma key diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index 8fea1742..a92c87c9 100644 --- a/tracker-pt/module/point_extractor.cpp +++ b/tracker-pt/module/point_extractor.cpp @@ -141,32 +141,32 @@ void PointExtractor::color_to_grayscale(const cv::Mat& frame, cv::Mat1b& output) extract_single_channel(frame, 2, output); break; } - case pt_color_red_filter: + case pt_color_red_chromakey: { filter_single_channel(frame, 1, -0.5, -0.5, output); break; } - case pt_color_green_filter: + case pt_color_green_chromakey: { filter_single_channel(frame, -0.5, 1, -0.5, output); break; } - case pt_color_blue_filter: + case pt_color_blue_chromakey: { filter_single_channel(frame, -0.5, -0.5, 1, output); break; } - case pt_color_cyan_filter: + case pt_color_cyan_chromakey: { filter_single_channel(frame, -1, 0.5, 0.5, output); break; } - case pt_color_yellow_filter: + case pt_color_yellow_chromakey: { filter_single_channel(frame, 0.5, 0.5, -1, output); break; } - case pt_color_magenta_filter: + case pt_color_magenta_chromakey: { filter_single_channel(frame, 0.5, -1, 0.5, output); break; diff --git a/tracker-pt/pt-settings.hpp b/tracker-pt/pt-settings.hpp index 1016d17e..ed13a1ec 100644 --- a/tracker-pt/pt-settings.hpp +++ b/tracker-pt/pt-settings.hpp @@ -13,12 +13,12 @@ enum pt_color_type pt_color_average = 5, pt_color_blue_only = 6, pt_color_green_only = 7, - pt_color_red_filter = 8, - pt_color_green_filter = 9, - pt_color_blue_filter = 10, - pt_color_cyan_filter = 11, - pt_color_yellow_filter = 12, - pt_color_magenta_filter = 13, + pt_color_red_chromakey = 8, + pt_color_green_chromakey = 9, + pt_color_blue_chromakey = 10, + pt_color_cyan_chromakey = 11, + pt_color_yellow_chromakey = 12, + pt_color_magenta_chromakey = 13, }; namespace pt_impl { -- cgit v1.2.3