def test_compare_color_diff(self): imgA = open_img("./testImage/TestOrig.jpg") imgB = open_img("./testImage/TestImage.png") imgA_avg = blockify(imgA) imgB_avg = blockify(imgB) result = diff(imgA_avg, imgB_avg) self.assertNotEqual(result, 1)
def test_compare_grey_similar(self): imgA = open_img(u"./testImage/[クール教信者] 小林さんちのメイドラゴン 01_pg4.jpg") imgB = open_img(u"./testImage/[クール教信者] 小林さんちのメイドラゴン 01_pg4_eng.jpg") imgA_avg = blockify(imgA) imgB_avg = blockify(imgB) result = diff(imgA_avg, imgB_avg) self.assertNotEqual(result, 1) self.assertGreater(result, .95)
def test_compare_color_similar(self): imgA = open_img("./testImage/TestOrig.jpg") imgB = open_img("./testImage/TestSimilar.jpg") imgA_avg = blockify(imgA) imgB_avg = blockify(imgB) result = diff(imgA_avg, imgB_avg) self.assertNotEqual(result, 1) self.assertGreater(result, .85)
def __eval_image(self, block_list): """ evaluate differences between each image to another If evaluation result is higher or equal to desired percentage, it is a match Parameter --------- block_list - list of Tuple of image path and its averaged blocks Returns --------- A list of tuples of matching image with its maching image in a form of (imageA, imageB, result in int)""" compare_result = [] block_list_len = len(block_list) if block_list_len < 4: next_not_touch_index = 1 for imageA in block_list: for index in range(next_not_touch_index, block_list_len): imageB = block_list[index] result = float(block.diff(imageA[1], imageB[1])) if result >= self.fuzzy_percentage: result = "%.2f" % result compare_result.append((imageA[0], imageB[0], result)) # to prevent images of being compare to itself and already # compared images in previous loops next_not_touch_index += 1 else: jobs = [] procs = 4 queue = Queue() block_split = self.__split_list(block_list, 2) # prepare processes # The first part of the split image list will be compared to the first part and second # part with two processes # the second part work in the same way for i in range(procs): index = i % 2 process = Process(target=self.__eval_image_process, args=(block_split[i // 2], block_split[i % 2], queue)) jobs.append(process) # start process and wait for processes to end for j in jobs: j.start() for j in jobs: compare_result.extend(queue.get()) for j in jobs: j.join() return compare_result
def __eval_image_process(self, from_list, compare_list, queue): """ single process loop for evaluating image matches""" result_list = [] for imageA in from_list: for imageB in compare_list: if imageA[0] is not imageB[0]: result = float(block.diff(imageA[1], imageB[1])) if result >= self.fuzzy_percentage: result = "%.2f" % result result_list.append((imageA[0], imageB[0], result)) queue.put(result_list)