Commit c6a7fc3c authored by Rob Schonberger's avatar Rob Schonberger Committed by Commit Bot

Add Neural Stylus Palm Detection Filter, with unittest.

This is a major change that adds an implementation of
NeuralStylusPalmDetectionFilter, along with a unittest for it.

The changes outside of that new file are to support the new
class added.

Note that no actual implementation of a model is included, and this
class is not instantiated or used in this change.

Bug: 1009290
Change-Id: Icac32a1a113b0ff83e307bccb3a3d0fc948bcc48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1880414Reviewed-by: default avatarMichael Spang <spang@chromium.org>
Commit-Queue: Rob Schonberger <robsc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710609}
parent af87185e
......@@ -625,6 +625,7 @@ if (!is_ios) {
"ozone/evdev/touch_event_converter_evdev_unittest.cc",
"ozone/evdev/touch_filter/false_touch_finder_unittest.cc",
"ozone/evdev/touch_filter/heuristic_stylus_palm_detection_filter_unittest.cc",
"ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_unittest.cc",
"ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util_unittest.cc",
"ozone/evdev/touch_filter/open_palm_detection_filter_unittest.cc",
"ozone/evdev/touch_filter/palm_detection_filter_factory_unittest.cc",
......
......@@ -122,6 +122,8 @@ if (use_ozone) {
"evdev/touch_filter/horizontally_aligned_touch_noise_filter.h",
"evdev/touch_filter/low_pressure_filter.cc",
"evdev/touch_filter/low_pressure_filter.h",
"evdev/touch_filter/neural_stylus_palm_detection_filter.cc",
"evdev/touch_filter/neural_stylus_palm_detection_filter.h",
"evdev/touch_filter/neural_stylus_palm_detection_filter_model.cc",
"evdev/touch_filter/neural_stylus_palm_detection_filter_model.h",
"evdev/touch_filter/neural_stylus_palm_detection_filter_util.cc",
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_H_
#define UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_H_
#include <bitset>
#include <cstdint>
#include <deque>
#include <vector>
#include "base/time/time.h"
#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/touch_evdev_types.h"
#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_model.h"
#include "ui/events/ozone/evdev/touch_filter/neural_stylus_palm_detection_filter_util.h"
#include "ui/events/ozone/evdev/touch_filter/palm_detection_filter.h"
#include "ui/events/ozone/evdev/touch_filter/shared_palm_detection_filter_state.h"
#include "ui/gfx/geometry/point_f.h"
namespace ui {
// An implementation of PalmDetectionFilter that relies on a DNN implementation
// to decide on palm detection. Requires a configured model as an argument.
// Heuristics are added for handling short strokes
class EVENTS_OZONE_EVDEV_EXPORT NeuralStylusPalmDetectionFilter
: public PalmDetectionFilter {
public:
// Takes ownership of the model.
NeuralStylusPalmDetectionFilter(
const EventDeviceInfo& devinfo,
std::unique_ptr<NeuralStylusPalmDetectionFilterModel> palm_model,
SharedPalmDetectionFilterState* shared_palm_state);
~NeuralStylusPalmDetectionFilter() override;
void Filter(const std::vector<InProgressTouchEvdev>& touches,
base::TimeTicks time,
std::bitset<kNumTouchEvdevSlots>* slots_to_hold,
std::bitset<kNumTouchEvdevSlots>* slots_to_suppress) override;
static bool CompatibleWithNeuralStylusPalmDetectionFilter(
const EventDeviceInfo& devinfo);
const static int kFeaturesPerSample;
const static int kExtraFeaturesForNeighbor;
private:
std::string FilterNameForTesting() const override;
void FindNearestNeighborsWithin(
int neighbor_count,
float max_distance,
const PalmFilterStroke& stroke,
std::vector<std::pair<float, int>>* nearest_strokes) const;
void FindBiggestNeighborsWithin(
int neighbor_count,
float max_distance,
const PalmFilterStroke& stroke,
std::vector<std::pair<float, int>>* biggest_strokes) const;
bool DetectSpuriousStroke(const std::vector<float>& features,
int tracking_id,
float threshold) const;
// Extracts the feature vector for the specified stroke.
std::vector<float> ExtractFeatures(int tracking_id) const;
void AppendFeatures(const PalmFilterStroke& stroke,
std::vector<float>* features) const;
void AppendFeaturesAsNeighbor(const PalmFilterStroke& stroke,
float distance,
std::vector<float>* features) const;
bool ShouldDecideStroke(const PalmFilterStroke& stroke) const;
bool IsHeuristicPalmStroke(const PalmFilterStroke& stroke) const;
void EraseOldStrokes(base::TimeTicks time);
std::bitset<kNumTouchEvdevSlots> is_palm_;
std::bitset<kNumTouchEvdevSlots> is_delay_;
std::map<int, PalmFilterStroke> strokes_;
int tracking_ids_[kNumTouchEvdevSlots];
const PalmFilterDeviceInfo palm_filter_dev_info_;
std::unique_ptr<NeuralStylusPalmDetectionFilterModel> model_;
const static char kFilterName[];
static const std::vector<int> kRequiredAbsMtCodes;
DISALLOW_COPY_AND_ASSIGN(NeuralStylusPalmDetectionFilter);
};
} // namespace ui
#endif // UI_EVENTS_OZONE_EVDEV_TOUCH_FILTER_NEURAL_STYLUS_PALM_DETECTION_FILTER_H_
......@@ -28,8 +28,7 @@ struct EVENTS_OZONE_EVDEV_EXPORT NeuralStylusPalmDetectionFilterModelConfig {
// Maximum distance of neighbor centroid, in millimeters.
float max_neighbor_distance_in_mm = 0.0f;
base::TimeDelta max_dead_neighbor_time =
base::TimeDelta::FromMilliseconds(0.0);
base::TimeDelta max_dead_neighbor_time;
// Minimum count of samples in a stroke for neural comparison.
uint32_t min_sample_count = 0;
......@@ -62,7 +61,7 @@ class EVENTS_OZONE_EVDEV_EXPORT NeuralStylusPalmDetectionFilterModel {
// result.
virtual float Inference(const std::vector<float>& features) const = 0;
virtual NeuralStylusPalmDetectionFilterModelConfig& config() const = 0;
virtual const NeuralStylusPalmDetectionFilterModelConfig& config() const = 0;
};
} // namespace ui
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment