|
一.识别滑块缺口使用ddddocr识别该算法识别准确率为95%左右,测试三轮,每轮测试100次defgenerate_distance(slice_url,bg_url):""":parambg_url:背景图地址:paramslice_url:滑块图地址:return:distance:rtype:Integer"""slide=ddddocr.DdddOcr(det=False,ocr=False,show_ad=False)slice_image=requests.get(slice_url).contentbg_image=requests.get(bg_url).contentresult=slide.slide_match(target_bytes,bg_image,simple_target=True)returnresult['target'][0]使用cv2识别该算法识别准确率为95%左右,测试三轮,每轮测试100次defgenerate_distance(slice_url,bg_url):""":parambg_url:背景图地址:paramslice_url:滑块图地址:return:distance:rtype:Integer"""slice_image=np.asarray(bytearray(requests.get(slice_url).content),dtype=np.uint8)slice_image=cv2.imdecode(slice_image,1)slice_image=cv2.Canny(slice_image,255,255)bg_image=np.asarray(bytearray(requests.get(bg_url).content),dtype=np.uint8)bg_image=cv2.imdecode(bg_image,1)bg_image=cv2.pyrMeanShiftFiltering(bg_image,5,50)bg_image=cv2.Canny(bg_image,255,255)result=cv2.matchTemplate(bg_image,slice_image,cv2.TM_CCOEFF_NORMED)min_val,max_val,min_loc,max_loc=cv2.minMaxLoc(result)returnmax_loc[0]二.构造滑块轨迹构造轨迹库图片长度为300,理论上就300种轨迹,实际上应该是200+种,还要减去滑块图的长度80手动滑他个几百次,并把距离和轨迹记录下来,识别出距离后直接查对应轨迹算法构造轨迹trackdefgenerate_track(distance):def__ease_out_expo(step):return1ifstep==1else1-pow(2,-10*step)tracks=[[random.randint(20,60),random.randint(10,40),0]]count=30+int(distance/2)_x,_y=0,0foriteminrange(count):x=round(__ease_out_expo(item/count)*distance)t=random.randint(10,20)ifx==_x:continuetracks.append([x-_x,_y,t])_x=xtracks.append([0,0,random.randint(200,300)])times=sum([track[2]fortrackintracks])returntracks,times三.结语本篇文章篇幅不长,主要也没啥好说的,验证码研究多了,识别和轨迹就那几套方法,换汤不换药函数a(e,t)中的重头戏:c.guid()、_.encrypt()、i.encrypt()、c.arrayToHex()四个函数我们放到浩瀚篇再说吧,不然我这紫极魔瞳四大境界变成三大境界了,哈哈哈
|
|