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

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

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

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]
相关推荐
计算机编程指导师7 分钟前
计算机毕设选题推荐:基于Spark+Django的黄金价格历史数据分析与可视化系统源码 毕业设计 选题推荐 毕设选题 数据分析 机器学习
大数据·python·计算机·spark·django·课程设计·黄金价格
yi01115 分钟前
LeetCode 424. 替换后的最长重复字符|不定长滑动窗口:如何判断窗口是否合法?
笔记·python·算法·leetcode·双指针·滑动窗口
计算机编程指导师17 分钟前
计算机毕设怎么做?基于Spark+Django的股票数据分析与可视化系统实战指导 源码 毕业设计 选题推荐 毕设选题 数据分析 机器学习
大数据·python·spark·django·毕业设计·股票·课程设计
高级程序源19 分钟前
django房屋租赁系统28636-计算机课程设计、毕业设计
python·mysql·elasticsearch·小程序·django·flask·课程设计
deepseek2323 分钟前
SQLite WAL 开了仍报 database is locked?Python 后台任务的事务与幂等修复
数据库·python·sqlite·并发编程·wal
计算机编程指导师1 小时前
计算机大数据项目推荐:基于Hadoop+Django的人工智能社交媒体情绪数据分析可视化系统源码 毕业设计 选题推荐 毕设选题 数据分析 机器学习
大数据·hadoop·python·计算机·spark·毕业设计·社交媒体
高级程序源1 小时前
springboot荆州旅游推介平台24175-计算机课程设计、毕业设计
vue.js·spring boot·python·mysql·django·课程设计
企业数字化笔记1 小时前
新租户注册成功却不能用?开通状态、初始化恢复与可用性验收
开发语言·python
Guarding and trust1 小时前
项目拆解(二):模型输出是‘野‘的——三层兜底+重分析,把AI变成可靠零件
java·人工智能·python·大模型·fastapi·ollama·错误兜底
用户298698530141 小时前
Python 实战:将 HTML 内容保存为图像文件
后端·python·html