滑块缺口定位及轨迹

有读者希望我分享一下滑块轨迹的代码,其实数美对于轨迹的检测几近于无
获取缺口距离代码

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_trace_and_times(distance):
    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

这两套算法针对数美的滑动验证码成功率高达99%,偶尔失误是因为缺口距离识别错误


测试100次结果1

测试100次结果2

测试100次结果3
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容