导航菜单
首页 >  词达人考试内容  > 词达人模拟点击完成答题代码开源(基本都可以自动)

词达人模拟点击完成答题代码开源(基本都可以自动)

2021年12月项目暂停更新了

(未经许可,禁止转载)

本方法采用ocr文字识别获取坐标,然后与答案进行对比,点击屏幕

在这里插入图片描述

1.申请某度api

具体方法参考我之前的博客

2.fiddler配置参考我这个博客 4.对代码的解析(拒绝白嫖,从我做起) ## 2020.04.16## jun_军## qq:604803231## blog主页:https://blog.csdn.net/weixin_44868057## qq交流群 719352964 (进群密码:bug)##方便小白观看,我没有定义函数from aip import AipOcrimport jsonimport pyautoguiimport numpy as npimport cv2 as cvimport timeimport ostry:while True:##1截图以及图片处理img = pyautogui.screenshot(region=[0,0,592,1040]) # x,y,w,himg.save('1/answer.jpg')## 2图片灰度处理def access_pixels(image):height, width, channels = image.shapeprint("width:%s,height:%s,channels:%s" % (width, height, channels))for row in range(height):for list in range(width):for c in range(channels):pv = image[row, list, c]image[row, list, c] = 255 - pv# cv.imshow("AfterDeal", image)src = cv.imread('1/answer.jpg')# cv.imshow('OriginalImage', src)# 获取当前系统以运行的周期数t1 = cv.getTickCount()# 运行函数access_pixels(src)# 再次获取当前系统以运行的周期数t2 = cv.getTickCount()# 计时周期数差值除以每秒周期数,获得处理时间print("time cost:%s s" % ((t2 - t1) / cv.getTickFrequency()))cv.imwrite('2/answer.jpg',src)## 3图片放大10倍# 已知数据集位置indir = "2/"# 保存的数据集位置outdir = "3/"cout = 0for fileName in os.listdir(indir):if fileName == '.DS_Store':continuecout = cout + 1# print(cout)# print(fileName)img_dir = os.path.join(indir, fileName) # 获取图片的名字# print(img_dir)src = cv.imread(img_dir) # 读取图片h1, w1 = src.shape[:2]# print(h1, w1) # 打印长和宽r = 1 / 10 # 缩小倍数# 进行缩放dst = cv.resize(src, (int(w1 / r), int(h1 / r)), interpolation=cv.INTER_CUBIC) # 使用双立方插值h2, w2 = dst.shape[:2]# print(h2, w2) # 打印长和宽# print(outdir + fileName)cv.imwrite(outdir + fileName, dst)## 4图片显示增强I = cv.imread('3/answer.jpg', flags=0)aa = 2Oa = I * float(aa)Oa[Oa > 255] = 255Oa = np.round(Oa)Oa = Oa.astype(np.uint8)cv.imwrite('4/answer.jpg', Oa)##5.解析本地json文件答案type = 0lodec = 'responseBody.txt'# def getAnswer():# print('搜寻答案....') #hhh=[]answers = []data = json.loads(open(lodec, "r", encoding='utf-8').read())# 多选if data['data']['topic_mode'] in [31]:options = data['data']['options']for option in options:if option['answer'] == True:answers.append(option['content'].replace('adj','').replace('adv','').replace('noun','').replace(';','').replace(',','').replace('verb',''))# 单选if data['data']['topic_mode'] in [11, 22, 42]:options = data['data']['options']for option in options:if option['answer'] == True:answers.append(option['content'].replace(' ', '').replace(';', ';').replace(',', ',').replace('.', '').replace('…','').replace('adj','').replace('adv','').replace('noun','').replace('verb','').replace(';','').replace(',','').replace('写',''))# 选词if data['data']['topic_mode'] in [32]:options = data['data']['answer_content']['answer_arr']for option in options:# print(option)answers.append(option.replace('\'','').replace('j','').replace('l','').replace('J',''))# 填空if data['data']['topic_mode'] in [51]:type = 1answers.append(data['data']['answer_content'])for a in answers:print(a)# return answersprint("答案:",answers)##6.ocr识别""" 你的 APPID AK SK 图2的内容"""APP_ID = '*********'API_KEY = '************************'SECRET_KEY = '************************'client = AipOcr(APP_ID, API_KEY, SECRET_KEY)fname = './4/answer.jpg'# fname = 'screenshot.png'# """ 读取图片 """def get_file_content(filePath):with open(filePath, 'rb') as fp:return fp.read()#image = get_file_content(fname)""" 调用通用文字识别, 图片参数为本地图片 """client.general(image)# options = {}# options["recognize_granularity"] = "big"# options["language_type"] = "CHN_ENG"# options["detect_direction"] = "true"# options["detect_language"] = "true"# options["vertexes_location"] = "true"# options["probability"] = "true"results = client.general(image)["words_result"] # 还可以使用身份证驾驶证模板,直接得到字典对应所需字段h = []t = []for result in results:text = result["words"].replace(' ','').replace('adj','').replace('adv','').replace('I','').replace('gan√','gain').replace("I","").replace('j','').replace('J','').replace('i','')\.replace('noun','').replace('verb','').replace('ver','').replace('ad','').replace(';','').replace(',','').replace('写','')b= (result["location"]['left']/int('10')+int('10'),result["location"]['top']/int('10')+int('10'))h.append(text)t.append(b)# e = (text)# text = print(result["words"].replace(';', '')) # 只有中文英文## # f = print(a.replace('None','')) ## location = result["location"]# # a= [result["location"]['left'],result["location"]['top']]# c= list(text)+list(b)# text1=list(text)+list(b)## # # print(re.findall(r"\d+\.?\d*",text))# # content = list("".join(a)) + list(b)# t=[]# print('识别到的坐标:',t)print("识别的:",h)if len(answers)>200:break## if len(list(h))

相关推荐: