[RainBowText]二维码识别[/RainBowText]

import pyzbar.pyzbar as pyzbar
from PIL import Image,ImageEnhance

image = "139_00.png"
img = Image.open(image)
#img = ImageEnhance.Brightness(img).enhance(2.0)#增加亮度
#img = ImageEnhance.Sharpness(img).enhance(17.0)#锐利化
#img = ImageEnhance.Contrast(img).enhance(4.0)#增加对比度
#img = img.convert('L')#灰度化
img.show()
barcodes = pyzbar.decode(img)
for barcode in barcodes:
    barcodeData = barcode.data.decode("utf-8")
    print(barcodeData)

[RainBowText]验证码识别[/RainBowText]

import time
import muggle_ocr
import os
sdk = muggle_ocr.SDK(model_type=muggle_ocr.ModelType.OCR)
root_dir = r"./imgs"
for i in os.listdir(root_dir):
    n = os.path.join(root_dir, i)
    with open(n, "rb") as f:
        b = f.read()
    st = time.time()
    text = sdk.predict(image_bytes=b)
    print(i, text, time.time() - st)

[RainBowText]图片webp转jpg[/RainBowText]

import os
from PIL import Image
path = "1.webp"
im=Image.open(path)
im.load()
im.save("1.jpg")
os.remove(path)

[RainBowText]图片jpg转webp[/RainBowText]

#coding=utf-8
from PIL import Image
im = Image.open('3.jpeg').convert("RGB")
im.save("3.webp", "WEBP")

[RainBowText]python实现浏览器截图[/RainBowText]

from selenium import webdriver
import time

# 设置你自己的chormedriver存放路径,并把chromedriver.exe放到该路径下
driver_path = r"E:\Google\Chrome\Application\chromedriver.exe"
# 传入chromedriver路径
driver = webdriver.Chrome(executable_path=driver_path)
driver.maximize_window()
driver.implicitly_wait(10)
driver.get("https://ctf.bugku.com/login")
time.sleep(1)
erweima=driver.find_element_by_xpath('//*[@id="vcode"]')
# 指定元素截图
erweima.screenshot("55.png")

# # 整个浏览器截图
# driver.save_screenshot("3.png")
driver.close()

[RainBowText]读取某目录下的文件名[/RainBowText]

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
import os
def file_name(file_dir):
    for root, dirs, files in os.walk(file_dir):
        print(root)  # 当前目录路径
        print(dirs)  # 当前路径下所有子目录
        print(files)  # 当前路径下所有非目录子文件
file_name('./')
最后修改:2021 年 06 月 04 日 09 : 28 AM
如果觉得我的文章对你有用,请随意赞赏