示例#1
0
    def descriptors(self):
        """
        Get the set of descriptor instances contained in this set as a tuple.

        :return: A tuple of the contained descriptor instances.
        :rtype: tuple[Descriptor]
        """
        out_d_array = ctypes.POINTER(Descriptor.c_ptr_type())()
        out_d_array_size = ctypes.c_size_t()

        self._call_cfunc(
            'vital_descriptor_set_get_descriptors',
            [
                self.C_TYPE_PTR,
                ctypes.POINTER(ctypes.POINTER(Descriptor.c_ptr_type())),
                ctypes.POINTER(ctypes.c_size_t)
            ],
            [self,
             ctypes.byref(out_d_array),
             ctypes.byref(out_d_array_size)],
        )

        d_list = []
        for i in range(out_d_array_size.value):
            cptr = Descriptor.c_ptr_type()(out_d_array[i].contents)
            d_list.append(Descriptor(from_cptr=cptr))
        free_void_ptr(out_d_array)

        return d_list
示例#2
0
    def select(self, one=0.0, two=None):

        c_output = ctypes.POINTER(DetectedObject.c_ptr_type())()
        length = ctypes.c_size_t()

        if two is None:
            dos_st = self.VITAL_LIB.vital_detected_object_set_select_threshold
            dos_st.argtypes = [
                self.C_TYPE_PTR, ctypes.c_double,
                ctypes.POINTER(ctypes.POINTER(DetectedObject.c_ptr_type())),
                ctypes.POINTER(ctypes.c_size_t)
            ]
            dos_st(self, one, ctypes.byref(c_output), ctypes.byref(length))
        else:
            dos_sct = self.VITAL_LIB.vital_detected_object_set_select_class_threshold
            dos_sct.argtypes = [
                self.C_TYPE_PTR, ctypes.c_char_p, ctypes.c_double,
                ctypes.POINTER(ctypes.POINTER(DetectedObject.c_ptr_type())),
                ctypes.POINTER(ctypes.c_size_t)
            ]
            dos_sct(self, one, two, ctypes.byref(c_output),
                    ctypes.byref(length))

        output = []
        for i in range(length.value):
            cptr = DetectedObject.c_ptr_type()(c_output[i].contents)
            output.append(DetectedObject(from_cptr=cptr))

        free_void_ptr(c_output)
        return output
示例#3
0
    def interpolated_rotations(cls, a, b, n):
        """
        Generate `n` evenly interpolated rotations in between `a` and `b`.

        We interpret `n` as an integer, e.g. if a float is given, we cast it to
        an integer, effectively flooring it.

        :param a: Rotation we are interpolating from.
        :param b: Rotation we are interpolating towards.
        :param n: Number of even interpolations in between `a` and `b` to
            generate.

        :return: Sequence of rotations between
        :rtype: list[Rotation]

        :raises ValueError: `a` or `b` are not rotation instances
        :raises ValueError: If `n` is less than 1.

        """
        if not (isinstance(a, Rotation) and isinstance(b, Rotation)):
            raise ValueError("a and b are not rotations (given: (%s, %s))" %
                             (type(a), type(b)))
        n = int(n)
        if n < 1:
            raise ValueError("n must be >= 1 (given: ")

        # if a._ctype != b._ctype, convert b into a new rotation with the same
        # type as a
        if a._ctype != b._ctype:
            cls.logger().debug("Converting `b` from type '%s' to '%s'",
                               b._ctype, a._ctype)
            b = Rotation.from_quaternion(b.quaternion(), a._ctype)

        r_interp = cls._get_c_function(cls._gen_spec(a._ctype),
                                       "interpolated_rotations")
        r_interp.argtypes = [
            a.C_TYPE_PTR, b.C_TYPE_PTR, ctypes.c_size_t,
            VitalErrorHandle.C_TYPE_PTR
        ]
        r_interp.restype = ctypes.POINTER(a.C_TYPE_PTR)
        with VitalErrorHandle() as eh:
            r_arr_ptr = r_interp(a, b, n, eh)
        r_list = []
        for i in xrange(n):
            # Have to create a new pointer instance and copy the pointer value
            # at r_arr_ptr[i] into it.
            # the pointer content at index `i` in the ptr array
            # r_list.append(Rotation(a._ctype, r_arr_ptr[i]))
            rptr = a.C_TYPE_PTR(r_arr_ptr[i].contents)
            assert ctypes.addressof(rptr.contents) == ctypes.addressof(
                r_arr_ptr[i].contents)
            r_list.append(Rotation(a._ctype, rptr))

        # This causes the rotations extracted to be freed, too...
        free_void_ptr(r_arr_ptr)

        return r_list
