数美的缺口识别 + 轨迹生成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | import math import random import cv2 import numpy as np import requests def get_distance(fg, bg): fg_image = np.asarray( bytearray(requests.get(url = fg, verify = False ).content), dtype = "uint8" ) fg_image = cv2.imdecode(fg_image, 1 ) shape = fg_image.shape x_points, y_points = [], [] for x_point in range (shape[ 0 ]): for y_point in range (shape[ 1 ]): if list (fg_image[x_point][y_point]) ! = [ 0 , 0 , 0 ]: x_points.append(x_point) y_points.append(y_point) fg_cut_image = fg_image[ min (x_points) : max (x_points), ] bg_image = np.asarray( bytearray(requests.get(url = bg, verify = False ).content), dtype = "uint8" ) bg_image = cv2.imdecode(bg_image, 1 ) bg_cut_image = bg_image[ min (x_points) : max (x_points), ] result = cv2.matchTemplate(bg_cut_image, fg_cut_image, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(result) distance = max_loc[ 0 ] return int (distance) def get_track(distance: int ): """ 获取轨迹 Args: distance: 距离 Returns: """ x = [ 0 , 0 ] y = [ 0 , 0 , 0 ] z = [ 0 ] count = np.linspace( - math.pi / 2 , math.pi / 2 , random.randrange( 20 , 30 )) func = list ( map (math.sin, count)) nx = [i + 1 for i in func] add = random.randrange( 10 , 15 ) sadd = distance + add x.extend( list ( map ( lambda x: x * (sadd / 2 ), nx))) x.extend(np.linspace(sadd, distance, 3 if add > 12 else 2 )) x = [math.floor(i) for i in x] for i in range ( len (x) - 2 ): if y[ - 1 ] < 30 : y.append(y[ - 1 ] + random.choice([ 0 , 0 , 1 , 1 , 2 , 2 , 1 , 2 , 0 , 0 , 3 , 3 ])) else : y.append( y[ - 1 ] + random.choice([ 0 , 0 , - 1 , - 1 , - 2 , - 2 , - 1 , - 2 , 0 , 0 , - 3 , - 3 ]) ) for i in range ( len (x) - 1 ): z.append( (z[ - 1 ] / / 100 * 100 ) + 100 + random.choice([ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 2 ]) ) trace = list ( map ( list , zip (x, y, z))) times = trace[ - 1 ][ - 1 ] + random.randint( 1 , 5 ) return trace, times fg = 'https://castatic.fengkongcloud.cn/crb/slide-atlas-default-without-logo-20230423/v4/c7db06c0414b3faa735cbc324bdfd7ff_fg.png' bg = 'https://castatic.fengkongcloud.cn/crb/slide-atlas-default-without-logo-20230423/v4/c7db06c0414b3faa735cbc324bdfd7ff_bg.jpg' print (get_distance(fg, bg)) print (get_track(get_distance(fg, bg))) |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
2019-06-20 swarm 集群
2019-06-20 docker compose