网站开发都用什么浏览器,网站建设宗旨是指,建设银行网站修改,做网站运营需要学什么软件目前有个想法#xff0c;就是将UI截图与自动化截图进行对比。不一致的情况下提示错误截图对比方法有#xff1a;import cv2import numpy as np# 均值哈希算法def aHash(img):# 缩放为8*8img cv2.resize(img, (8, 8))# 转换为灰度图gray cv2.cvtColor(img, cv2.COLOR_BGR2GR…目前有个想法就是将UI截图与自动化截图进行对比。不一致的情况下提示错误截图对比方法有import cv2import numpy as np# 均值哈希算法def aHash(img):# 缩放为8*8img cv2.resize(img, (8, 8))# 转换为灰度图gray cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# s为像素和初值为0hash_str为hash值初值为s 0hash_str # 遍历累加求像素和for i in range(8):for j in range(8):s s gray[i, j]# 求平均灰度avg s / 64# 灰度大于平均值为1相反为0生成图片的hash值for i in range(8):for j in range(8):if gray[i, j] avg:hash_str hash_str 1else:hash_str hash_str 0return hash_str# 差值感知算法def dHash(img):# 缩放8*8img cv2.resize(img, (9, 8))# 转换灰度图gray cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)hash_str # 每行前一个像素大于后一个像素为1相反为0生成哈希for i in range(8):for j in range(8):if gray[i, j] gray[i, j 1]:hash_str hash_str 1else:hash_str hash_str 0return hash_str# 感知哈希算法(pHash)def pHash(img):# 缩放32*32img cv2.resize(img, (32, 32)) # , interpolationcv2.INTER_CUBIC# 转换为灰度图gray cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)# 将灰度图转为浮点型再进行dct变换dct cv2.dct(np.float32(gray))# opencv实现的掩码操作dct_roi dct[0:8, 0:8]hash []avreage np.mean(dct_roi)for i in range(dct_roi.shape[0]):for j in range(dct_roi.shape[1]):if dct_roi[i, j] avreage:hash.append(1)else:hash.append(0)return hash# 通过得到RGB每个通道的直方图来计算相似度def classify_hist_with_split(image1, image2, size(256, 256)):# 将图像resize后分离为RGB三个通道再计算每个通道的相似值image1 cv2.resize(image1, size)image2 cv2.resize(image2, size)sub_image1 cv2.split(image1)sub_image2 cv2.split(image2)sub_data 0for im1, im2 in zip(sub_image1, sub_image2):sub_data calculate(im1, im2)sub_data sub_data / 3return sub_data# 计算单通道的直方图的相似值def calculate(image1, image2):hist1 cv2.calcHist([image1], [0], None, [256], [0.0, 255.0])hist2 cv2.calcHist([image2], [0], None, [256], [0.0, 255.0])# 计算直方图的重合度degree 0for i in range(len(hist1)):if hist1[i] ! hist2[i]:degree degree (1 - abs(hist1[i] - hist2[i]) / max(hist1[i], hist2[i]))else:degree degree 1degree degree / len(hist1)return degree# Hash值对比def cmpHash(hash1, hash2):n 0# hash长度不同则返回-1代表传参出错if len(hash1)!len(hash2):return -1# 遍历判断for i in range(len(hash1)):# 不相等则n计数1n最终为相似度if hash1[i] ! hash2[i]:n n 1return nimg1 cv2.imread(openpic/x1y2.png) # 11--- 16 ----13 ---- 0.43img2 cv2.imread(openpic/x2y4.png)img1 cv2.imread(openpic/x3y5.png) # 10----11 ----8------0.25img2 cv2.imread(openpic/x9y1.png)img1 cv2.imread(openpic/x1y2.png) # 6------5 ----2--------0.84img2 cv2.imread(openpic/x2y6.png)img1 cv2.imread(openpic/t1.png) # 14------19---10--------0.70img2 cv2.imread(openpic/t2.png)img1 cv2.imread(openpic/t1.png) # 39------33---18--------0.58img2 cv2.imread(openpic/t3.png)hash1 aHash(img1)hash2 aHash(img2)n cmpHash(hash1, hash2)print(均值哈希算法相似度, n)hash1 dHash(img1)hash2 dHash(img2)n cmpHash(hash1, hash2)print(差值哈希算法相似度, n)hash1 pHash(img1)hash2 pHash(img2)n cmpHash(hash1, hash2)print(感知哈希算法相似度, n)n classify_hist_with_split(img1, img2)print(三直方图算法相似度, n)由于截图对比要求较高我选择差值哈希算法。具体截图代码如下对比代码结果