From 3f921bdd3de93abf4a044b24c9947fa0ebfc306c Mon Sep 17 00:00:00 2001 From: yanchunhuo Date: Wed, 26 Feb 2020 11:30:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=9B=BE=E7=89=87=E7=9B=B8?= =?UTF-8?q?=E4=BC=BC=E5=BA=A6=E6=AF=94=E8=BE=83=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/image/__init__.py | 3 +++ common/image/imageCompare.py | 35 +++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 40 insertions(+) create mode 100644 common/image/__init__.py create mode 100644 common/image/imageCompare.py diff --git a/common/image/__init__.py b/common/image/__init__.py new file mode 100644 index 0000000..b9cdc7a --- /dev/null +++ b/common/image/__init__.py @@ -0,0 +1,3 @@ +# 作者 yanchunhuo +# 创建时间 2020/2/26 10:00 +# github https://github.com/yanchunhuo \ No newline at end of file diff --git a/common/image/imageCompare.py b/common/image/imageCompare.py new file mode 100644 index 0000000..3765362 --- /dev/null +++ b/common/image/imageCompare.py @@ -0,0 +1,35 @@ +# 作者 yanchunhuo +# 创建时间 2020/2/26 10:00 +# github https://github.com/yanchunhuo +from skimage.metrics import structural_similarity +import cv2 + +class ImageCompare: + @classmethod + def compareTwoImage(cls,image1_path,image2_path,zoom_type='in'): + """ + 比较两张图片相识度,返回值范围为0~1,提供比较的两张图片尺寸应该一致,如果不一致会进行缩放 + :param image1_path: + :param image2_path: + :param zoom_type: in:放大,out:缩小,当图片尺寸一致时,该参数被忽略 + :return: + """ + image1=cv2.imread(image1_path) + image2=cv2.imread(image2_path) + height1,width1,channel1=image1.shape + height2,width2,channel2=image2.shape + if not height1==height2 and not width1==width2: + height=0 + width=0 + if zoom_type.lower()=='in': + height=max(height1,height2) + width=max(width1,width2) + elif zoom_type.lower()=='out': + height=min(height1,height2) + width=min(width1,width2) + image1 = cv2.resize(image1, (height, width)) + image2 = cv2.resize(image2, (height, width)) + image1_gray=cv2.cvtColor(image1,cv2.COLOR_BGR2GRAY) + image2_gray=cv2.cvtColor(image2,cv2.COLOR_BGR2GRAY) + score,diff=structural_similarity(image1_gray,image2_gray,full=True) + return score \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index a96cb90..167b762 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,6 +10,8 @@ cx_Oracle==6.3.1 JPype1==0.6.3 paramiko==2.4.0 Pillow==5.3.0 +scikit-image==0.16.2 +opencv-python==4.2.0.32 PyMySQL==0.8.0 redis==2.10.6 ujson==1.35