https://github.com/godtoy/python-tecent-slider-crack
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# __author__ = '__zx-coder__'
import os
import time
import uuid
import cv2
import cv2 as cv
import pyautogui
def myscreen(region):
time.sleep(0.5)
file = os.path.join(os.path.dirname(__file__), "tmp", str(uuid.uuid4()) + "_captcha.jpeg")
return pyautogui.screenshot(file, region=region)
def get_pos(image):
"""
缺口轮廓检测
对付腾讯滑块够用
该方法识别率 50% 左右,使用背景简单的图
"""
blurred = cv.GaussianBlur(image, (5, 5), 0)
canny = cv.Canny(blurred, 84, 400)
# cv.imshow('canny', canny)
# cv.waitKey()
contours, hierarchy = cv.findContours(canny, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
# 画轮廓
# areas = []
# for contour in contours:
# areas.append(cv2.contourArea(contour))
# areas = np.asarray(areas)
# index = areas.argsort()
# print(index[-1])
# img = cv2.drawContours(image, contours, index[-1], (0, 255, 0), 2)
# cv.imshow('cnts', img)
# cv2.waitKey()
# cv2.destroyAllWindows()
for i, contour in enumerate(contours):
# for contour in contours:
m = cv.moments(contour)
if m['m00'] == 0:
cx = cy = 0
else:
cx, cy = m['m10'] / m['m00'], m['m01'] / m['m00']
print('周长:', cv.arcLength(contour, True))
print('面积:', cv.contourArea(contour))
# print(contour)
print('重心:', cx, cy)
print(i)
print("-" * 200)
if 1500 < cv.contourArea(contour) < 3000 and 200 < cv.arcLength(contour, True) < 300:
if cx < 200:
continue
x, y, w, h = cv.boundingRect(contour) # 外接矩形
cv.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
cv.imshow('image', image)
cv.waitKey()
# print(x)
# real_show(image)
return x
return 0
# img= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) #转化为灰度图
def onmouse(event, x, y, flags, param): # 标准鼠标交互函数
# if event==cv2.EVENT_LBUTTONDBLCLK : #当鼠标点击时
# print("y=",y), print("x=",x), print(img[y,x],"\n") #显示鼠标所在像素的数值,注意像素表示方法和坐标位置的不同
if event == cv2.EVENT_MOUSEMOVE: # 当鼠标移动时
print("y=", y, "x=", x, img[y, x], "\n") # 显示鼠标所在像素的数值,注意像素表示方法和坐标位置的不同
def real_show(img):
'''实时显示坐标'''
cv2.namedWindow("img") # 构建窗口
cv2.setMouseCallback("img", onmouse) # 回调绑定窗口
while True: # 无限循环
cv2.imshow("img", img) # 显示图像
if cv2.waitKey() == 27:
cv2.destroyAllWindows() # 关闭窗口
break
if __name__ == '__main__':
"""
这里是滑块缺口识别
识别到后
1。可以通过自动化工具取拖动滑块
2。可以通过参数解析的形式生成参数提交通过验证
"""
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent / 'tmp'
for path in BASE_DIR.iterdir():
print(path)
img = cv2.imread(str(path))
get_pos(img)
# img = cv2.imread('tmp/1cef093f-0950-46e6-bff6-70fd2e88fb7d_captcha.jpeg')
# print(get_pos(img))
网友评论