Unverified Commit 07bea5c1 authored by Kiryuu's avatar Kiryuu
Browse files

Finally finish this series

parent 0f0b0699
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
\ No newline at end of file
GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]
\ No newline at end of file
These data were extracted from the GADM database (www.gadm.org), version 3.4, April 2018. They can be used for non-commercial purposes only. It is not allowed to redistribute these data, or use them for commercial purposes, without prior consent. See the website (www.gadm.org) for more information.
\ No newline at end of file
import test
import numpy as np
from PIL import Image
def getDiff(width, high, image): # 将要裁剪成w*h的image照片
diff = []
im = image.resize((width, high))
imgray = im.convert('L') # 转换为灰度图片 便于处理
pixels = list(imgray.getdata()) # 得到像素数据 灰度0-255
for row in range(high): # 逐一与它左边的像素点进行比较
rowStart = row * width # 起始位置行号
for index in range(width - 1):
leftIndex = rowStart + index
rightIndex = leftIndex + 1 # 左右位置号
diff.append(pixels[leftIndex] > pixels[rightIndex])
return diff # *得到差异值序列 这里可以转换为hash码*
def getHamming(diff, diff2): # 暴力计算两点间汉明距离
hamming_distance = 0
for i in range(len(diff)):
if diff[i] != diff2[i]:
hamming_distance += 1
return hamming_distance
if __name__ == '__main__':
file_path="Task3/TT.png"
np.random.seed(45678)
x=np.random.randint(300,800,50)
y = np.random.randint(350, 652, 50)
test.student(file_path,x,y)
hash1 = Image.open("Task3/img/T1.png")
hash2 = Image.open("Task3/img1/T2.png")
diff1 = getDiff(32, 32, hash1)
diff2 = getDiff(32, 32, hash2)
ans = getHamming(diff1, diff2)
if ans < 1:
print("生成图片与预期图片一致")
else:
print("生成图片与预期图片不一致")
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import numpy as np
from numpy import *
def student(img_path,x,y):
# ********* Begin *********#
# ********* End *********#
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment