Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def find_template_by_crop(self, img, area=None):
if Aircv.support_network:
img_url = "".join(["http://", Aircv.host, Aircv.path, img])
data = requests.get(img_url)
img_serch = self.cvHandler.imdecode(data.content)
else:
img_serch = self.cvHandler.imread(img)
if area:
crop_img = self.aircv_cache_image[area[1]:area[3], area[0]:area[2]]
result = self.cvHandler.find_template(crop_img, img_serch)
point = result['result'] if result else None
if point:
point = (point[0] + area[0], point[1] + area[1])
else:
crop_img = self.aircv_cache_image
result = self.cvHandler.find_template(crop_img, img_serch)
point = result['result'] if result else None
return (int(point[0] * self.zoom_out), int(point[1] * self.zoom_out)) if point else None
def find_template_by_crop(self, img, area=None):
if Aircv.support_network:
img_url = "".join(["http://", Aircv.host, Aircv.path, img])
data = requests.get(img_url)
img_serch = self.cvHandler.imdecode(data.content)
else:
img_serch = self.cvHandler.imread(img)
if area:
crop_img = self.aircv_cache_image[area[1]:area[3], area[0]:area[2]]
result = self.cvHandler.find_template(crop_img, img_serch)
point = result['result'] if result else None
if point:
point = (point[0] + area[0], point[1] + area[1])
else:
crop_img = self.aircv_cache_image
result = self.cvHandler.find_template(crop_img, img_serch)
point = result['result'] if result else None
def swipe_points(self, img_list, duration=0.5, timeout=timeout, area=None):
point_list = []
while timeout:
if self.debug:
print(timeout)
if self.aircv_cache_image is not None:
for img in img_list:
point = self.find_template_by_crop(img, area)
if not point:
break
point_list.append(point)
if len(point_list) == len(img_list):
time.sleep(Aircv.wait_before_operation)
self.d.swipe_points(point_list, duration)
break
else:
timeout -= 1
time.sleep(1)
if not timeout:
raise RuntimeError('No image found')
def on_message(ws, message):
this = self
if isinstance(message, bytes):
if int(time.time()) - this.__rcv_interva_time_cache >= Aircv.rcv_interval:
# with open(this.aircv_cache_image_name, 'wb') as f:
# f.write(message)
# this.aircv_cache_image = this.cvHandler.imread(self.aircv_cache_image_name)
this.aircv_cache_image = this.cvHandler.imdecode(message)
this.__rcv_interva_time_cache = int(time.time())