ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/ns_dev/Python/NinoCode/Active_prgs/Document_Oculus.py
Revision: 667
Committed: Thu Dec 12 21:20:38 2019 UTC (6 years, 3 months ago) by nino.borges
Content type: text/x-python
File size: 1971 byte(s)
Log Message:
Program to help in detection of near duplicates in paper world

File Contents

# Content
1 """
2
3 Document Oculus
4
5 Created by
6 Emanuel Borges
7 02.21.2015
8
9 This program will help in the detection of near duplicates in the paper world.
10
11 """
12 import os, shelve
13 from PIL import Image
14
15 def CreateNewMatrix(imagesPath):
16 matrix = {}
17 for root, dirs,files in os.walk(imagesPath):
18 for name in files:
19 if os.path.splitext(name)[1] == '.tif':
20 image = Image.open(os.path.join(root,name))
21 h = str(imagehash.dhash(image))
22 if h in matrix.keys():
23 matrix[h].append(os.path.join(root,name))
24 else:
25 matrix[h] = [os.path.join(root,name),]
26
27 print "there are %s groups"% str(len(matrix.keys()))
28 return Matrix
29
30 def GetMatrixFromShelve(shelvePath):
31 matrix = shelve.open(shelvePath)
32 ## Dont forget to close the file matrix
33 return matrix
34
35 def SaveMatrixToShelve(shelvePath,matrix):
36 s = shelve.open(shelvePath)
37 s.update(matrix)
38 s.close()
39
40
41 if __name__ == '__main__':
42 matrix = {}
43 imagesPath = r'C:\Test\imageTest'
44
45
46
47 for root, dirs,files in os.walk(imagesPath):
48 for name in files:
49 if os.path.splitext(name)[1] == '.tif':
50 image = Image.open(os.path.join(root,name))
51 h = str(imagehash.dhash(image))
52 if h in matrix.keys():
53 matrix[h].append(os.path.join(root,name))
54 else:
55 matrix[h] = [os.path.join(root,name),]
56
57 print "there are %s groups"% str(len(matrix.keys()))
58
59 testList = []
60 for i in matrix.keys():
61 if len(matrix[i]) > 1:
62 testList.append(i)
63
64 print "There are %s groups of 2 or more"% str(len(testList))
65
66 highNo= 1
67 for i in matrix.keys():
68 if len(matrix[i]) > highNo:
69 highNo = len(matrix[i])
70
71 print "The highest group is %s."% str(highNo)
72