手势识别

该类允许您轻松创建新手势并进行比较:

from kivy.gesture import Gesture, GestureDatabase

# Create a gesture
g = Gesture()
g.add_stroke(point_list=[(1,1), (3,4), (2,1)])
g.normalize()

# Add it to the database
gdb = GestureDatabase()
gdb.add_gesture(g)

# And for the next gesture, try to find it!
g2 = Gesture()
# ...
gdb.find(g2)

警告

你真的不想这样做:这更多是一个如何动态构建手势的示例。通常,你需要更多的点,因此最好将手势记录在文件中,并在之后重新加载以进行比较。请查看examples/gestures目录,那里有一个如何做到这一点的示例。

class kivy.gesture.Gesture(tolerance=None)[源代码]

基类:object

Oleg Dopertchouk 手势识别算法的 Python 实现:http://www.gamedev.net/reference/articles/article2039.asp

由Jeiel Aranal(chemikhazi@gmail.com)实现,并已发布至公共领域。

add_stroke(point_list=None)[源代码]

为手势添加一条笔画,并返回该笔画的实例。可选参数 point_list 是鼠标点的列表,用于构成该笔画。

dot_product(comparison_gesture)[源代码]

计算该手势与另一个手势的点积。

get_rigid_rotation(dstpts)[源代码]

提取一组点所需应用的旋转,以最小化其与第二组点之间的距离。假设这两组点均已居中。这是一个简化版本,仅根据手势的第一个点来选择一个角度。

get_score(comparison_gesture, rotation_invariant=True)[源代码]

返回该手势与另一个手势的匹配得分。

normalize(stroke_samples=32)[源代码]

运行手势归一化算法,并计算与自身的点积。

class kivy.gesture.GestureDatabase[源代码]

基类:object

用于处理手势数据库的类。

add_gesture(gesture)[源代码]

向数据库中添加一个新的手势。

find(gesture, minscore=0.9, rotation_invariant=True)[源代码]

在数据库中查找匹配的手势。

gesture_to_str(gesture)[源代码]

将手势转换为唯一字符串。

str_to_gesture(data)[源代码]

将一个唯一字符串转换为手势。

class kivy.gesture.GestureStroke[源代码]

基类:object

手势可以由多个笔画组成。

add_point(x=x_pos, y=y_pos)[源代码]

向笔画中添加一个点。

center_stroke(offset_x, offset_y)[源代码]

通过偏移点来使描边居中。

normalize_stroke(sample_points=32)[源代码]

标准化笔画,使每个笔画具有标准数量的点。如果笔画已标准化,则返回True;如果无法标准化,则返回False。`sample_points`控制笔画的解析度。

points_distance(point1=GesturePoint, point2=GesturePoint)[源代码]

返回两个手势点之间的距离。

scale_stroke(scale_factor=float)[源代码]

按比例因子缩小描边。

stroke_length(point_list=None)[源代码]

计算笔画的长度。如果提供了点列表,则计算该列表的长度。