This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @staticmethod | |
| def normalizeNot(image): | |
| return image |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Use for testing ImageRecognizer Class | |
| if __name__ == "__main__": | |
| ImageClassifier.createDatabase("images", "number_db") | |
| imageClassifier = ImageClassifier("number_db") | |
| imageClassifier.openDatabase() | |
| print(imageClassifier) | |
| imageClassifier.normalizeDatabase(ImageClassifier.normalizeBinary) | |
| for number in range(10): | |
| print(imageClassifier.classifyImage("test" + str(number) +".jpg", ImageClassifier.normalizeBinary)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| max_confidence = sorted(confidence_dict.values(), reverse=True) | |
| for key, value in confidence_dict.items(): | |
| if value == max_confidence[0]: | |
| return key, min(round(((1.0/max_confidence[0])*max_confidence[1])*100,2), 100.00) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for i in range(10): | |
| confidence_dict[i] = 0 | |
| for number in range(len(self._database.keys())): | |
| for image in self._database[number]: | |
| for column in range(len(image)): | |
| for pixel in range(len(image[column])): | |
| if image[column][pixel] == test_image[column][pixel] == 1: | |
| confidence_dict[number] += 2 | |
| if image[column][pixel] == test_image[column][pixel] == 0: | |
| continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def classifyImage(self, img, normFunction): | |
| test_image = Image.open(img) | |
| test_image = np.array(test_image).tolist() | |
| test_image = normFunction(test_image) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def normalizeDatabase(self, normFunction): | |
| for number in range(len(self._database.keys())): | |
| for image in self._database[number]: | |
| image = normFunction(image) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @staticmethod | |
| def normalizeBinary(image): | |
| for column in image: | |
| for pixel in range(len(column)): | |
| total_color = 0 | |
| for color in column[pixel]: | |
| total_color += color | |
| if total_color/3 < 255/2: | |
| column[pixel] = 0 | |
| else: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def openDatabase(self): | |
| with open(self._databaseName+".pkl", "rb") as db: | |
| self._database = pickle.load(db) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if __name__ == "__main__": | |
| ImageClassifier.createDatabase("images", "number_db") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with open(databaseName + ".pkl", "wb") as db: | |
| pickle.dump(number_db,db) |
NewerOlder