Classes | |
| class | BOX |
| class | DETECTION |
| class | DETNUMPAIR |
| class | IMAGE |
Functions | |
| bbox2points (bbox) | |
| class_colors (names) | |
| decode_detection (detections) | |
| detect_image (network, class_names, image, thresh=.5, hier_thresh=.5, nms=.45) | |
| draw_boxes (detections, image, colors) | |
| load_network (config_file, data_file, weights, batch_size=1) | |
| network_dimensions (net) | |
| network_height (net) | |
| network_width (net) | |
| non_max_suppression_fast (detections, overlap_thresh) | |
| print_detections (detections, coordinates=False) | |
| remove_negatives (detections, class_names, num) | |
| remove_negatives_faster (detections, class_names, num) | |
Variables | |
| add_skipped_class = lib.darknet_add_skipped_class | |
| argtypes | |
| clear_skipped_classes = lib.darknet_clear_skipped_classes | |
| copy_image_from_bytes = lib.copy_image_from_bytes | |
| del_skipped_class = lib.darknet_del_skipped_class | |
| do_nms_obj = lib.do_nms_obj | |
| do_nms_sort = lib.do_nms_sort | |
| free_detections = lib.free_detections | |
| free_image = lib.free_image | |
| free_network_ptr = lib.free_network_ptr | |
| free_ptrs = lib.free_ptrs | |
| get_network_boxes = lib.get_network_boxes | |
| lib = CDLL(libpath, RTLD_GLOBAL) | |
| str | libpath = "/usr/lib/libdarknet.so" |
| load_image = lib.load_image_v2 | |
| load_net = lib.load_network | |
| load_net_custom = lib.load_network_custom | |
| make_image = lib.make_image | |
| make_network_boxes = lib.make_network_boxes | |
| network_dimensions = lib.darknet_network_dimensions | |
| network_predict = lib.network_predict_ptr | |
| predict = lib.network_predict_ptr | |
| predict_image = lib.network_predict_image | |
| predict_image_letterbox = lib.network_predict_image_letterbox | |
| reset_rnn = lib.reset_rnn | |
| restype | |
| set_gpu = lib.cuda_set_device | |
| set_output_stream = lib.darknet_set_output_stream | |
| set_verbose = lib.darknet_set_verbose | |
| show_version_info = lib.darknet_show_version_info | |
| version_short = lib.darknet_version_short | |
| version_string = lib.darknet_version_string | |
Python 3 wrapper for identifying objects in images Running the script requires opencv-python to be installed, via either of these two options: - sudo apt-get install python3-opencv - pip3 install opencv-python NOTE: As of December 2023 while using Ubuntu 22.04, the apt-get install one was better since the pip3 one would result in a known segfault when cv2.imshow() was called: https://github.com/opencv/opencv-python/issues/794 Directly viewing or returning bounding-boxed images requires scikit-image to be installed: - pip3 install scikit-image See the example code (such as "example.py") which imports this module.
| darknet.bbox2points | ( | bbox | ) |
Convert bounding box from YOLO format to corner points in CV2 rectangle format.

| darknet.class_colors | ( | names | ) |
Create a dict with a deterministic, yet 'random', BGR color for each class name. This function uses a hash of the class name to generate consistent colors.

| darknet.decode_detection | ( | detections | ) |
Decode detection results and format confidence scores.
Args:
detections: List of detected objects, each represented as (label, confidence, bbox).
Returns:
List of decoded detection results with formatted confidence scores.

| darknet.detect_image | ( | network, | |
| class_names, | |||
| image, | |||
thresh = .5, |
|||
hier_thresh = .5, |
|||
nms = .45 |
|||
| ) |
Returns a list with the highest confidence class and their bounding box.
Args:
network: Darknet network.
class_names: List of class names.
image: Input image.
thresh: Detection confidence threshold.
hier_thresh: Hierarchical threshold.
nms: Non-Maximum Suppression threshold.
Returns:
List of detections with class name, confidence, and bounding box.


