FileWriter fstream = new FileWriter("E:/test001/code.txt");//定义本地文件路径
BufferedWriter out = new BufferedWriter(fstream);
out.write("${image}");// 验证码base64变量名
out.write(System.getProperty("line.separator"));//换行
out.close();
fstream.close();
import java.io.BufferedReader;
import java.io.InputStreamReader;
String command = "cmd /c python E://D-drive-26093//pycharm//test01//venv//testA.py ";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);
pr.waitFor();
BufferedReader b = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = "";
StringBuilder response = new StringBuilder();
while ((line = b.readLine()) != null) {
response.append(line);
}
String response_data = response.toString();
System.out.println(response_data);
b.close();
//System.out.println(response.toString());
vars.put("code",response.toString()); //把结果赋值给变量 TEST ,方便后面调用
from PIL import Image
import re
import pytesseract
import os, base64
import numpy as np
import time
import matplotlib.pyplot as plt
import ddddocr
# 对base64图片解码
with open("E:\\test001\\code.txt", "r") as f:
imgdata = base64.b64decode(f.read())
filea = open('E:\\test001\\1.jpg', 'wb')
filea.write(imgdata)
filea.close()
# 验证码降噪
image = Image.open('E:\\test001\\1.jpg','r')
image = image.convert('L')
image = np.asarray(image)
image = (image > 135) * 255
image = Image.fromarray(image).convert('RGB')
image.save('E:\\test001\\12345.jpg')
time.sleep(2)
# 识别验证码图片文字
ocr = ddddocr.DdddOcr()
with open('E:\\test001\\12345.jpg', 'rb') as f:
img_bytes = f.read()
res = ocr.classification(img_bytes)
file = open('E:\\test001\\001test.txt', mode='w')
file.writelines(res)
print (res)
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |