diff options
author | Andy Sloane <andy@a1k0n.net> | 2020-06-04 18:48:51 -0700 |
---|---|---|
committer | Andy Sloane <andy@a1k0n.net> | 2020-06-05 07:29:25 -0700 |
commit | c3148df41d2c540acc0a6f72aa0f2088147848ee (patch) | |
tree | f10e2aeccd65e29860823ad3d58d045db5aab6a6 /tracker-pt/module | |
parent | 8b14345cf6e06a2938dc7cd8de5e8ca2ec2df039 (diff) |
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.
Diffstat (limited to 'tracker-pt/module')
-rw-r--r-- | tracker-pt/module/point_extractor.cpp | 43 | ||||
-rw-r--r-- | tracker-pt/module/point_extractor.h | 1 |
2 files changed, 41 insertions, 3 deletions
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); |