Example #1
0
    def __Augmentation(self):
        """Projects an augmentation object over the chessboard pattern."""
        # Load the camera.
        cameraID = 0
        SIGBTools.VideoCapture(cameraID,
                               SIGBTools.CAMERA_VIDEOCAPTURE_640X480_30FPS)

        # Read each frame from input camera.
        while True:
            # Read the current image from the camera.
            image = SIGBTools.read()

            # Finds the positions of internal corners of the chessboard.
            corners = SIGBTools.FindCorners(image, False)
            if corners is not None:
                pass

            # Show the final processed image.
            cv2.imshow("Augmentation", image)
            if cv2.waitKey(1) & 0xFF == ord("q"):
                break

        # Wait 2 seconds before finishing the method.
        cv2.waitKey(2000)

        # Close all allocated resources.
        cv2.destroyAllWindows()
        SIGBTools.release()
Example #2
0
    def __TextureMapGridSequence(self):
        """Skeleton for texturemapping on a video sequence."""
        # Load videodata.
        filename = self.__path + "Videos/Grid05.mp4"
        SIGBTools.VideoCapture(filename, SIGBTools.CAMERA_VIDEOCAPTURE_640X480)
        outputSize = (1280, 720)
        recorder = SIGBTools.RecordingVideos(
            self.__path + "Outputs/TextureMapGridSequence_Grid05.wmv",
            size=outputSize)

        # Load texture mapping image.
        texture = cv2.imread(self.__path + "Images/ITULogo.png")
        texture = cv2.pyrDown(texture)

        # Define the number and ids of inner corners per a chessboard row and column.
        patternSize = (9, 6)
        idx = [0, 8, 45, 53]

        # Read each frame from input video.
        h, w = texture.shape[0:2]
        textureCorners = np.asarray([[0, h], [0, 0], [w, h], [w, 0]])
        while True:
            # Read the current image from a video file.
            image = SIGBTools.read()
            # Blurs an image and downsamples it.
            image = cv2.pyrDown(image)

            # Finds the positions of internal corners of the chessboard.
            corners = SIGBTools.FindCorners(image, False)
            if corners is not None:
                pass
                corners = np.asarray([
                    corners[idx[0]], corners[idx[1]], corners[idx[2]],
                    corners[idx[3]]
                ])
                homography, _ = cv2.findHomography(textureCorners, corners)
                h, w = image.shape[0:2]
                overlay = cv2.warpPerspective(texture, homography, (w, h))
                image = cv2.addWeighted(image, 0.5, overlay, 0.5, 0)

            imagecopy = image.copy()
            imagecopy = cv2.resize(imagecopy, outputSize)
            SIGBTools.write(imagecopy)
            # Show the final processed image.
            cv2.imshow("Image", image)
            if cv2.waitKey(1) & 0xFF == ord("q"):
                break

        # Wait 2 seconds before finishing the method.
        cv2.waitKey(2000)

        # Close all allocated resources.
        cv2.destroyAllWindows()
        SIGBTools.close()
        SIGBTools.release()
Example #3
0
    def __TextureMapGridSequence(self):
        """Skeleton for texturemapping on a video sequence."""
        # Load videodata.
        filename = self.__path + "Videos/Grid01.mp4"
        SIGBTools.VideoCapture(filename, SIGBTools.CAMERA_VIDEOCAPTURE_640X480)

        SIGBTools.RecordingVideos("C:\\ITU programming\\IIAML\\Project3\\Assignments\\_02\\Outputs\\TextureMapGridSequenceGrid01.wmv")

        # Load texture mapping image.
        texture = cv2.imread(self.__path + "Images/ITULogo.png")
        texture = cv2.pyrDown(texture)

        # Define the number and ids of inner corners per a chessboard row and column.
        patternSize = (9, 6)
        idx = [53, 45, 8, 0]

        # Read each frame from input video.
        while True:
            # Read the current image from a video file.
            image = SIGBTools.read()
            # Blurs an image and downsamples it.
            image = cv2.pyrDown(image)

            # Finds the positions of internal corners of the chessboard.
            corners = SIGBTools.FindCorners(image)
            if corners is not None:
                # ====================================================
                # Find corner points image
                corner_points = []
                for i, point in enumerate(corners[idx]):
                    corner_points.append(point[0].astype(int).tolist())
                corner_points = np.array(corner_points)
                
                # Corner points texture
                corner_points_texture = np.array([[0,0], 
                                                  [texture.shape[1]-1,0],
                                                  [0,texture.shape[0]-1],
                                                  [texture.shape[1]-1,texture.shape[0]-1]],
                                                 dtype=int)
                
                # Calculate homography
                H = cv2.findHomography(corner_points_texture, corner_points)[0]
                
                # Draw the homography transformation.
                h, w = image.shape[0:2]
                overlay = cv2.warpPerspective(texture, H, (w, h))
                image  = cv2.addWeighted(image, 1, overlay, 1, 0)
                # ====================================================
            
            # Show the final processed image.
            SIGBTools.write(image)
            cv2.imshow("Image", image)
            if cv2.waitKey(1) & 0xFF == ord("q"):
                break

        # Wait 2 seconds before finishing the method.
        SIGBTools.close()
        cv2.waitKey(2000)
        # Close all allocated resources.
        cv2.destroyAllWindows()
        SIGBTools.release()