Exemple #1
0
 def test_new_nonempty(self):
     n = 10
     tracks = [Track() for _ in xrange(n)]
     ts = TrackSet(tracks)
     nt.assert_true(ts, "Invalid track set instance constructed")
     nt.assert_equal(len(ts), n)
     nt.assert_equal(ts.size(), n)
Exemple #2
0
 def test_new_nonempty(self):
     n = 10
     tracks = [Track() for _ in xrange(n)]
     ts = TrackSet(tracks)
     nt.assert_true(ts, "Invalid track set instance constructed")
     nt.assert_equal(len(ts), n)
     nt.assert_equal(ts.size(), n)
Exemple #3
0
 def test_empty_len_size(self):
     ts = TrackSet()
     nt.assert_true(ts, "Invalid track set instance constructed")
     l = len(ts)
     s = ts.size()
     nt.assert_equal(l, 0)
     nt.assert_equal(l, s)
Exemple #4
0
 def test_empty_len_size(self):
     ts = TrackSet()
     nt.assert_true(ts, "Invalid track set instance constructed")
     l = len(ts)
     s = ts.size()
     nt.assert_equal(l, 0)
     nt.assert_equal(l, s)
    def track_images(self):
        # Create list of input filepaths
        self.log.info("Reading input image list file...")
        with open(self.image_list_filepath, 'r') as image_list_file:
            input_filepaths = \
                [line.strip() for line in image_list_file.readlines()]

        # Create a list of mask images if we were given a list file
        mask_filepaths = None
        if self.mask_list_filepath:
            self.log.info("Reading mask image list file...")
            with open(self.mask_list_filepath) as mask_list_file:
                mask_filepaths = \
                    [line.strip() for line in mask_list_file.readlines()]

            if len(input_filepaths) != len(mask_filepaths):
                self.log.error("Input and Mask image lists were not congruent "
                               "in size.")
                return False

        # Check that the output tracks file is open-able and that the containing
        # directory exists.
        if not os.path.isdir(os.path.dirname(self.output_tracks_filepath)):
            self.log.info("Creating containing directory for output tracks "
                          "file: %s",
                          os.path.dirname(self.output_tracks_filepath))
            os.mkdir(os.path.dirname(self.output_tracks_filepath))
        self.log.info("Testing that output tracks file is open-able...")
        test_f = open(self.output_tracks_filepath, 'w')
        test_f.close()

        tracks = TrackSet()
        for frame_num in xrange(len(input_filepaths)):
            input_img = self.algo_convert_img.convert(
                self.algo_image_io.load(input_filepaths[frame_num])
            )
            mask_img = None
            if mask_filepaths:
                mask_img = self.algo_convert_img.convert(
                    self.algo_image_io.load(mask_filepaths[frame_num])
                )
            self.log.info("Processing frame %d...", frame_num)
            tracks = self.algo_track_features.track(tracks, frame_num,
                                                    input_img, mask_img)

        self.log.info("Frame processing complete, writing out track set...")
        tracks.write_tracks_file(self.output_tracks_filepath)
    def track_images(self):
        # Create list of input filepaths
        self.log.info("Reading input image list file...")
        with open(self.image_list_filepath, 'r') as image_list_file:
            input_filepaths = \
                [line.strip() for line in image_list_file.readlines()]

        # Create a list of mask images if we were given a list file
        mask_filepaths = None
        if self.mask_list_filepath:
            self.log.info("Reading mask image list file...")
            with open(self.mask_list_filepath) as mask_list_file:
                mask_filepaths = \
                    [line.strip() for line in mask_list_file.readlines()]

            if len(input_filepaths) != len(mask_filepaths):
                self.log.error("Input and Mask image lists were not congruent "
                               "in size.")
                return False

        # Check that the output tracks file is open-able and that the containing
        # directory exists.
        if not os.path.isdir(os.path.dirname(self.output_tracks_filepath)):
            self.log.info(
                "Creating containing directory for output tracks "
                "file: %s", os.path.dirname(self.output_tracks_filepath))
            os.mkdir(os.path.dirname(self.output_tracks_filepath))
        self.log.info("Testing that output tracks file is open-able...")
        test_f = open(self.output_tracks_filepath, 'w')
        test_f.close()

        tracks = TrackSet()
        for frame_num in xrange(len(input_filepaths)):
            input_img = self.algo_convert_img.convert(
                self.algo_image_io.load(input_filepaths[frame_num]))
            mask_img = None
            if mask_filepaths:
                mask_img = self.algo_convert_img.convert(
                    self.algo_image_io.load(mask_filepaths[frame_num]))
            self.log.info("Processing frame %d...", frame_num)
            tracks = self.algo_track_features.track(tracks, frame_num,
                                                    input_img, mask_img)

        self.log.info("Frame processing complete, writing out track set...")
        tracks.write_tracks_file(self.output_tracks_filepath)
