Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
#
img = Image.open(s1)
img = img.convert("RGB")
im=np.array(img)
cv2.imshow('src',im)
cv2.waitKey(0)
cv2.imwrite('captcha.jpg',im)
ocr = PyTessBaseAPI()
# ocr.Init(".", "eng", tesseract.OEM_DEFAULT)
ocr.SetVariable("tessedit_char_whitelist", "0123456789abcdefghijklmnopqrstuvwxyz")
# ocr.SetPageSegMode(tesseract.PSM_AUTO)
# ocr.SetImage(img)
print('验证码是',tesserocr.image_to_text(img))
#TODO 发送cookies
def ocr():
image=Image.open('captcha.jpg')
image=image.convert('L')
threshold=127
table=[]
for i in range(256):
if i
def video_segment_contains_text(video_segment):
"""
Checks if a video segment contains text
"""
first_frame_contains_text = False
last_frame_contains_text = False
first_frame = video_segment.get_frame(t='00:00:00')
last_frame = video_segment.get_frame(t=video_segment.duration)
#Check first frame
frame_image = Image.fromarray(first_frame)
text = tesserocr.image_to_text(frame_image)
if len(text.strip()) > 0:
first_frame_contains_text = True
#Check last frame
frame_image = Image.fromarray(last_frame)
text = tesserocr.image_to_text(frame_image)
if len(text.strip()) > 0:
last_frame_contains_text = True
return True if first_frame_contains_text or last_frame_contains_text else False
def _authcode_crack(self, raw):
from PIL import Image
import tesserocr
image = Image.open(raw)
image = image.convert('L')
threshold = 128
table = [0 if i < threshold else 1 for i in range(256)]
image = image.point(table, "1")
result = tesserocr.image_to_text(image)
result = result.strip().replace(' ', '')
return result
def handle_code(image):
"""
处理验证码
:param image: Image对象
:return:
"""
image = image.convert("L") # 灰度处理
threshold = 120 # 设置阈值为120(可灵活配置)
table = []
for i in range(256): #
if i < threshold:
table.append(0)
else:
table.append(1)
image = image.point(table, '1') # 二值化处理
result_1 = tesserocr.image_to_text(image).strip() # 使用tesserocr获取处理结果
result_2 = pytesseract.image_to_string(image).strip() # 使用pytesseract获取处理结果
# print('验证码为:', result_1)
return result_1, result_2
#利用Image对象的convert()方法参数传入L,转化为灰度图像
image = image.convert("L")
#进行二值化
#阈值127
threshold = 127
table = []
for i in range(256):
if i < threshold:
table.append(0)
else:
table.append(1)
image = image.point(table,'1')
image.show()
print (2)
result = tesserocr.image_to_text(image)
print(result)
print (1)