|
@@ -1,24 +1,28 @@
|
|
from UI.rename_pic import Ui_Form as rename_pic_Ui_Form
|
|
from UI.rename_pic import Ui_Form as rename_pic_Ui_Form
|
|
from PySide6.QtWidgets import *
|
|
from PySide6.QtWidgets import *
|
|
from PySide6.QtCore import *
|
|
from PySide6.QtCore import *
|
|
|
|
+
|
|
# from collections import defaultdict
|
|
# from collections import defaultdict
|
|
import os
|
|
import os
|
|
import log
|
|
import log
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
import time
|
|
import time
|
|
import settings
|
|
import settings
|
|
|
|
+
|
|
# from pyzbar.pyzbar import decode
|
|
# from pyzbar.pyzbar import decode
|
|
import shutil
|
|
import shutil
|
|
from cv2 import cvtColor, COLOR_RGB2BGR
|
|
from cv2 import cvtColor, COLOR_RGB2BGR
|
|
|
|
+
|
|
# cv2.cvtColor(np.asarray(im), cv2.COLOR_RGB2BGR)
|
|
# cv2.cvtColor(np.asarray(im), cv2.COLOR_RGB2BGR)
|
|
import numpy as np
|
|
import numpy as np
|
|
from cv2.wechat_qrcode import WeChatQRCode
|
|
from cv2.wechat_qrcode import WeChatQRCode
|
|
from module.module_online_data import GetOnlineData
|
|
from module.module_online_data import GetOnlineData
|
|
-
|
|
|
|
|
|
+from MineQWidget import MineQWidget
|
|
|
|
|
|
# pip install opencv-python -i https://pypi.douban.com/simple
|
|
# pip install opencv-python -i https://pypi.douban.com/simple
|
|
# pip install opencv-contrib-python -i https://pypi.douban.com/simple
|
|
# pip install opencv-contrib-python -i https://pypi.douban.com/simple
|
|
|
|
|
|
|
|
+
|
|
class Picture:
|
|
class Picture:
|
|
def __init__(self, in_path):
|
|
def __init__(self, in_path):
|
|
self.im = Image.open(in_path)
|
|
self.im = Image.open(in_path)
|
|
@@ -41,10 +45,12 @@ class Picture:
|
|
def corp_square(self):
|
|
def corp_square(self):
|
|
if self.y < self.x:
|
|
if self.y < self.x:
|
|
return
|
|
return
|
|
- self.im = self.im.crop((0, int((self.y - self.x) / 2), self.x, self.y - int((self.y - self.x) / 2)))
|
|
|
|
|
|
+ self.im = self.im.crop(
|
|
|
|
+ (0, int((self.y - self.x) / 2), self.x, self.y - int((self.y - self.x) / 2))
|
|
|
|
+ )
|
|
|
|
|
|
|
|
|
|
-class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
|
|
|
|
+class RenamePic(MineQWidget, rename_pic_Ui_Form):
|
|
progress_sign = Signal(dict)
|
|
progress_sign = Signal(dict)
|
|
info_sign = Signal(str)
|
|
info_sign = Signal(str)
|
|
text_show = Signal(str)
|
|
text_show = Signal(str)
|
|
@@ -60,13 +66,7 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
self.setFixedSize(self.width(), self.height())
|
|
self.setFixedSize(self.width(), self.height())
|
|
self.set_state(2)
|
|
self.set_state(2)
|
|
self.show()
|
|
self.show()
|
|
- QTimer.singleShot(500, self.check_login)
|
|
|
|
-
|
|
|
|
- def check_login(self, *args):
|
|
|
|
- if not settings.IsLogin:
|
|
|
|
- a = QMessageBox.question(self, '确认', '请先登录',
|
|
|
|
- QMessageBox.Yes)
|
|
|
|
- self.close()
|
|
|
|
|
|
+ QTimer.singleShot(500, self.checkLogin)
|
|
|
|
|
|
def init(self):
|
|
def init(self):
|
|
self.text_show.connect(self.append_text_to_browser)
|
|
self.text_show.connect(self.append_text_to_browser)
|
|
@@ -81,7 +81,7 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
|
|
|
|
def get_len_text(self, text, max_len: int):
|
|
def get_len_text(self, text, max_len: int):
|
|
if len(text) > max_len:
|
|
if len(text) > max_len:
|
|
- text = text[:int(max_len / 4)] + "..." + text[-1 * int(max_len * 3 / 4):]
|
|
|
|
|
|
+ text = text[: int(max_len / 4)] + "..." + text[-1 * int(max_len * 3 / 4) :]
|
|
return text
|
|
return text
|
|
|
|
|
|
def select_pic_dir(self, *args):
|
|
def select_pic_dir(self, *args):
|
|
@@ -118,11 +118,9 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
|
|
|
|
def run(self):
|
|
def run(self):
|
|
# 基础检查
|
|
# 基础检查
|
|
- if not settings.IsLogin:
|
|
|
|
- a = QMessageBox.question(self, '确认', '请先登录',
|
|
|
|
- QMessageBox.Yes)
|
|
|
|
|
|
+ checkRes = self.checkLogin()
|
|
|
|
+ if checkRes == False:
|
|
return
|
|
return
|
|
-
|
|
|
|
self.set_state(1)
|
|
self.set_state(1)
|
|
if not self.pic_dir:
|
|
if not self.pic_dir:
|
|
self.text_show.emit("请选择图片文件夹")
|
|
self.text_show.emit("请选择图片文件夹")
|
|
@@ -133,7 +131,7 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
self.set_state(2)
|
|
self.set_state(2)
|
|
return
|
|
return
|
|
total = 0
|
|
total = 0
|
|
- _Type = ['.png', '.PNG', '.jpg', '.JPG', '.gif', '.GIF', '.jpeg', '.JPEG']
|
|
|
|
|
|
+ _Type = [".png", ".PNG", ".jpg", ".JPG", ".gif", ".GIF", ".jpeg", ".JPEG"]
|
|
for image_file in os.listdir(self.pic_dir):
|
|
for image_file in os.listdir(self.pic_dir):
|
|
path = "{}\{}".format(self.pic_dir, image_file)
|
|
path = "{}\{}".format(self.pic_dir, image_file)
|
|
if os.path.isfile(path):
|
|
if os.path.isfile(path):
|
|
@@ -158,7 +156,9 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
|
|
|
|
def run_deal(self, total, is_add_text=False):
|
|
def run_deal(self, total, is_add_text=False):
|
|
# 输出目录
|
|
# 输出目录
|
|
- out_put_path = "{}\out_put_{}".format(os.path.split(self.pic_dir)[0], int(time.time()))
|
|
|
|
|
|
+ out_put_path = "{}\out_put_{}".format(
|
|
|
|
+ os.path.split(self.pic_dir)[0], int(time.time())
|
|
|
|
+ )
|
|
# 无法识别的目录
|
|
# 无法识别的目录
|
|
error_path = "{}\识别失败".format(out_put_path)
|
|
error_path = "{}\识别失败".format(out_put_path)
|
|
# 识别成功的目录
|
|
# 识别成功的目录
|
|
@@ -169,28 +169,35 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
self.check_path(success_path)
|
|
self.check_path(success_path)
|
|
|
|
|
|
error_list = []
|
|
error_list = []
|
|
- _Type = ['.png', '.PNG', '.jpg', '.JPG', '.gif', '.GIF', '.jpeg', '.JPEG']
|
|
|
|
|
|
+ _Type = [".png", ".PNG", ".jpg", ".JPG", ".gif", ".GIF", ".jpeg", ".JPEG"]
|
|
last_code = None
|
|
last_code = None
|
|
do_n = 0
|
|
do_n = 0
|
|
for image_file in os.listdir(self.pic_dir):
|
|
for image_file in os.listdir(self.pic_dir):
|
|
if os.path.splitext(image_file)[1] in _Type:
|
|
if os.path.splitext(image_file)[1] in _Type:
|
|
# 获取当前路径的文件夹名称
|
|
# 获取当前路径的文件夹名称
|
|
file_path = "{}/{}".format(self.pic_dir, image_file)
|
|
file_path = "{}/{}".format(self.pic_dir, image_file)
|
|
- self.send_info({"_type": "text",
|
|
|
|
- "data": "{}图片解析".format(image_file)})
|
|
|
|
|
|
+ self.send_info(
|
|
|
|
+ {"_type": "text", "data": "{}图片解析".format(image_file)}
|
|
|
|
+ )
|
|
code = self.get_code(file_path)
|
|
code = self.get_code(file_path)
|
|
|
|
|
|
if code:
|
|
if code:
|
|
if "_" in code:
|
|
if "_" in code:
|
|
goods_number = code.split("_")[0]
|
|
goods_number = code.split("_")[0]
|
|
numbers_list = [goods_number]
|
|
numbers_list = [goods_number]
|
|
- r_data = GetOnlineData().get_goods_art_no_info(numbers_list=numbers_list)
|
|
|
|
|
|
+ r_data = GetOnlineData().get_goods_art_no_info(
|
|
|
|
+ numbers_list=numbers_list
|
|
|
|
+ )
|
|
if goods_number in r_data:
|
|
if goods_number in r_data:
|
|
code = r_data[goods_number]["商品货号"]
|
|
code = r_data[goods_number]["商品货号"]
|
|
else:
|
|
else:
|
|
code = None
|
|
code = None
|
|
- self.send_info({"_type": "text",
|
|
|
|
- "data": "{}查询不到商品".format(goods_number)})
|
|
|
|
|
|
+ self.send_info(
|
|
|
|
+ {
|
|
|
|
+ "_type": "text",
|
|
|
|
+ "data": "{}查询不到商品".format(goods_number),
|
|
|
|
+ }
|
|
|
|
+ )
|
|
|
|
|
|
if code:
|
|
if code:
|
|
# 获取到二维码内容,说明是二维码图片,则不做处理
|
|
# 获取到二维码内容,说明是二维码图片,则不做处理
|
|
@@ -200,18 +207,27 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
# 上个二维码没有解析成功
|
|
# 上个二维码没有解析成功
|
|
if not last_code:
|
|
if not last_code:
|
|
error_list.append(image_file)
|
|
error_list.append(image_file)
|
|
- self.send_info({"_type": "text",
|
|
|
|
- "data": "{}无法识别".format(image_file)})
|
|
|
|
- shutil.copyfile(file_path, "{}\{}".format(error_path, image_file))
|
|
|
|
|
|
+ self.send_info(
|
|
|
|
+ {"_type": "text", "data": "{}无法识别".format(image_file)}
|
|
|
|
+ )
|
|
|
|
+ shutil.copyfile(
|
|
|
|
+ file_path, "{}\{}".format(error_path, image_file)
|
|
|
|
+ )
|
|
#
|
|
#
|
|
if last_code:
|
|
if last_code:
|
|
print("{}--------".format(last_code))
|
|
print("{}--------".format(last_code))
|
|
# 目标文件路径
|
|
# 目标文件路径
|
|
- _file_name = "{}{}".format(last_code, os.path.splitext(image_file)[1])
|
|
|
|
|
|
+ _file_name = "{}{}".format(
|
|
|
|
+ last_code, os.path.splitext(image_file)[1]
|
|
|
|
+ )
|
|
dst_file = "{}/{}".format(success_path, _file_name)
|
|
dst_file = "{}/{}".format(success_path, _file_name)
|
|
if os.path.exists(dst_file):
|
|
if os.path.exists(dst_file):
|
|
- self.send_info({"_type": "text",
|
|
|
|
- "data": "{}图片已存在".format(image_file)})
|
|
|
|
|
|
+ self.send_info(
|
|
|
|
+ {
|
|
|
|
+ "_type": "text",
|
|
|
|
+ "data": "{}图片已存在".format(image_file),
|
|
|
|
+ }
|
|
|
|
+ )
|
|
last_code = None
|
|
last_code = None
|
|
continue
|
|
continue
|
|
shutil.copy(file_path, dst_file) # 复制文件
|
|
shutil.copy(file_path, dst_file) # 复制文件
|
|
@@ -220,20 +236,19 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
pic.corp_square() # 居中剪裁
|
|
pic.corp_square() # 居中剪裁
|
|
if is_add_text:
|
|
if is_add_text:
|
|
draw = ImageDraw.Draw(pic.im)
|
|
draw = ImageDraw.Draw(pic.im)
|
|
- font_style_1 = ImageFont.truetype(r"ttf\simfang.ttf", 40, encoding="utf-8")
|
|
|
|
|
|
+ font_style_1 = ImageFont.truetype(
|
|
|
|
+ r"ttf\simfang.ttf", 40, encoding="utf-8"
|
|
|
|
+ )
|
|
draw.text((0, 0), last_code, 0, font=font_style_1)
|
|
draw.text((0, 0), last_code, 0, font=font_style_1)
|
|
pic.save_img(dst_file)
|
|
pic.save_img(dst_file)
|
|
# 处理成功了,清空上个记录
|
|
# 处理成功了,清空上个记录
|
|
last_code = None
|
|
last_code = None
|
|
|
|
|
|
do_n += 1
|
|
do_n += 1
|
|
- self.send_info({"_type": "show_p",
|
|
|
|
- "data": int(do_n / total * 100)})
|
|
|
|
|
|
+ self.send_info({"_type": "show_p", "data": int(do_n / total * 100)})
|
|
if error_list:
|
|
if error_list:
|
|
- self.send_info({"_type": "text",
|
|
|
|
- "data": "以下图片无法解析,请自行处理"})
|
|
|
|
- self.send_info({"_type": "text",
|
|
|
|
- "data": "{}".format(error_list)})
|
|
|
|
|
|
+ self.send_info({"_type": "text", "data": "以下图片无法解析,请自行处理"})
|
|
|
|
+ self.send_info({"_type": "text", "data": "{}".format(error_list)})
|
|
|
|
|
|
os.startfile(out_put_path)
|
|
os.startfile(out_put_path)
|
|
|
|
|
|
@@ -251,17 +266,24 @@ class RenamePic(QWidget, rename_pic_Ui_Form):
|
|
im = pic.im
|
|
im = pic.im
|
|
img = cvtColor(np.asarray(im), COLOR_RGB2BGR)
|
|
img = cvtColor(np.asarray(im), COLOR_RGB2BGR)
|
|
# path = r"D:\MyDocuments\PythonCode\MyPython\red_dragonfly\deal_pics\rename_by_qrcode\opencv_3rdparty-wechat_qrcode"
|
|
# path = r"D:\MyDocuments\PythonCode\MyPython\red_dragonfly\deal_pics\rename_by_qrcode\opencv_3rdparty-wechat_qrcode"
|
|
- detector = WeChatQRCode(detector_prototxt_path="qr_mode/detect.prototxt",
|
|
|
|
- detector_caffe_model_path="qr_mode/detect.caffemodel",
|
|
|
|
- super_resolution_prototxt_path="qr_mode/sr.prototxt",
|
|
|
|
- super_resolution_caffe_model_path="qr_mode/sr.caffemodel")
|
|
|
|
|
|
+ detector = WeChatQRCode(
|
|
|
|
+ detector_prototxt_path="qr_mode/detect.prototxt",
|
|
|
|
+ detector_caffe_model_path="qr_mode/detect.caffemodel",
|
|
|
|
+ super_resolution_prototxt_path="qr_mode/sr.prototxt",
|
|
|
|
+ super_resolution_caffe_model_path="qr_mode/sr.caffemodel",
|
|
|
|
+ )
|
|
|
|
|
|
res, points = detector.detectAndDecode(img)
|
|
res, points = detector.detectAndDecode(img)
|
|
if res:
|
|
if res:
|
|
return res[0]
|
|
return res[0]
|
|
return None
|
|
return None
|
|
|
|
|
|
- def deal_pic_resize(self, file_path, target_size, times=0, ):
|
|
|
|
|
|
+ def deal_pic_resize(
|
|
|
|
+ self,
|
|
|
|
+ file_path,
|
|
|
|
+ target_size,
|
|
|
|
+ times=0,
|
|
|
|
+ ):
|
|
file_size = int(os.path.getsize(file_path) / 1024)
|
|
file_size = int(os.path.getsize(file_path) / 1024)
|
|
if file_size < target_size:
|
|
if file_size < target_size:
|
|
return
|
|
return
|