Exemple #7
0
    def track(self, prev_tracks, frame_num, image, mask=None):
        """
        Extend a previous set of tracks using the given image.

        An optional mask image may be provided, where positive valued regions
        indicate regions of the input image to consider for feature tracking.
        The mask image must be of the same dimensions as the input image, other
        wise an exception is raised.

        :param prev_tracks:
        :param frame_num:
        :param image:
        :param mask:
        :return:

        """
        tf_track_argtypes = [self.C_TYPE_PTR, TrackSet.C_TYPE_PTR,
                             ctypes.c_uint, ImageContainer.C_TYPE_PTR]
        tf_track_args = [self, prev_tracks, frame_num, image]
        tf_track_restype = TrackSet.C_TYPE_PTR

        if mask:
            tf_track = self.MAPTK_LIB['maptk_algorithm_track_features_'
                                      'track_with_mask']
            tf_track_argtypes.append(ImageContainer.C_TYPE_PTR)
            tf_track_args.append(mask)
        else:
            tf_track = self.MAPTK_LIB['maptk_algorithm_track_features_track']
        tf_track_argtypes.append(MaptkErrorHandle.C_TYPE_PTR)

        tf_track.argtypes = tf_track_argtypes
        tf_track.restype = tf_track_restype

        with MaptkErrorHandle() as eh:
            tf_track_args.append(eh)
            return TrackSet.from_c_pointer(
                tf_track(*tf_track_args)
            )
Exemple #8
0
    def track(self, prev_tracks, frame_num, image, mask=None):
        """
        Extend a previous set of tracks using the given image.

        An optional mask image may be provided, where positive valued regions
        indicate regions of the input image to consider for feature tracking.
        The mask image must be of the same dimensions as the input image, other
        wise an exception is raised.

        :param prev_tracks:
        :param frame_num:
        :param image:
        :param mask:
        :return:

        """
        tf_track_argtypes = [
            self.C_TYPE_PTR, TrackSet.C_TYPE_PTR, ctypes.c_uint,
            ImageContainer.C_TYPE_PTR
        ]
        tf_track_args = [self, prev_tracks, frame_num, image]
        tf_track_restype = TrackSet.C_TYPE_PTR

        if mask:
            tf_track = self.MAPTK_LIB['maptk_algorithm_track_features_'
                                      'track_with_mask']
            tf_track_argtypes.append(ImageContainer.C_TYPE_PTR)
            tf_track_args.append(mask)
        else:
            tf_track = self.MAPTK_LIB['maptk_algorithm_track_features_track']
        tf_track_argtypes.append(MaptkErrorHandle.C_TYPE_PTR)

        tf_track.argtypes = tf_track_argtypes
        tf_track.restype = tf_track_restype

        with MaptkErrorHandle() as eh:
            tf_track_args.append(eh)
            return TrackSet.from_c_pointer(tf_track(*tf_track_args))
Exemple #9
0
 def test_new(self):
     ts = TrackSet()
     nt.assert_true(ts, "Invalid track set instance constructed")