Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jankais3r authored Aug 26, 2021
1 parent a271e1e commit db5abd9
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions generateHashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@

inputFolder = r'C:\images\to\be\hashed'

def generateHash(imageFile):
def generateHash(outputFolder, imageFile):
workerId = multiprocessing.current_process().name
with open(os.path.join(outputFolder, workerId + '.txt'), 'a', encoding = 'utf8') as outputFile:
result = subprocess.run([os.path.join(os.getcwd(), 'jPhotoDNA.exe') , os.path.join(os.getcwd(), 'PhotoDNAx64.dll'), imageFile], stdout = subprocess.PIPE)
fileName = result.stdout.decode('utf-8').split('|')[0]
hashString = result.stdout.decode('utf-8').split('|')[1].replace('\r\n', '')
result = subprocess.run([os.path.join(outputFolder, 'jPhotoDNA.exe'), os.path.join(outputFolder, 'PhotoDNAx64.dll'), imageFile], stdout = subprocess.PIPE)
fileName = result.stdout.decode('utf-8').split('|')[0]
hashString = result.stdout.decode('utf-8').split('|')[1].replace('\r\n', '')

hashList = hashString.split(',')
for i, hashPart in enumerate(hashList):
hashList[i] = int(hashPart).to_bytes((len(hashPart) + 7) // 8, 'big')
hashBytes = b''.join(hashList)
#print(fileName + ',' + base64.b64encode(hashBytes).decode('utf-8'))
with open(os.path.join(outputFolder, workerId + '.txt'), 'a', encoding = 'utf8') as outputFile:
outputFile.write(fileName + ',' + base64.b64encode(hashBytes).decode('utf-8') + '\n')
hashList = hashString.split(',')
for i, hashPart in enumerate(hashList):
hashList[i] = int(hashPart).to_bytes((len(hashPart) + 7) // 8, 'big')
hashBytes = b''.join(hashList)
#print(fileName + ',' + base64.b64encode(hashBytes).decode('utf-8'))

with open(os.path.join(outputFolder, workerId + '.txt'), 'a', encoding = 'utf8') as outputFile:
outputFile.write(fileName + ',' + base64.b64encode(hashBytes).decode('utf-8') + '\n')

if __name__ == '__main__':
outputFolder = os.getcwd()
Expand All @@ -44,7 +43,7 @@ def generateHash(imageFile):
images.extend(glob.glob(os.path.join(inputFolder, '**', '*.bmp'), recursive = True))
for f in images:
imageCount = imageCount + 1
p.apply_async(generateHash, [f])
p.apply_async(generateHash, [outputFolder, f])
p.close()
p.join()

Expand Down

0 comments on commit db5abd9

Please sign in to comment.