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 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()
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.hasImage(): filename = tkFileDialog.asksaveasfilename( parent=self, filetypes=uiutils.supportedFiletypes, defaultextension=".png") if filename: self.imageCanvas.writeToFile(filename) self.setStatus('Saved screenshot to ' + filename) else: uiutils.error('Load image before taking a screenshot!')
def warpImage(self, *args): if self.image is not None: outImage = np.copy(self.image) focalLength = float(self.focalLengthSlider.get()) k1 = self.getK1() k2 = self.getK2() warpedImage = warp.warpSpherical(self.image, focalLength, \ k1, k2) self.setImage(warpedImage) self.setStatus('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.setStatus('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.setStatus('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.setStatus('Blending Images') self.setImage( blend.blendImages(ipv, int(self.blendWidthSlider.get()), self.is360Var.get() == 1)) self.setStatus('Panorama generated') else: uiutils.error('Select a folder with images before creating the ' + 'panorama!')