예제 #1
0
 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
예제 #2
0
 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
예제 #3
0
 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()
예제 #4
0
 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
예제 #5
0
 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!')
예제 #6
0
    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!'
            )
예제 #7
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!')
예제 #8
0
 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!')
예제 #9
0
    def get_mapping(self):
        if not (self.left_image_widget.has_image()
                and self.right_image_widget.has_image()):
            return None
        left = self.left_image_widget.get_clicked_points_in_image_coordinates()
        right = self.right_image_widget.get_clicked_points_in_image_coordinates(
        )
        num_points = min(len(left), len(right))
        if num_points != 3:
            uiutils.error(
                'Please click on at exactly three corresponding points.')
            return None
        left = left[:num_points]
        right = right[:num_points]
        left = np.array([[x, y] for y, x in left], np.float32)
        right = np.array([[x, y] for y, x in right], np.float32)

        at = cv2.getAffineTransform(right, left)
        return at
예제 #10
0
파일: gui.py 프로젝트: danielkcasey/Hybrid
    def get_mapping(self):
        if not (self.left_image_widget.has_image() and
                    self.right_image_widget.has_image()):
            return None
        left = self.left_image_widget.get_clicked_points_in_image_coordinates()
        right = self.right_image_widget.get_clicked_points_in_image_coordinates(
        )
        num_points = min(len(left), len(right))
        if num_points != 3:
            uiutils.error(
                'Please click on at exactly three corresponding points.')
            return None
        left = left[:num_points]
        right = right[:num_points]
        left = np.array([[x, y] for y, x in left], np.float32)
        right = np.array([[x, y] for y, x in right], np.float32)

        at = cv2.getAffineTransform(right, left)
        return at