-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreCAPTCHA_test.py
More file actions
53 lines (45 loc) · 1.41 KB
/
Copy pathreCAPTCHA_test.py
File metadata and controls
53 lines (45 loc) · 1.41 KB
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
from adb.client import Client as AdbClient
import time
import random
import datetime
# for image recognition
import cv2
import numpy as np
from matplotlib import pyplot as plt
# Connecting to BlueStacks
# Requires ./adb start-server; ./adb devices to be done prior
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("emulator-5554")
def encounteredreCAPTCHA():
#template = cv2.imread('recaptcha.png',0)
template = cv2.imread('images/recaptcha.png',0)
w, h = template.shape[::-1]
result = device.screencap()
#with open("screen.png", "wb") as fp:
# fp.write(result)
npimg = np.fromstring(str(result), np.uint8)
img = cv2.imdecode(npimg,0)
#img = cv2.imread('screen.png',0)
sift = cv2.xfeatures2d.SIFT_create()
# find the keypoints and descriptors with SIFT
kp1, des1 = sift.detectAndCompute(template,None)
kp2, des2 = sift.detectAndCompute(img,None)
# BFMatcher with default params
bf = cv2.BFMatcher()
matches = bf.knnMatch(des1,des2, k=2)
# Apply ratio test
good = []
for m,n in matches:
if m.distance < 0.75*n.distance:
good.append([m])
# cv2.drawMatchesKnn expects list of lists as matches.
img3 = cv2.drawMatchesKnn(template,kp1,img,kp2,good,flags=2,outImg=None)
plt.imshow(img3),plt.show()
#threshold = 0.9
#flag = False
#for i in res:
# if i.any() > threshold:
# flag = True
#return flag
#print("reCaptcha Seen: " + str(encounteredreCAPTCHA()))
encounteredreCAPTCHA()