示例#4
0
 def upper_left(self):
     """
     returns two doubles
     """
     bb_ul = self.VITAL_LIB.vital_bounding_box_upper_left
     bb_ul.argtypes = [self.C_TYPE_PTR]
     bb_ul.restype = ctypes.POINTER(ctypes.c_double)
     l_value = output_pt[0]
     r_value = output_pt[1]
     free_void_ptr(output_pt)
     return l_value, r_value
示例#5
0
    def interpolated_rotations(cls, a, b, n):
        """
        Generate `n` evenly interpolated rotations in between `a` and `b`.

        We interpret `n` as an integer, e.g. if a float is given, we cast it to
        an integer, effectively flooring it.

        :param a: Rotation we are interpolating from.
        :param b: Rotation we are interpolating towards.
        :param n: Number of even interpolations in between `a` and `b` to
            generate.

        :return: Sequence of rotations between
        :rtype: list[Rotation]

        :raises ValueError: `a` or `b` are not rotation instances
        :raises ValueError: If `n` is less than 1.

        """
        if not (isinstance(a, Rotation) and isinstance(b, Rotation)):
            raise ValueError("a and b are not rotations (given: (%s, %s))"
                             % (type(a), type(b)))
        n = int(n)
        if n < 1:
            raise ValueError("n must be >= 1 (given: ")

        # if a._ctype != b._ctype, convert b into a new rotation with the same
        # type as a
        if a._ctype != b._ctype:
            cls.logger().debug("Converting `b` from type '%s' to '%s'",
                               b._ctype, a._ctype)
            b = Rotation.from_quaternion(b.quaternion(), a._ctype)

        r_interp = cls._get_c_function(cls._gen_spec(a._ctype),
                                       "interpolated_rotations")
        r_interp.argtypes = [a.C_TYPE_PTR, b.C_TYPE_PTR, ctypes.c_size_t,
                             VitalErrorHandle.C_TYPE_PTR]
        r_interp.restype = ctypes.POINTER(a.C_TYPE_PTR)
        with VitalErrorHandle() as eh:
            r_arr_ptr = r_interp(a, b, n, eh)
        r_list = []
        for i in xrange(n):
            # Have to create a new pointer instance and copy the pointer value
            # at r_arr_ptr[i] into it.
            # the pointer content at index `i` in the ptr array
            # r_list.append(Rotation(a._ctype, r_arr_ptr[i]))
            rptr = a.C_TYPE_PTR(r_arr_ptr[i].contents)
            assert ctypes.addressof(rptr.contents) == ctypes.addressof(r_arr_ptr[i].contents)
            r_list.append(Rotation(a._ctype, rptr))

        # This causes the rotations extracted to be freed, too...
        free_void_ptr(r_arr_ptr)

        return r_list
示例#6
0
 def lower_right(self):
     """
     returns two doubles
     """
     bb_lr = self.VITAL_LIB.vital_bounding_box_lower_right
     bb_lr.argtypes = [self.C_TYPE_PTR]
     bb_lr.restype = ctypes.POINTER(ctypes.c_double)
     output_pt = bb_lr(self)
     l_value = output_pt[0]
     r_value = output_pt[1]
     free_void_ptr(output_pt)
     return l_value, r_value
示例#7
0
 def all_track_ids(self):
     """ Get the set of all track IDs contained in this set
     :return: Set of track ID integers
     :rtype: set[int]
     """
     arr_len = ctypes.c_size_t()
     tid_arr = self._call_cfunc(
         'vital_trackset_all_track_ids',
         [self.C_TYPE_PTR, ctypes.POINTER(ctypes.c_size_t)],
         [self, ctypes.byref(arr_len)], ctypes.POINTER(ctypes.c_int64))
     tid_set = set()
     for i in range(arr_len.value):
         tid_set.add(tid_arr[i])
     free_void_ptr(tid_arr)
     return tid_set
示例#8
0
文件: track.py 项目: nagyist/kwiver
 def all_frame_ids(self):
     """
     Get set of all frame IDs covered by states in this track.
     :return: Set of frame ID integers
     :rtype: set[int]
     """
     n = ctypes.c_size_t()
     s = self._call_cfunc(
         "vital_track_all_frame_ids",
         [self.C_TYPE_PTR, ctypes.POINTER(ctypes.c_size_t)],
         [self, ctypes.byref(n)], ctypes.POINTER(ctypes.c_int64))
     r = set()
     for i in xrange(n.value):
         r.add(s[i])
     free_void_ptr(s)
     return r
示例#9
0
    def all_frame_ids(self):
        """
        Get the set of all frame IDs covered by tracks in this set

        :return: Set of frame IDs covered
        :rtype: set[int]

        """
        arr_len = ctypes.c_size_t()
        fid_arr = self._call_cfunc(
            'vital_trackset_all_frame_ids',
            [self.C_TYPE_PTR, ctypes.POINTER(ctypes.c_size_t)],
            [self, ctypes.byref(arr_len)], ctypes.POINTER(ctypes.c_int64))
        fid_set = set()
        for i in range(arr_len.value):
            fid_set.add(fid_arr[i])
        free_void_ptr(fid_arr)
        return fid_set
