滑块验证码,滑块和有缺口的背景

滑块验证码,滑块和有缺口的背景

突破滑动验证码有缺口的背景内容

python 复制代码
import cv2 as cv
import numpy as np
import os
 
def find_p(img):
    ret, thresh = cv.threshold(img, 127, 255, 0)
    img = cv.cvtColor(img, cv.COLOR_GRAY2BGR)
    contours, hierarchy = cv.findContours(thresh, cv.RETR_TREE, cv.CHAIN_APPROX_SIMPLE)
    # print(len(contours))
    cnt = contours[0]
    x, y, w, h = cv.boundingRect(cnt)
    img = cv.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
    # cv.imshow('7', img)
 
    return x, y, w, h, thresh[y: y + h, x: x + w]
 
def tmp_match(img, tar):
    w, h = tar.shape[0:-1]
    # methods = ['cv.TM_CCOEFF', 'cv.TM_CCOEFF_NORMED', 'cv.TM_CCORR',
    #            'cv.TM_CCORR_NORMED', 'cv.TM_SQDIFF', 'cv.TM_SQDIFF_NORMED']
    method = cv.TM_CCOEFF_NORMED
    # Apply template Matching
    res = cv.matchTemplate(img, tar, method)
    min_val, max_val, min_loc, max_loc = cv.minMaxLoc(res)
    # If the method is TM_SQDIFF or TM_SQDIFF_NORMED, take minimum
    top_left = max_loc
    bottom_right = (top_left[0] + w, top_left[1] + h)
    cv.rectangle(img, top_left, bottom_right, 255, 2)
    # cv.imshow('5', img)
    return top_left
 
def sub_img_op(pth, pth1):
    img = cv.imread(pth, -1)
    img_tar = cv.imread(pth1)
    sub_img = img[:, :, 3]
 
    img_o = cv.cvtColor(img, cv.COLOR_BGRA2BGR)
 
    # sub_img = cv.cvtColor(sub_img, cv.GRAY2BGR)
    # print(sub_img[50:70, :])
 
    x, y, w, h, mask = find_p(sub_img)
 
    white_img = np.ones([h, w, 3], dtype='uint8') * 255
 
    # print(x, y, w, h)
 
    img_tar_sub = img_tar[y: y + h, :, :]
    img_o_sub = img_o[y: y + h, x: x + w, :]
 
    res_img = cv.addWeighted(img_o_sub, 0.7, white_img, 0.3, 0)
    # res_img = img_o_sub
 
    top_left = tmp_match(img_tar_sub, res_img)
 
    print(top_left[0])
 
    # cv.imshow('1', img_o)
    cv.imshow('2', img_tar_sub)
    cv.imshow('3', res_img)
 
    cv.waitKey()
    cv.destroyAllWindows()
 
    return top_left[0]
相关推荐
myenjoy_130 分钟前
串口采集与 Modbus RTU——字节流里的时间敏感博弈
网络·python·网络协议·tcp/ip
易舟云财务软件38 分钟前
财务 AI Python 实战:从自动化报表到智能风控的应用场景
人工智能·python·自动化
武雄(小星Ai)39 分钟前
一个模型干五件事:拆解 NVIDIA Cosmos 3 的物理 AI 全模态架构
人工智能·python·agent
Mr.Daozhi42 分钟前
跨境电商选品完整流水线:Google Trends筛词+Meta广告分析,CLI工具设计实战
开发语言·爬虫·python·跨境电商·工具链·选品
装不满的克莱因瓶1 小时前
掌握典型卷积神经网络的搭建
人工智能·python·深度学习·神经网络·机器学习·ai·cnn
海鸥-w1 小时前
用python (fastapi)做项目第一天创建项目结构,数据建表,ORM配置安装,写第一个接口
数据库·python·fastapi
㳺三才人子1 小时前
初探 Flask-WTF
后端·python·flask·html5
装不满的克莱因瓶1 小时前
基于 sklearn 工具和鸢尾花数据集,进行逻辑回归实战
人工智能·python·机器学习·ai·逻辑回归·sklearn