diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2020-06-05 19:42:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-05 19:42:46 +0000 |
commit | 442c01a60ed376c8693255a7649666113250bf37 (patch) | |
tree | dd3c66c0e9f837fdfef64aafa6b923f654419376 /tracker-pt | |
parent | 8b14345cf6e06a2938dc7cd8de5e8ca2ec2df039 (diff) | |
parent | c5d6ace1295ca93e42962c93742c62d56222bee8 (diff) |
Merge pull request #1095 from a1k0n/unstable
Add proper color keying to tracker-pt
Diffstat (limited to 'tracker-pt')
-rw-r--r-- | tracker-pt/FTNoIR_PT_Controls.ui | 30 | ||||
-rw-r--r-- | tracker-pt/ftnoir_tracker_pt_dialog.cpp | 6 | ||||
-rw-r--r-- | tracker-pt/lang/nl_NL.ts | 24 | ||||
-rw-r--r-- | tracker-pt/lang/ru_RU.ts | 24 | ||||
-rw-r--r-- | tracker-pt/lang/stub.ts | 24 | ||||
-rw-r--r-- | tracker-pt/lang/zh_CN.ts | 24 | ||||
-rw-r--r-- | tracker-pt/module/point_extractor.cpp | 43 | ||||
-rw-r--r-- | tracker-pt/module/point_extractor.h | 1 | ||||
-rw-r--r-- | tracker-pt/pt-settings.hpp | 6 |
9 files changed, 179 insertions, 3 deletions
diff --git a/tracker-pt/FTNoIR_PT_Controls.ui b/tracker-pt/FTNoIR_PT_Controls.ui index 061f5351..f683d7c3 100644 --- a/tracker-pt/FTNoIR_PT_Controls.ui +++ b/tracker-pt/FTNoIR_PT_Controls.ui @@ -420,6 +420,36 @@ <string>Blue only</string> </property> </item> + <item> + <property name="text"> + <string>Red chroma key</string> + </property> + </item> + <item> + <property name="text"> + <string>Green chroma key</string> + </property> + </item> + <item> + <property name="text"> + <string>Blue chroma key</string> + </property> + </item> + <item> + <property name="text"> + <string>Cyan chroma key</string> + </property> + </item> + <item> + <property name="text"> + <string>Yellow chroma key</string> + </property> + </item> + <item> + <property name="text"> + <string>Magenta chroma key</string> + </property> + </item> </widget> </item> <item row="5" column="0"> diff --git a/tracker-pt/ftnoir_tracker_pt_dialog.cpp b/tracker-pt/ftnoir_tracker_pt_dialog.cpp index edf689a9..32916cc5 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_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 1456157c..3d12a7ea 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.</source> <source>Green only</source> <translation type="unfinished"></translation> </message> + <message> + <source>Red chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Green chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Blue chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cyan chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Yellow chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Magenta chroma key</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>pt_impl::TrackerDialog_PT</name> diff --git a/tracker-pt/lang/ru_RU.ts b/tracker-pt/lang/ru_RU.ts index c91dd087..0315d493 100644 --- a/tracker-pt/lang/ru_RU.ts +++ b/tracker-pt/lang/ru_RU.ts @@ -237,6 +237,30 @@ ROLL или X/Y-смещения.</translation> <source>Green only</source> <translation type="unfinished"></translation> </message> + <message> + <source>Red chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Green chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Blue chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cyan chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Yellow chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Magenta chroma key</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>pt_impl::TrackerDialog_PT</name> diff --git a/tracker-pt/lang/stub.ts b/tracker-pt/lang/stub.ts index 36090e5e..4c8c4f82 100644 --- a/tracker-pt/lang/stub.ts +++ b/tracker-pt/lang/stub.ts @@ -232,6 +232,30 @@ Don't roll or change position.</source> <source>Green only</source> <translation type="unfinished"></translation> </message> + <message> + <source>Red chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Green chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Blue chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cyan chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Yellow chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Magenta chroma key</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>pt_impl::TrackerDialog_PT</name> diff --git a/tracker-pt/lang/zh_CN.ts b/tracker-pt/lang/zh_CN.ts index 667c2811..bbbc7f8d 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.</source> <source>Green only</source> <translation type="unfinished"></translation> </message> + <message> + <source>Red chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Green chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Blue chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Cyan chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Yellow chroma key</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>Magenta chroma key</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>pt_impl::TrackerDialog_PT</name> diff --git a/tracker-pt/module/point_extractor.cpp b/tracker-pt/module/point_extractor.cpp index 7ad9925a..a92c87c9 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(b, g, r))); +} + 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_chromakey: + { + filter_single_channel(frame, 1, -0.5, -0.5, output); + break; + } + case pt_color_green_chromakey: + { + filter_single_channel(frame, -0.5, 1, -0.5, output); + break; + } + case pt_color_blue_chromakey: + { + filter_single_channel(frame, -0.5, -0.5, 1, output); + break; + } + case pt_color_cyan_chromakey: + { + filter_single_channel(frame, -1, 0.5, 0.5, output); + break; + } + case pt_color_yellow_chromakey: + { + filter_single_channel(frame, 0.5, 0.5, -1, output); + break; + } + case pt_color_magenta_chromakey: + { + 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..ed13a1ec 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_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 { |