Detector Data Types and Related Algorithms¶
Detected Object Set¶
-
class detected_object_set : public kwiver::vital::set<detected_object_sptr>, private kwiver::vital::noncopyable¶
Set of detected objects.
This class represents a ordered set of detected objects. The detections are ordered on their basic confidence value.
- Reentrancy considerations:
Typical usage for a set is for a single detector thread to create a set. It is possible to have an application where two threads are accessing the same set concurrently.
Unnamed Group
-
virtual detected_object_sptr at(size_t pos) override¶
Get pointer to detected object at specified index.
This method returns a reference to the element at
pos
, with bounds checking. Ifpos
is not within the range of the container, a std::out_of_range exception is thrown.- Parameters
pos – Position of element to return (from zero).
- Throws
std::out_of_range – if
pos
is not within the range of objects in the container.- Returns
Shared pointer to specified element.
Public Functions
-
detected_object_set()¶
Create an empty detection set.
This constructor creates an empty detection set. Detections can be added with the add() method.
-
detected_object_set(std::vector<detected_object_sptr> const &objs)¶
Create a new set of detected objects.
This constructor creates a detection set using the supplied vector of detection objects. This can be used to create a new detection set from the output of a select() method.
- Parameters
objs – Vector of detected objects.
-
detected_object_set_sptr clone() const¶
Clone the detected object set (polymorphic copy constructor).
-
void add(detected_object_sptr object)¶
Add detection to set.
This method adds a new detection to this set.
- Parameters
object – Detection to be added to set.
-
void add(detected_object_set_sptr detections)¶
Add detection to set.
This method adds a new detection to this set.
- Parameters
detections – Detection set to be added to set.
-
virtual size_t size() const override¶
Get number of detections in this set.
-
virtual bool empty() const override¶
Test if this set is empty.
- Returns
true
if the set is empty, otherwisefalse
.
-
detected_object_set_sptr select(double threshold = detected_object_type::INVALID_SCORE) const¶
Select detections based on confidence value.
This method returns a vector of detections ordered by confidence value, from high to low. If the optional
threshold
is specified, then all detections from the set that are less than the threshold are not in the selected set. Note that the selected set may be empty.The returned vector refers to the actual detections in the set, so if you make changes to the selected set, you are also changing the object in the set. If you want a clean set of detections, call clone() first.
- Parameters
threshold – Select all detections with confidence not less than this value. If this parameter is omitted, all detections are selected.
- Returns
List of detections.
-
detected_object_set_sptr select(const std::string &class_name, double threshold = detected_object_type::INVALID_SCORE) const¶
Select detections based on class name.
This method returns a vector of detections that have the specified
class_name
. These detections are ordered by descending score for the name. Note that the selected set may be empty.The returned vector refers to the actual detections in the set, so if you make changes to the selected set, you are also changing the object in the set. If you want a clean set of detections, call clone() first.
- Parameters
class_name – Class name of detections to be selected.
threshold – Select all detections with confidence not less than this value. If this parameter is omitted, all detections are selected.
- Returns
List of detections.
- VITAL_DEPRECATED void scale (double scale_factor)
Scale all detection locations by some scale factor.
This method changes the bounding boxes within all stored detections by scaling them by the specified scale factor.
- Deprecated:
Note
Detections in this set can be shared by multiple sets, so scaling the detections in this set will also scale the detection in other sets that share the detections. To avoid this, clone() the set before shifting.
- Parameters
scale – Scale factor to be applied.
- VITAL_DEPRECATED void shift (double col_shift, double row_shift)
Shift all detection locations by some translation offset.
This method shifts the bounding boxes within all stored detections by a supplied column and row shift.
- Deprecated:
Note
Detections in this set can be shared by multiple sets, so shifting the detections in this set will also shift the detection in other sets that share the detections. To avoid this, clone() the set before shifting.
- Parameters
col_shift – Column (a.k.a. x, i, width) translation value.
row_shift – Row (a.k.a. y, j, height) translation value.
-
attribute_set_sptr attributes() const¶
Get attribute set.
This method returns a pointer to the attribute set that is attached to this detected object set. It is possible that the pointer is null, so check before using it.
- Returns
Pointer to attribute set or
nullptr
-
void set_attributes(attribute_set_sptr attrs)¶
Attach attribute set to this detected object set.
This method attaches the specified attribute set to this detected object set.
- Parameters
attrs – Pointer to attribute set to attach.
Detected Object¶
-
class detected_object¶
Detected object class.
This class represents a detected object in image space.
There is one object of this type for each detected object. These objects are defined by a bounding box in the image space. Each object has an optional classification object attached.
Public Functions
-
detected_object(double confidence = 1.0, detected_object_type_sptr classifications = nullptr)¶
Create default detected object.
- Parameters
confidence – Detectors confidence in this detection.
classifications – Optional object classification.
-
detected_object(bounding_box_d const &bbox, double confidence = 1.0, detected_object_type_sptr classifications = nullptr)¶
Create detected object with bounding box and other attributes.
- Parameters
bbox – Bounding box surrounding detected object, in image coordinates.
confidence – Detectors confidence in this detection.
classifications – Optional object classification.
-
detected_object(kwiver::vital::geo_point const &geo_pt, double confidence = 1.0, detected_object_type_sptr classifications = nullptr)¶
Create detected object with a geo_point and other attributes.
- Parameters
geo_pt – Geographic location of the detection, in world coordinates.
confidence – Detectors confidence in this detection.
classifications – Optional object classification.
-
detected_object_sptr clone() const¶
Create a deep copy of this object.
- Returns
Managed copy of this object.
-
bounding_box_d bounding_box() const¶
Get bounding box from this detection.
The bounding box for this detection is returned. This box is in image coordinates. A default constructed (invalid) bounding box is returned if no box has been supplied for this detection.
- Returns
A copy of the bounding box.
-
void set_bounding_box(bounding_box_d const &bbox)¶
Set new bounding box for this detection.
The supplied bounding box replaces the box for this detection.
- Parameters
bbox – Bounding box for this detection.
-
kwiver::vital::geo_point geo_point() const¶
Get geo_point from this detection.
The geo_point for this detection is returned. A default constructed (invalid) geo_point is returned if no point has been supplied for this detection.
- Returns
A copy of the geo_point.
-
void set_geo_point(kwiver::vital::geo_point const &gp)¶
Set new geo_point for this detection.
The supplied geo_point replaces the point for this detection.
- Parameters
gp – geo_point for this detection.
-
double confidence() const¶
Get confidence for this detection.
This method returns the current confidence value for this detection. Confidence values are in the range of 0.0 - 1.0.
- Returns
Confidence value for this detection.
-
void set_confidence(double d)¶
Set new confidence value for detection.
This method sets a new confidence value for this detection. Confidence values are in the range of [0.0 - 1.0].
- Parameters
d – New confidence value for this detection.
-
uint64_t index() const¶
Get detection index.
This method returns the index for this detection.
The detection index is a general purpose field that the application can use to individually identify a detection. In some cases, this field can be used to correlate the detection of an object over multiple frames.
- Returns
Detection index fof this detections.
-
void set_index(uint64_t idx)¶
Set detection index.
This method sets tne index value for this detection.
The detection index is a general purpose field that the application can use to individually identify a detection. In some cases, this field can be used to correlate the detection of an object over multiple frames.
- Parameters
idx – Detection index.
-
std::string detector_name() const¶
Get detector name.
This method returns the name of the detector that created this element. An empty string is returned if the detector name is not set.
- Returns
Name of the detector.
-
void set_detector_name(std::string const &name)¶
Set detector name.
This method sets the name of the detector for this detection.
- Parameters
name – Detector name.
-
detected_object_type_sptr type() const¶
Get pointer to optional classifications object.
This method returns the pointer to the classification object if there is one. If there is no classification object the pointer is NULL.
- Returns
Pointer to classification object or NULL.
-
void set_type(detected_object_type_sptr c)¶
Set new classifications for this detection.
This method supplies a new set of class_names and scores for this detection.
- Parameters
c – New classification for this detection
-
image_container_scptr mask() const¶
Get detection mask image.
This method returns the mask image associated with this detection.
- Returns
Pointer to the mask image.
-
void set_mask(image_container_scptr m)¶
Set mask image for this detection.
This method supplies a new mask image for this detection.
- Parameters
m – Mask image
-
descriptor_scptr descriptor() const¶
Get descriptor vector.
This method returns an optional descriptor vector that was used to create this detection. This is only set for certain object detectors.
- Returns
Pointer to the descriptor vector.
-
void set_descriptor(descriptor_scptr d)¶
Set descriptor for this detection.
This method sets a descriptor vector that was used to create this detection. This is only set for certain object detectors.
- Parameters
d – Descriptor vector
-
notes_t notes() const¶
Get vector of notes for this detection.
This method returns a list of notes (arbitrary strings) associated with this detection. Notes are useful in user interfaces for making any observations about this detection which don’t fit into types.
- Returns
A vector of notes.
-
void add_note(std::string const ¬e)¶
Add a note for this detection.
Notes are useful in user interfaces for making any observations about this detection which don’t fit into types.
- Parameters
note – String to add as a note
-
void clear_notes()¶
Reset notes for this detection.
Remove any notes stored within this detection.
-
keypoints_t keypoints() const¶
Returns a list of keypoints associated with this detection.
This method returns a map of keypoints associated with this detection, which can be of arbitrary length.
- Returns
A map of keypoints and their identifiers.
-
void add_keypoint(std::string const &id, vital::point_2d const &p)¶
Add a note for this detection.
Notes are useful in user interfaces for making any observations about this detection which don’t fit into types. If a keypoint of the given name already exists, it will be over-written.
- Parameters
id – String id of the keypoint
p – The location of the keypoint
-
void clear_keypoints()¶
Reset keypoints for this detection.
Removes any keypoints stored within this detection.
-
detected_object(double confidence = 1.0, detected_object_type_sptr classifications = nullptr)¶
Class Map¶
-
template<typename T>
class class_map¶ Map of classifications to confidence scores for an object.
This class represents a set of possible types for an object. A type for an object is represented by a class_name string and a score.
When an object is classified, there may be several possibilities determined, since the classification process is probabilistic. This class captures the set of possible types along with the relative likelyhood or score.
Note that score values in this object are not constrained to [0.0,1.0] because different detectors use different approaches for scores. These scores can be normalized, but that is up to the user of these values.
Note that the list of possible names is managed through a class static string pool. Every effort has been made to make this pool externally unmutable. Your cooperation is appreciated.
Unnamed Group
-
class_const_iterator_t begin() const¶
Get start iterator to all class/score pairs.
This method returns an iterator that may be used to iterate over all class/score pairs. The order in which items will be seen by this iterator is unspecified.
See also
- Returns
Start iterator to all class/score pairs.
Unnamed Group
Public Functions
-
class_map()¶
Create an empty object.
An object is created without class_names or scores.
-
class_map(const std::vector<std::string> &class_names, const std::vector<double> &scores)¶
Create new object type class.
Create a new object type instance with a set of labels and likelyhoods. The parameters have corresponding ordering, which means that the first label is for the first likelyhood , and so on.
The number of elements in the parameter vectors must be the same.
- Parameters
class_names – List of names for the possible classes.
scores – Vector of scores for this object.*
- Throws
std::invalid_argument – if the vector lengths differ
-
class_map(const std::string &class_name, double score)¶
Create new object type class.
Create a new object type instance from a single class name and label.
- Parameters
class_name – Class name
score – Probability score for the class
-
bool has_class_name(const std::string &class_name) const¶
Determine if class-name is present.
This method determines if the specified class name is present in this object.
- Parameters
class_name – Class name to test.
- Returns
true if class name is present.
-
double score(const std::string &class_name) const¶
Get score for specific class_name.
This method returns the score for the specified class_name. If the name is not associated with this object, an exception is thrown.
- Parameters
class_name – Return score for this entry.
- Throws
std::runtime_error – If supplied class_name is not associated with this object.
- Returns
Score for selected class_name.
-
void get_most_likely(std::string &max_name) const¶
Get max class name.
This method returns the most likely class for this object.
If there are no scores associated with this object, then an exception is thrown
- Parameters
max_name – [out] Class name with the maximum score.
- Throws
std::runtime_error – If no scores are associated with this object.
-
void get_most_likely(std::string &max_name, double &max_score) const¶
Get max score and name.
This method returns the maximum score or the most likely class for this object. The score value and class_name are returned.
If there are no scores associated with this object, then an exception is thrown
- Parameters
max_name – [out] Class name with the maximum score.
max_score – [out] maximum score
- Throws
std::runtime_error – If no scores are associated with this object.
-
void set_score(const std::string &class_name, double score)¶
Set score for a class.
This method sets or updates the score for a type name. Note that the score value is not constrained to [0.0,1.0].
If the class_name specified is not previously associated with this object type, it is added, If it is present, the score is updated.
- Parameters
class_name – Class name.
score – Score value for class_name
-
void delete_score(const std::string &class_name)¶
Remove score and class_name.
This method removes the type entry for the specified class_name. An exception is thrown if this object type does not have that class_name.
- Parameters
label – Class name to remove.
- Throws
std::runtime_error – If supplied class_name is not associated with this object.
-
std::vector<std::string> class_names(double threshold = INVALID_SCORE) const¶
Get list of class_names for this object.
This method returns a vector of class_names that apply to this object. The names are ordered by decreasing score. If an optional threshold value is supplied, then names with a score not less than that value are included in the returned list.
- Parameters
threshold – If a value is supplied, labels with a score below this value are omitted from the returned list.
- Returns
Ordered list of class_names. Note that the list may be empty.
-
size_t size() const¶
Get number of class names on this object.
This method returns the number of class names that are in this object type.
- Returns
Number of registered class names.
Public Static Functions
-
static std::vector<std::string> all_class_names()¶
Get list of all class_names in use.
This method returns an ordered vector of all class_name strings. This set of strings represents the superset of all class_names used to classify objects. Strings are added to this set when a previously unseen class_name is passed to the CTOR or
- Returns
Vector of class names.
Public Static Attributes
-
static signal<std::string const&> class_name_added¶
Signal emitted when a new type name is created.
This signal is emitted whenever a new type name is seen for the first time. Applications which need to perform some function when this occurs may do so by connecting to this signal. The name of the new type is passed to the slot.
Warning
Connected slots execute on whichever thread caused the creation of a new detected object type name. This thread should generally be treated as arbitrary, and the slot coded accordingly. Note also that it may be important for performance that the slot does not take a long time to execute.
-
class_const_iterator_t begin() const¶
Activity Type¶
Warning
doxygenclass: Cannot find class “kwiver::vital::activity_type” in doxygen xml output for project “kwiver” from directory: ./_build/xml
Detected Object Type¶
Warning
doxygenclass: Cannot find class “kwiver::vital::detected_object_type” in doxygen xml output for project “kwiver” from directory: ./_build/xml
Bounding Box¶
-
template<typename T>
class bounding_box¶ Coordinate aligned bounding box.
This class represents a coordinate aligned box. The coordinate system places the origin in the upper left.
A bounding box must be constructed with the correct geometry. Once created, the geometry can not be altered.
Public Functions
-
inline bounding_box(vector_type const &upper_left, vector_type const &lower_right)¶
Create box from two corner points.
- Parameters
upper_left – Upper left corner of box.
lower_right – Lower right corner of box.
-
inline bounding_box(vector_type const &upper_left, T width, T height)¶
Create box from point and dimensions.
- Parameters
upper_left – Upper left corner point
width – Width of box.
height – Height of box.
-
inline bounding_box(T xmin, T ymin, T xmax, T ymax)¶
Create a box from four coordinates.
- Parameters
xmin – Minimum x coordinate
ymin – Minimum y coordinate
xmax – Maximum x coordinate
ymax – Maximum y coordinate
-
inline bounding_box()¶
Create default (invalid) box.
-
inline bool is_valid() const¶
Check to see if the two corner points are valid.
- Returns
true if the box is valid
-
inline void reset()¶
Reset the bounding box to an initial invalid state.
-
inline vector_type center() const¶
Get center coordinate of box.
- Returns
Center coordinate of box.
-
inline vector_type upper_left() const¶
Get upper left coordinate of box.
- Returns
Upper left coordinate of box.
-
inline vector_type lower_right() const¶
Get lower right coordinate of box.
- Returns
Lower right coordinate of box.
-
inline double area() const¶
Get area of box.
- Returns
Area of box.
-
inline bool contains(vector_type const &pt) const¶
Check if point inside box.
- Returns
true if point is inside box
-
inline bounding_box(vector_type const &upper_left, vector_type const &lower_right)¶
Descriptor¶
-
class descriptor¶
A representation of a feature descriptor used in matching.
Subclassed by kwiver::vital::descriptor_array_of< T >
Public Functions
-
virtual ~descriptor() = default¶
Destructor.
-
virtual std::type_info const &data_type() const = 0¶
Access the type info of the underlying data (double or float)
-
virtual std::size_t size() const = 0¶
The number of elements of the underlying type.
-
virtual std::size_t num_bytes() const = 0¶
The number of bytes used to represent the data.
-
virtual const byte *as_bytes() const = 0¶
Return the descriptor as pointer to bytes
Subclasses should ensure this always works by storing the data as a continuous byte array. Note that as_bytes returns a pointer to the underlying data while as_double returns a vector of doubles which will be copied from the underlying data if possible. As_bytes is written this way for speed (no copying) at the cost of being restrictive on sub-classes in terms of the way they lay out their descriptors in memory.
-
virtual std::vector<double> as_double() const = 0¶
Return the descriptor as a vector of doubles
Return an empty vector if this makes no sense for the underlying type.
-
inline bool operator==(descriptor const &other) const¶
Equality operator.
-
inline bool operator!=(descriptor const &other) const¶
Inequality operator.
-
inline virtual unsigned int node_id() const¶
Returns the node_id for the descriptor.
The node_id is generally the vocabulary tree leaf index computed when the descriptor is quantized in the tree. Two features with the same node_id are expected to have similar visual appearance.
- inline virtual bool set_node_id (VITAL_UNUSED unsigned int node_id)
Sets the node_id for the descriptor.
By default this returns false because this base class has nowhere to store the node_id. Derived classes that do store the node_id should return true if it successfully stored.
-
virtual ~descriptor() = default¶
Image Object Detector Algorithm¶
Instantiate with:
kwiver::vital::algo::image_object_detector_sptr detector = kwiver::vital::algo::image_object_detector::create("<impl_name>");
Arrow & Configuration |
<impl_name> options |
CMake Flag to Enable |
---|---|---|
example_detector |
KWIVER_ENABLE_ARROWS |
|
hough_circle |
KWIVER_ENABLE_OPENCV |
|
darknet |
KWIVER_ENABLE_DARKNET |
-
class image_object_detector : public kwiver::vital::algorithm_def<image_object_detector>¶
Image object detector base class/.
Subclassed by kwiver::arrows::core::create_detection_grid, kwiver::arrows::core::example_detector, kwiver::arrows::darknet::darknet_detector, kwiver::arrows::matlab::matlab_image_object_detector, kwiver::arrows::ocv::detect_heat_map, kwiver::arrows::ocv::hough_circle_detector
Public Functions
-
virtual detected_object_set_sptr detect(image_container_sptr image_data) const = 0¶
Find all objects on the provided image
This method analyzes the supplied image and along with any saved context, returns a vector of detected image objects.
- Parameters
image_data – the image pixels
- Returns
vector of image objects found
Public Static Functions
-
static inline std::string static_type_name()¶
Return the name of this algorithm.
-
virtual detected_object_set_sptr detect(image_container_sptr image_data) const = 0¶
Train Detector Algorithm¶
Instantiate with:
kwiver::vital::algo::train_detector_sptr trainer = kwiver::vital::algo::train_detector::create("<impl_name>");
Arrow & Configuration |
<impl_name> options |
CMake Flag to Enable |
---|---|---|
darknet |
KWIVER_ENABLE_DARKNET |
-
class train_detector : public kwiver::vital::algorithm_def<train_detector>¶
An abstract base class for training object detectors.
Subclassed by kwiver::arrows::darknet::darknet_trainer
Public Functions
-
virtual void train_from_disk(vital::category_hierarchy_sptr object_labels, std::vector<std::string> train_image_names, std::vector<kwiver::vital::detected_object_set_sptr> train_groundtruth, std::vector<std::string> test_image_names = std::vector<std::string>(), std::vector<kwiver::vital::detected_object_set_sptr> test_groundtruth = std::vector<kwiver::vital::detected_object_set_sptr>())¶
Train a detection model given a list of images and detections
This varient is geared towards offline training.
- Parameters
object_labels – object category labels for training
train_image_list – list of train image filenames
train_groundtruth – annotations loaded for each image
test_image_list – list of test image filenames
test_groundtruth – annotations loaded for each image
-
virtual void train_from_memory(vital::category_hierarchy_sptr object_labels, std::vector<kwiver::vital::image_container_sptr> train_images, std::vector<kwiver::vital::detected_object_set_sptr> train_groundtruth, std::vector<kwiver::vital::image_container_sptr> test_images = std::vector<kwiver::vital::image_container_sptr>(), std::vector<kwiver::vital::detected_object_set_sptr> test_groundtruth = std::vector<kwiver::vital::detected_object_set_sptr>())¶
Train a detection model given images and detections
This varient is geared towards online training, and is not required to be defined.
- Throws
runtime_exception – if not defined.
- Parameters
object_labels – object category labels for training
train_images – vector of input train images
train_groundtruth – annotations loaded for each train image
test_images – optional vector of input test images
test_groundtruth – optional annotations loaded for each test image
Public Static Functions
-
static inline std::string static_type_name()¶
Return the name of this algorithm.
-
virtual void train_from_disk(vital::category_hierarchy_sptr object_labels, std::vector<std::string> train_image_names, std::vector<kwiver::vital::detected_object_set_sptr> train_groundtruth, std::vector<std::string> test_image_names = std::vector<std::string>(), std::vector<kwiver::vital::detected_object_set_sptr> test_groundtruth = std::vector<kwiver::vital::detected_object_set_sptr>())¶
Detected Object Filter Algorithm¶
Instantiate with:
kwiver::vital::algo::detected_object_filter_sptr filter = kwiver::vital::algo::detected_object_filter::create("<impl_name>");
Arrow & Configuration |
<impl_name> options |
CMake Flag to Enable |
---|---|---|
class_probablity_filter |
KWIVER_ENABLE_ARROWS |
-
class detected_object_filter : public kwiver::vital::algorithm_def<detected_object_filter>¶
An abstract base class for filtering sets of detected objects.
A detected object filter accepts a set of detections and produces another set of detections. The output set may be different from the input set. It all depends on the actual implementation. In any case, the input detection set shall be unmodified.
Subclassed by kwiver::arrows::core::class_probablity_filter, kwiver::arrows::core::transfer_bbox_with_depth_map, kwiver::arrows::core::transform_detected_object_set
Public Functions
-
virtual detected_object_set_sptr filter(const detected_object_set_sptr input_set) const = 0¶
Filter set of detected objects.
This method applies a filter to the input set to create an output set. The input set of detections is unmodified.
- Parameters
input_set – Set of detections to be filtered.
- Returns
Filtered set of detections.
Public Static Functions
-
static inline std::string static_type_name()¶
Return the name of this algorithm.
-
virtual detected_object_set_sptr filter(const detected_object_set_sptr input_set) const = 0¶
Draw Detected Object Set Algorithm¶
Instantiate with:
kwiver::vital::algo::draw_detected_object_set_sptr draw = kwiver::vital::algo::draw_detected_object_set::create("<impl_name>");
Arrow & Configuration |
<impl_name> options |
CMake Flag to Enable |
---|---|---|
ocv |
KWIVER_ENABLE_OPENCV |
-
class draw_detected_object_set : public kwiver::vital::algorithm_def<draw_detected_object_set>¶
An abstract base class for algorithms which draw tracks on top of images in various ways, for analyzing results.
Subclassed by kwiver::arrows::ocv::draw_detected_object_set
Public Functions
-
virtual kwiver::vital::image_container_sptr draw(kwiver::vital::detected_object_set_sptr detected_set, kwiver::vital::image_container_sptr image) = 0¶
Draw detected object boxes on Image.
This method draws the detections on a copy of the image. The input image is unmodified. The actual boxes that are drawn are controlled by the configuration for the implementation.
- Parameters
detected_set – Set of detected objects
image – Boxes are drawn in this image
- Returns
Image with boxes and other annotations added.
Public Static Functions
-
static inline std::string static_type_name()¶
Return the name of this algorithm.
-
virtual kwiver::vital::image_container_sptr draw(kwiver::vital::detected_object_set_sptr detected_set, kwiver::vital::image_container_sptr image) = 0¶
Detected Object Set Input Algorithm¶
Instantiate with:
kwiver::vital::algo::detected_object_set_input_sptr detec_in = kwiver::vital::algo::detected_object_set_input::create("<impl_name>");
Arrow & Configuration |
<impl_name> options |
CMake Flag to Enable |
---|---|---|
csv |
KWIVER_ENABLE_ARROWS |
|
kw18 |
KWIVER_ENABLE_ARROWS |
-
class detected_object_set_input : public kwiver::vital::algorithm_def<detected_object_set_input>¶
Read detected object sets.
This class is the abstract base class for the detected object set writer.
Detection sets from multiple images are stored in a single file with enough information to recreate a unique image identifier, usually the file name, and an associated set of detections.
Subclassed by kwiver::arrows::core::detected_object_set_input_csv, kwiver::arrows::core::detected_object_set_input_kw18, kwiver::arrows::core::detected_object_set_input_simulator, kwiver::arrows::kpf::detected_object_set_input_kpf
Public Functions
-
virtual void open(std::string const &filename)¶
Open a file of detection sets.
This method opens a detection set file for reading.
- Parameters
filename – Name of file to open
- Throws
kwiver::vital::path_not_exists – Thrown when the given path does not exist.
kwiver::vital::path_not_a_file – Thrown when the given path does not point to a file (i.e. it points to a directory).
kwiver::vital::file_not_found_exception –
-
void use_stream(std::istream *strm)¶
Read detections from an existing stream
This method specifies the input stream to use for reading detections. Using a stream is handy when the detections are available in a stream format.
- Parameters
strm – input stream to use
-
virtual void close()¶
Close detection set file.
The currently open detection set file is closed. If there is no currently open file, then this method does nothing.
-
virtual bool read_set(kwiver::vital::detected_object_set_sptr &set, std::string &image_name) = 0¶
Read next detected object set
This method reads the next set of detected objects from the file. False is returned when the end of file is reached.
- Parameters
set – [out] Pointer to the new set of detections. Set may be empty if there are no detections on an image.
image_name – [out] Name of the image that goes with the detections. This string may be empty depending on the source format.
- Returns
true if detections are returned, false if end of file.
-
bool at_eof() const¶
Determine if input file is at end of file.
This method reports the end of file status for a file open for reading.
- Returns
true if file is at end.
Public Static Functions
-
static inline std::string static_type_name()¶
Return the name of this algorithm.
-
virtual void open(std::string const &filename)¶
Detected Object Set Output Algorithm¶
Instantiate with:
kwiver::vital::algo::detected_object_set_output_sptr detec_out = kwiver::vital::algo::detected_object_set_output::create("<impl_name>");
Arrow & Configuration |
<impl_name> options |
CMake Flag to Enable |
---|---|---|
csv |
KWIVER_ENABLE_ARROWS |
|
kw18 |
KWIVER_ENABLE_ARROWS |
-
class detected_object_set_output : public kwiver::vital::algorithm_def<detected_object_set_output>¶
Read and write detected object sets.
This class is the abstract base class for the detected object set reader and writer.
Detection sets from multiple images are stored in a single file with enough information to recreate a unique image identifier, usually the file name, and an associated wet of detections.
Subclassed by kwiver::arrows::core::detected_object_set_output_csv, kwiver::arrows::core::detected_object_set_output_kw18, kwiver::arrows::kpf::detected_object_set_output_kpf, kwiver::arrows::matlab::matlab_detection_output
Public Functions
-
virtual void open(std::string const &filename)¶
Open a file of detection sets.
This method opens a detection set file for writing.
- Parameters
filename – Name of file to open
- Throws
kwiver::vital::path_not_exists – Thrown when the given path does not exist.
kwiver::vital::path_not_a_file – Thrown when the given path does not point to a file (i.e. it points to a directory).
-
void use_stream(std::ostream *strm)¶
Write detections to an existing stream
This method specifies the output stream to use for writing detections. Using a stream is handy when the detections output is available in a stream format.
- Parameters
strm – output stream to use
-
virtual void close()¶
Close detection set file.
The currently open detection set file is closed. If there is no currently open file, then this method does nothing.
-
virtual void write_set(const kwiver::vital::detected_object_set_sptr set, std::string const &image_path) = 0¶
Write detected object set.
This method writes the specified detected object set and image name to the currently open file.
- Parameters
set – Detected object set
image_path – File path to image associated with the detections.
-
inline virtual void complete()¶
Perform end-of-stream actions.
This method writes any necessary final data to the currently open file.
Public Static Functions
-
static inline std::string static_type_name()¶
Return the name of this algorithm.
-
virtual void open(std::string const &filename)¶
Code Example¶
// Many vision algorithms are used to detect and identify items in an image.
// Detectors are any class that implements the kwiver::vital::algo::image_object_detector interface
// In this example we will explore the detection data types.
// In the following section we will create dummy data in the data types in lieu of running a detection algorithm
// First, Load an image (see how_to_part_01_images)
kwiver::vital::algo::image_io_sptr ocv_io = kwiver::vital::algo::image_io::create("ocv");
kwiver::vital::image_container_sptr ocv_img = ocv_io->load("./soda_circles.jpg");
// Now let's run a detection algorithm that comes with kwiver
kwiver::vital::algo::image_object_detector_sptr detector = kwiver::vital::algo::image_object_detector::create("hough_circle");
kwiver::vital::detected_object_set_sptr hough_detections = detector->detect(ocv_img);
// We can take this detection set and create a new image with the detections overlaid on the image
kwiver::vital::algo::draw_detected_object_set_sptr drawer = kwiver::vital::algo::draw_detected_object_set::create("ocv");
drawer->set_configuration(drawer->get_configuration());// This will default the configuration
kwiver::vital::image_container_sptr hough_img = drawer->draw(hough_detections, ocv_img);
// Let's see what it looks like
cv::Mat hough_mat = kwiver::arrows::ocv::image_container::vital_to_ocv(hough_img->get_image(), kwiver::arrows::ocv::image_container::RGB_COLOR);
cv::namedWindow("Hough Detections", cv::WINDOW_AUTOSIZE);// Create a window for display.
cv::imshow("Hough Detections", hough_mat); // Show our image inside it.
cv::waitKey(5);
kwiversys::SystemTools::Delay(2000); // Wait for 2s
cv::destroyWindow("Hough Detections");
// Next, let's look at the detection data structures and we can make them
// General detection data is defined by the detected_object class
// Detectors will take in an image and return a detected_object_set_sptr object
// A detected_object_set_sptr is comprised of the following data:
// A bounding box
// bounding_box_d is a double based box where the top left and bottom right corners are specificed as TODO pixel index?
// The top left corner is the anchor. A bounding_box_i is interger based to associate corners to pixels in the image
kwiver::vital::bounding_box_d bbox1(ocv_img->width()*0.25, ocv_img->height()*0.25,
ocv_img->width()*0.75, ocv_img->height()*0.75);
// The confidence value is the confidence associated with the detection.
// It should be a probability (0..1) that the detector is sure that it has identified what it is supposed to find.
double confidence1 = 1.0;
// A Classification
// The detected_object_type is created by a classifier which is sometimes part of the detector.
// It is a group of name / value pairs.The name being the name of the class.
// The score is the probability that the object is that class.
// It is optional and not required for a detected object although most examples provide one just to be complete.
kwiver::vital::detected_object_type_sptr type1(new kwiver::vital::detected_object_type());
// This can have multiple entries / scores
type1->set_score("car", 0.03);
type1->set_score("fish", 0.52);
type1->set_score("flag pole", 0.23);
// Put it all together to make a detection
kwiver::vital::detected_object_sptr detection1(new kwiver::vital::detected_object(bbox1, confidence1, type1));
detection1->set_detector_name("center");
// Let's add a few more detections to our detection set and write it out in various formats
kwiver::vital::bounding_box_d bbox2(ocv_img->width()*0.05, ocv_img->height()*0.05,
ocv_img->width()*0.55, ocv_img->height()*0.55);
double confidence2 = 0.50;
kwiver::vital::detected_object_type_sptr type2(new kwiver::vital::detected_object_type());
type2->set_score("car", 0.04);
type2->set_score("fish", 0.12);
type2->set_score("flag pole", 0.67);
kwiver::vital::detected_object_sptr detection2(new kwiver::vital::detected_object(bbox2, confidence2, type2));
detection2->set_detector_name("upper left");
kwiver::vital::bounding_box_d bbox3(ocv_img->width()*0.45, ocv_img->height()*0.45,
ocv_img->width()*0.95, ocv_img->height()*0.95);
double confidence3 = 0.75;
kwiver::vital::detected_object_type_sptr type3(new kwiver::vital::detected_object_type());
type3->set_score("car", 0.22);
type3->set_score("fish", 0.08);
type3->set_score("flag pole", 0.07);
kwiver::vital::detected_object_sptr detection3(new kwiver::vital::detected_object(bbox3, confidence3, type3));
detection3->set_detector_name("lower right");
// Group multiple detections for an image in a set object
kwiver::vital::detected_object_set_sptr detections(new kwiver::vital::detected_object_set());
detections->add(detection1);
detections->add(detection2);
detections->add(detection3);
kwiver::vital::image_container_sptr img_detections = drawer->draw(detections, ocv_img);
// Let's see what it looks like
cv::Mat mat = kwiver::arrows::ocv::image_container::vital_to_ocv(img_detections->get_image(), kwiver::arrows::ocv::image_container::RGB_COLOR);
cv::namedWindow("Detections", cv::WINDOW_AUTOSIZE);// Create a window for display.
cv::imshow("Detections", mat); // Show our image inside it.
cv::waitKey(5);
kwiversys::SystemTools::Delay(2000); // Wait for 2s
cv::destroyWindow("Detections");
kwiver::vital::algo::detected_object_set_output_sptr kpf_writer = kwiver::vital::algo::detected_object_set_output::create("kpf_output");
kwiver::vital::algo::detected_object_set_input_sptr kpf_reader = kwiver::vital::algo::detected_object_set_input::create("kpf_input");
if (kpf_writer == nullptr)
{
std::cerr << "Make sure you have built the kpf arrow, which requires fletch to have yaml" << std::endl;
}
else
{
kpf_writer->open("detected_object_set.kpf");
kpf_writer->write_set(detections, "");
// Now let's read the kpf data back in
std::string image_name;
kwiver::vital::detected_object_set_sptr kpf_detections;
kpf_reader->open("detected_object_set.kpf");
kpf_reader->read_set(kpf_detections, image_name);
auto ie = kpf_detections->cend();
for (auto det = kpf_detections->cbegin(); det != ie; ++det)
{
const kwiver::vital::bounding_box_d bbox((*det)->bounding_box());
std::stringstream ss;
ss << "detector_name " << (*det)->detector_name() << "\n"
<< "bounding box :" << "x1(" << bbox.min_x() << ") y1(" << bbox.min_y() << ") x2(" << bbox.max_x() << ") y2(" << bbox.max_y() << ") \n"
<< "confidence : " << (*det)->confidence() << "\n"
<< "classifications : " << "\n";
for (auto t : *(*det)->type())
ss << "\t type : " << t.first << " " << t.second;
std::cout << ss.str();
}
}
}