示例#10
0
    def get_value(self, key, default=None):
        """ Get the string value for a key.

        The given key may not exist in this configuration. If no default was
        given, then an exception is raised. Otherwise, the provided default
        value is returned.

        :param key: The index of the configuration value to retrieve.
        :type key: str

        :param default: Optional default value that will be returned if the
            given is not found in this configuration.
        :type default: str

        :return: The string value stored within the configuration
        :rtype: str

        :raises VitalConfigBlockNoSuchValueException: the given key doesn't
            exist in the configuration and no default was provided.

        """
        c_arg_t = [self.C_TYPE_PTR, ctypes.c_char_p]
        c_arg_v = [self, key]
        c_arg_r = ctypes.c_void_p
        ex_map = {1: VitalConfigBlockNoSuchValueException}

        if default is None:
            v = self._call_cfunc(
                'vital_config_block_get_value',
                c_arg_t, c_arg_v, c_arg_r, ex_map
            )
        else:
            v = self._call_cfunc(
                'vital_config_block_get_value_default',
                c_arg_t + [ctypes.c_char_p],
                c_arg_v + [default],
                c_arg_r,
                ex_map
            )

        s = ctypes.c_char_p(v).value
        free_void_ptr(v)
        return s
示例#11
0
    def get_value(self, key, default=None):
        """ Get the string value for a key.

        The given key may not exist in this configuration. If no default was
        given, then an exception is raised. Otherwise, the provided default
        value is returned.

        :param key: The index of the configuration value to retrieve.
        :type key: str

        :param default: Optional default value that will be returned if the
            given is not found in this configuration.
        :type default: str

        :return: The string value stored within the configuration
        :rtype: str

        :raises VitalConfigBlockNoSuchValueException: the given key doesn't
            exist in the configuration and no default was provided.

        """
        c_arg_t = [self.C_TYPE_PTR, ctypes.c_char_p]
        c_arg_v = [self, key]
        c_arg_r = ctypes.c_void_p
        ex_map = {1: VitalConfigBlockNoSuchValueException}

        if default is None:
            v = self._call_cfunc(
                'vital_config_block_get_value',
                c_arg_t, c_arg_v, c_arg_r, ex_map
            )
        else:
            v = self._call_cfunc(
                'vital_config_block_get_value_default',
                c_arg_t + [ctypes.c_char_p],
                c_arg_v + [default],
                c_arg_r,
                ex_map
            )

        s = ctypes.c_char_p(v).value
        free_void_ptr(v)
        return s
示例#12
0
    def tracks(self):
        """
        Get the list of all tracks contained in this set (new instances).

        :return: list of new Track instances of tracks contained in this set
        :rtype: list[Track]

        """
        c_ptr_arr = self._call_cfunc('vital_trackset_tracks',
                                     [self.C_TYPE_PTR], [self],
                                     ctypes.POINTER(Track.c_ptr_type()))

        tracks = []
        for cptr in c_ptr_arr[:self.size()]:
            cptr = Track.c_ptr_type()(cptr.contents)
            tracks.append(Track(from_cptr=cptr))
        free_void_ptr(c_ptr_arr)

        return tracks
示例#13
0
    def get_description(self, key):
        """
        Get the string description for a given key.

        :raises VitalConfigBlockNoSuchValueException: the given key doesn't
            exist in the configuration.

        :param key: The name of the parameter to get the description of.
        :type key: str

        :returns: The string description of the give key.
        :rtype: str or None

        """
        v = self._call_cfunc('vital_config_block_get_description',
                             [self.C_TYPE_PTR, ctypes.c_char_p], [self, key],
                             ctypes.c_void_p,
                             {1: VitalConfigBlockNoSuchValueException})
        s = ctypes.c_char_p(v).value
        free_void_ptr(v)
        return s
示例#14
0
    def get_description(self, key):
        """
        Get the string description for a given key.

        :raises VitalConfigBlockNoSuchValueException: the given key doesn't
            exist in the configuration.

        :param key: The name of the parameter to get the description of.
        :type key: str

        :returns: The string description of the give key.
        :rtype: str or None

        """
        v = self._call_cfunc(
            'vital_config_block_get_description',
            [self.C_TYPE_PTR, ctypes.c_char_p],
            [self, key],
            ctypes.c_void_p,
            {1: VitalConfigBlockNoSuchValueException}
        )
        s = ctypes.c_char_p(v).value
        free_void_ptr(v)
        return s