| darknet.draw_boxes | ( | detections, | |
| image, | |||
| colors | |||
| ) |
Draw bounding boxes on an image.
Args:
detections: List of detected objects, each represented as (label, confidence, bbox).
image: Input image.
colors: Dictionary of colors for each class label.
Returns:
Image with bounding boxes drawn.


| darknet.load_network | ( | config_file, | |
| data_file, | |||
| weights, | |||
batch_size = 1 |
|||
| ) |
load model description and weights from config files
args:
config_file (str): path to .cfg model file
data_file (str): path to .data model file
weights (str): path to weights
returns:
network: trained model
| darknet.network_dimensions | ( | net | ) |
| darknet.network_height | ( | net | ) |

| darknet.network_width | ( | net | ) |

| darknet.non_max_suppression_fast | ( | detections, | |
| overlap_thresh | |||
| ) |
Apply non-maximum suppression (NMS) to a list of detections.
Args:
detections: List of detected objects, where each detection is represented as a tuple
(label, confidence, (x, y, w, h)).
overlap_thresh: Threshold for considering overlap between bounding boxes.
Returns:
List of selected detections after NMS.
| darknet.print_detections | ( | detections, | |
coordinates = False |
|||
| ) |
Print detected objects and their confidence scores.
Args:
detections: List of detected objects, each represented as (label, confidence, bbox).
coordinates: If True, also print bounding box coordinates.
Prints:
Detected objects with or without bounding box coordinates.

| darknet.remove_negatives | ( | detections, | |
| class_names, | |||
| num | |||
| ) |
Remove all classes with 0% confidence within the detection.
Args:
detections: List of detections, where each detection is an object with confidence scores for classes.
class_names: List of class names.
num: Number of detections.
Returns:
List of valid predictions with class name, confidence, and bounding box.

| darknet.remove_negatives_faster | ( | detections, | |
| class_names, | |||
| num | |||
| ) |
Faster version of remove_negatives (very useful when using yolo9000).
Args:
detections: List of detections, where each detection is an object with confidence scores for classes.
class_names: List of class names.
num: Number of detections.
Returns:
List of valid predictions with class name, confidence, and bounding box.
| darknet.add_skipped_class = lib.darknet_add_skipped_class |
| darknet.argtypes |
| darknet.clear_skipped_classes = lib.darknet_clear_skipped_classes |
| darknet.copy_image_from_bytes = lib.copy_image_from_bytes |
| darknet.del_skipped_class = lib.darknet_del_skipped_class |
| darknet.do_nms_obj = lib.do_nms_obj |
| darknet.do_nms_sort = lib.do_nms_sort |
| darknet.free_detections = lib.free_detections |
| darknet.free_image = lib.free_image |
| darknet.free_network_ptr = lib.free_network_ptr |
| darknet.free_ptrs = lib.free_ptrs |
| darknet.get_network_boxes = lib.get_network_boxes |
| darknet.lib = CDLL(libpath, RTLD_GLOBAL) |
| str darknet.libpath = "/usr/lib/libdarknet.so" |
| darknet.load_image = lib.load_image_v2 |
| darknet.load_net = lib.load_network |
| darknet.load_net_custom = lib.load_network_custom |
| darknet.make_image = lib.make_image |
| darknet.make_network_boxes = lib.make_network_boxes |
| darknet.network_dimensions = lib.darknet_network_dimensions |
| darknet.network_predict = lib.network_predict_ptr |
| darknet.predict = lib.network_predict_ptr |
| darknet.predict_image = lib.network_predict_image |
| darknet.predict_image_letterbox = lib.network_predict_image_letterbox |
| darknet.reset_rnn = lib.reset_rnn |
| darknet.restype |
| darknet.set_gpu = lib.cuda_set_device |
| darknet.set_output_stream = lib.darknet_set_output_stream |
| darknet.set_verbose = lib.darknet_set_verbose |
| darknet.show_version_info = lib.darknet_show_version_info |
| darknet.version_short = lib.darknet_version_short |
| darknet.version_string = lib.darknet_version_string |