Exemplo n.º 1
0
    def __RealisticTextureMap(self):
        # Load videodata.
        filename = self.__path + "Videos/ITUStudent.avi"
        SIGBTools.VideoCapture(filename, SIGBTools.CAMERA_VIDEOCAPTURE_640X480)

        # Load tracking data.
        dataFile = np.loadtxt(self.__path + "Inputs/trackingdata.dat")
        lenght = dataFile.shape[0]

        # Define the boxes colors.
        boxColors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]  # BGR.

        # Read each frame from input video and draw the rectangules on it.
        for i in range(lenght):
            # Read the current image from a video file.
            image = SIGBTools.read()

            # Draw each color rectangule in the image.
            boxes = SIGBTools.FrameTrackingData2BoxData(dataFile[i, :])
            for j in range(3):
                box = boxes[j]
                cv2.rectangle(image, box[0], box[1], boxColors[j])

            # Show the final processed image.
            cv2.imshow("Ground Floor", 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()
Exemplo n.º 2
0
    def __TextureMapGroundFloor(self):
        """Places a texture on the ground floor for each input image."""
        # Load videodata.
        filename = self.__path + "Videos/ITUStudent.avi"
        SIGBTools.VideoCapture(filename, SIGBTools.CAMERA_VIDEOCAPTURE_640X480)
        outputSize = (640, 480)
        recorder = SIGBTools.RecordingVideos(
            self.__path + "Outputs/TextureMapGroundFloor.wmv", size=outputSize)

        # Load tracking data.
        dataFile = np.loadtxt(self.__path + "Inputs/trackingdata.dat")
        lenght = dataFile.shape[0]

        # Define the boxes colors.
        boxColors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]  # BGR.

        homography = None
        overlay = None
        itulogo = cv2.imread(self.__path + "Images/ITULogo.png")
        # Read each frame from input video and draw the rectangules on it.
        for i in range(lenght):
            # Read the current image from a video file.
            image = SIGBTools.read()
            if homography is None:
                h, _ = SIGBTools.GetHomographyFromMouse(itulogo, image, -4)
                homography = h
                np.save('homography2.npy', homography)
                h, w = image.shape[0:2]
                overlay = cv2.warpPerspective(itulogo, homography, (w, h))

            image = cv2.addWeighted(image, 0.8, overlay, 0.2, 0)

            # Draw each color rectangule in the image.
            boxes = SIGBTools.FrameTrackingData2BoxData(dataFile[i, :])
            for j in range(3):
                box = boxes[j]
                cv2.rectangle(image, box[0], box[1], boxColors[j])

            imagecopy = image.copy()
            imagecopy = cv2.resize(imagecopy, outputSize)
            SIGBTools.write(imagecopy)
            # Show the final processed image.
            cv2.imshow("Ground Floor", 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()
Exemplo n.º 3
0
    def __ShowFloorTrackingData(self):
        # Load videodata.
        filename = self.__path + "Videos/ITUStudent.avi"
        image2 = cv2.imread(self.__path + "Images/ITUMap.png")
        SIGBTools.VideoCapture(filename, SIGBTools.CAMERA_VIDEOCAPTURE_640X480)
        SIGBTools.RecordingVideos("C:\\Code\\IIAML\\Project3\\Assignments\\_02\\Outputs\\MapLocation.wmv")
        
        # Load homography
        homography = np.load(self.__path + "Outputs/homography1.npy")
        
        # Load tracking data.
        dataFile = np.loadtxt(self.__path + "Inputs/trackingdata.dat")
        lenght   = dataFile.shape[0]

        # Define the boxes colors.
        boxColors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] # BGR.

        # Read each frame from input video and draw the rectangules on it.
        for i in range(lenght):
            # Read the current image from a video file.
            image = SIGBTools.read()

            # Draw each color rectangule in the image.
            boxes = SIGBTools.FrameTrackingData2BoxData(dataFile[i, :])
            for j in range(3):
                box = boxes[j]
                cv2.rectangle(image, box[0], box[1], boxColors[j])

            point2 = self.__calcHomogenousCoordinates(boxes[2][1], homography)
            # Show the final processed image.
            # Live tracking
            image2_updated = image2.copy()
            cv2.circle(image2_updated, (int(point2[0]), int(point2[1])), 10, (0, 255, 0), -1)
            cv2.imshow("Map", image2_updated)
            # Drawing
            #cv2.circle(image2, (int(point2[0]), int(point2[1])), 3, (0, 255, 0), -1)
            #cv2.imshow("Map", image2)
            
            cv2.imshow("Ground Floor", image)
            SIGBTools.write(image2_updated)
            
            #self.__showPointsOnFrameOfView(image, points)            
            if cv2.waitKey(1) & 0xFF == ord("q"):
                break

        # Wait 2 seconds before finishing the method.
        SIGBTools.close()
        cv2.waitKey(2000)
        cv2.imwrite(self.__path + "Outputs/mapImage.png", image2)

        # Close all allocated resources.
        cv2.destroyAllWindows()
        SIGBTools.release()
