def getK2(self): k2 = DEFAULT_K2 try: k2 = float(self.k2Entry.get()) except: uiutils.error('You entered an invalid k2! Please try again.') return k2
def getK1(self): k1 = DEFAULT_K1 try: k1 = float(self.k1Entry.get()) except: uiutils.error('You entered an invalid k1! Please try again.') return k1
def getFocalLength(self): focalLength = 0 try: focalLength = float(self.focalLengthEntry.get()) if focalLength > 0: return focalLength except: pass uiutils.error('You entered an invalid focal length! Please try again.') return 0
def saveScreenshot(self): if self.imageCanvas.has_image(): filename = tkFileDialog.asksaveasfilename( parent=self, filetypes=uiutils.supportedFiletypes, defaultextension=".png") if filename: self.imageCanvas.write_to_file(filename) self.set_status('Saved screenshot to ' + filename) else: uiutils.error('Load image before taking a screenshot!')
def warpImage(self, *args): if self.image is not None: focalLength = float(self.focalLengthEntry.get()) k1 = self.getK1() k2 = self.getK2() warpedImage = warp.warpSpherical(self.image, focalLength, k1, k2) self.setImage(warpedImage) self.set_status('Warped image with focal length ' + str(focalLength)) elif len(args) == 0: # i.e., click on the button uiutils.error('Select an image before warping!')
def applyHomography(self): if self.image is not None: homography = uiutils.showMatrixDialog(self, text='Apply', rows=3, columns=3) if homography is not None: height, width, _ = self.image.shape self.setImage( cv2.warpPerspective(self.image, homography, (width, height))) self.set_status('Applied the homography.') else: uiutils.error('Select an image before applying a homography!')
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 alignImagesClick(self): if self.leftImage is None or self.rightImage is None: uiutils.error('Both the images must be selected for alignment to ' 'be possible!') else: self.compute()