def compute(self, *args): if self.images is not None and len(self.images) > 0: f = self.getFocalLength() if f <= 0: return k1 = self.getK1() k2 = self.getK2() processedImages = None if self.motionModelVar.get() == alignment.eTranslate: processedImages = [ warp.warpSpherical(i, f, k1, k2) for i in self.images ] else: processedImages = self.images t = np.eye(3) ipv = [] for i in range(0, len(processedImages) - 1): self.set_status( 'Computing mapping from {0} to {1}'.format(i, i+1) ) ipv.append( blend.ImageInfo('', processedImages[i], np.linalg.inv(t)) ) t = self.computeMapping( processedImages[i], processedImages[i+1] ).dot(t) ipv.append(blend.ImageInfo( '', processedImages[len(processedImages)-1], np.linalg.inv(t)) ) t = self.computeMapping( processedImages[len(processedImages)-1], processedImages[0] ).dot(t) if self.is360Var.get(): ipv.append(blend.ImageInfo( '', processedImages[0], np.linalg.inv(t)) ) self.set_status('Blending Images') self.setImage(blend.blendImages( ipv, int(self.blendWidthSlider.get()), self.is360Var.get() == 1 )) self.set_status('Panorama generated') else: uiutils.error( 'Select a folder with images before creating the panorama!' )
def test_getAccSize(self): '''Tests TODO 9''' ipv = [blend.ImageInfo("test1",self.testimage,self.rot_trans_transform1), blend.ImageInfo("test2",self.testimage,self.rot_trans_transform2)] accWidth, accHeight, channels, width, translation = blend.getAccSize(ipv) self.assertAlmostEqual(accWidth, 20, msg='Expected acc width to be {} +/-1 but got {}.'.format(20, accWidth), delta=1.01, ) self.assertAlmostEqual(accHeight, 20, msg='Expected acc height to be {} +/-1 but got {}.'.format(20, accHeight), delta=1.01, )
def pano(set_n, use_algorithm): name_of_set = "ep" + str(set_n) name_of_path0 = "data/" + name_of_set #+ "SIFT" + "_set_Lunch/" if use_algorithm == "SIFT": scale_percent = 30 elif use_algorithm == "SURF": scale_percent = 20 elif use_algorithm == "ORB": scale_percent = 10 scale_percent = 20 w_p = 200 name_of_final = use_algorithm + "_" + name_of_set focalLength = 2500 k1 = -0.0484573 k2 = 0.0100024 f = focalLength start_time = timeit.default_timer() name_of_path = name_of_path0 iter = 1 processedImages = None point_time_1 = timeit.default_timer() files = os.listdir(name_of_path0) images = [cv2.imread(os.path.join(name_of_path0, i)) for i in files] images_crop = [] for i in images: # calculate the 50 percent of original dimensions width = int(i.shape[1] * scale_percent / 100) height = int(i.shape[0] * scale_percent / 100) # dsize dsize = (width, height) # resize image images_crop.append(cv2.resize(i, dsize)) #images_crop.append(i) point_time_2 = timeit.default_timer() processedImages = [warp.warpSpherical(i, f, k1, k2) for i in images_crop] #processedImages = images_crop t = np.eye(3) ipv = [] for i in range(0, len(processedImages) - 1): ipv.append(blend.ImageInfo('', processedImages[i], np.linalg.inv(t))) t = computeMapping(processedImages[i], processedImages[i + 1]).dot(t) ipv.append( blend.ImageInfo('', processedImages[len(processedImages) - 1], np.linalg.inv(t))) t = computeMapping(processedImages[len(processedImages) - 1], processedImages[0]).dot(t) result = blend.blendImages(ipv, int(w_p), False) #cv2.imwrite("result_" + name_of_final + ".jpg", result) stop_time = timeit.default_timer() height = result.shape[0] width = result.shape[1] filtr_res = contraharmonic_mean(result, (height, width), 0.5) #cv2.imwrite("result_" + name_of_final + "_f.jpg", result) # Create our shapening kernel, it must equal to one eventually kernel_sharpening = np.array([[-1, -1, -1], [-1, 9, -1], [-1, -1, -1]]) # applying the sharpening kernel to the input image & displaying it. sharpened = cv2.filter2D(result, -1, kernel_sharpening) #cv2.imwrite("result_" + name_of_final + "_s.jpg", sharpened) median = result #cv2.medianBlur(result, 3) #median = cv2.medianBlur(median, 3) #cv2.imwrite("result_" + name_of_final + "_m.jpg", median) sharpenedmedian = cv2.filter2D(median, -1, kernel_sharpening) cv2.imwrite("result_" + name_of_final + "_SM.jpg", sharpenedmedian) #seam_carving.main_seam("result_" + name_of_final + "_SM.jpg", "result_" + name_of_final + "_SM_SEAM.jpg") resave = cv2.imread("result_" + name_of_final + "_SM.jpg") cv2.imwrite("it3/result_" + name_of_final + ".jpg", resave) print('Execution time ' + name_of_set + ' ' + use_algorithm + ': ', stop_time - start_time)