Exemplo n.º 4
0
    def __ShowFloorTrackingData(self):
        # Load videodata.
        filename = self.__path + "Videos/ITUStudent.avi"
        SIGBTools.VideoCapture(filename, SIGBTools.CAMERA_VIDEOCAPTURE_640X480)

        # Load tracking data.
        dataFile = np.loadtxt(self.__path + "Inputs/trackingdata.dat")
        length = dataFile.shape[0]

        # Define the boxes colors.
        boxColors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)]  # BGR.
        outputSize = (1280, 960)
        recorder = SIGBTools.RecordingVideos(self.__path +
                                             "Outputs/MapLocation.wmv",
                                             size=outputSize)

        dataPoints = list()
        # Read each frame from input video and draw the rectangules on it.
        first = True
        homography = None
        itumap = cv2.imread(self.__path + "Images/ITUMap.png")
        for i in range(length):
            # Read the current image from a video file.
            image = SIGBTools.read()

            # Estimate the homograhy based on first frame
            if first:
                h, _ = SIGBTools.GetHomographyFromMouse(image, itumap)
                homography = h
                first = False
                np.save('homography1.npy', homography)

            # Draw each color rectangule in the image.
            boxes = SIGBTools.FrameTrackingData2BoxData(dataFile[i, :])

            # Transform center of the feet box - box1 is feet box
            box1 = boxes[1][0]
            box2 = boxes[1][1]
            center = [(box1[0] + 0.5 * (box2[0] - box1[0])),
                      (box1[1] + 0.5 * (box2[1] - box1[1]))]
            # Reshape the center to be as expected
            center = np.array([center], dtype=np.float32)
            center = np.array([center])
            transformedCenter = cv2.perspectiveTransform(center, homography)
            dataPoints.append(transformedCenter)

            for j in range(3):
                box = boxes[j]
                cv2.rectangle(image, box[0], box[1], boxColors[j])

            # Show the final processed image.
            #Draw current position
            c = transformedCenter[0][0]
            itumapCopy = itumap.copy()
            cv2.circle(itumapCopy, (int(c[0]), int(c[1])), 1, (0, 255, 0), -1)
            cv2.imshow("ITU Map", itumapCopy)

            cv2.imshow("Ground Floor", image)

            height, width, _ = image.shape
            resizedMap = cv2.resize(
                itumapCopy, (width, height))  # resize to same dimensions
            sideBySide = np.concatenate((image, resizedMap), axis=0)
            output = cv2.resize(sideBySide, outputSize)
            SIGBTools.write(output)
            if cv2.waitKey(1) & 0xFF == ord("q"):
                break

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

        imageMap = itumap.copy()
        for point in dataPoints:
            p = point[0][0]  #due to point being wrapped
            cv2.circle(imageMap, (int(p[0]), int(p[1])), 1, (0, 255, 0), -1)

        cv2.imwrite(self.__path + "Outputs/mapImage.png", imageMap)

        # Close all allocated resources.
        cv2.destroyAllWindows()
        SIGBTools.close()
        SIGBTools.release()
Exemplo n.º 5
0
    def __TextureMapGroundFloor(self):
        """Places a texture on the ground floor for each input image."""
        # Load videodata.
        filename = self.__path + "Videos/ITUStudent.avi"
        SIGBTools.VideoCapture(filename, SIGBTools.CAMERA_VIDEOCAPTURE_640X480)
        
        # Needs full path
        SIGBTools.RecordingVideos("C:\\Code\IIAML\\Project3\\Assignments\\_02\\Outputs\\TextureMapGroundFloor.wmv")
        
        # ======================================================
        # Read homography from ground to map.
        H_g2m = np.load(self.__path + "Outputs/homography1.npy")
        
        # Read the input images.
        image1 = cv2.imread(self.__path + "Images/ITULogo.PNG")
        image2 = cv2.imread(self.__path + "Images/ITUMap.png")
        
        # Estimate the homography from image to map.
        H_i2m, points = SIGBTools.GetHomographyFromMouse(image1, image2, -4)
        
        # Calculate homography from image to ground.
        H_i2g = np.dot(np.linalg.inv(H_g2m), H_i2m)
        
        np.save(self.__path + "Outputs/homography2.npy", H_i2g)
        # ========================================================
        
        # Load tracking data.
        dataFile = np.loadtxt(self.__path + "Inputs/trackingdata.dat")
        lenght   = dataFile.shape[0]

        # Define the boxes colors.
        boxColors = [(255, 0, 0), (0, 255, 0), (0, 0, 255)] # BGR.
        images = []
        
        # Read each frame from input video and draw the rectangules on it.
        for i in range(lenght):
            # Read the current image from a video file.
            image = SIGBTools.read()

            # Draw each color rectangule in the image.
            boxes = SIGBTools.FrameTrackingData2BoxData(dataFile[i, :])
            for j in range(3):
                box = boxes[j]
                cv2.rectangle(image, box[0], box[1], boxColors[j])
            
            
            # ========================================================
            # Draw the homography transformation.
            h, w    = image.shape[0:2]
            overlay = cv2.warpPerspective(image1, H_i2g, (w, h))
            result  = cv2.addWeighted(image, 0.5, overlay, 0.5, 0)
            #images.append(result)
            SIGBTools.write(result)
            # ========================================================

            # Show the final processed image.
            cv2.imshow("Camera", result)
            
            if cv2.waitKey(1) & 0xFF == ord("q"):
                break
        
        
        # Wait 2 seconds before finishing the method.
        cv2.waitKey(2000)
        SIGBTools.close()
        # Close all allocated resources.
        cv2.destroyAllWindows()
        
        SIGBTools.release()