# _*_ coding:UTF-8 _*_
[文档]
class TargetPos(object):
"""
点击目标图片的不同位置,默认为中心点0
1 2 3
4 0 6
7 8 9
"""
LEFTUP, UP, RIGHTUP = 1, 2, 3
LEFT, MID, RIGHT = 4, 5, 6
LEFTDOWN, DOWN, RIGHTDOWN = 7, 8, 9
[文档]
def getXY(self, cvret, pos):
if pos == 0 or pos == self.MID:
return cvret["result"]
rect = cvret.get("rectangle")
if not rect:
print("could not get rectangle, use mid point instead")
return cvret["result"]
w = rect[2][0] - rect[0][0]
h = rect[2][1] - rect[0][1]
if pos == self.LEFTUP:
return rect[0]
elif pos == self.LEFTDOWN:
return rect[1]
elif pos == self.RIGHTDOWN:
return rect[2]
elif pos == self.RIGHTUP:
return rect[3]
elif pos == self.LEFT:
return rect[0][0], rect[0][1] + h / 2
elif pos == self.UP:
return rect[0][0] + w / 2, rect[0][1]
elif pos == self.RIGHT:
return rect[2][0], rect[2][1] - h / 2
elif pos == self.DOWN:
return rect[2][0] - w / 2, rect[2][1]
else:
print("invalid target_pos:%s, use mid point instead" % pos)
return cvret["result"]