Darknet/YOLO v5.0-117-g31c55275-dirty
Object Detection Framework
 
Loading...
Searching...
No Matches
darknet Namespace Reference

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
 

Detailed Description

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.

Function Documentation

◆ bbox2points()

darknet.bbox2points (   bbox)
Convert bounding box from YOLO format to corner points in CV2 rectangle format.
Here is the caller graph for this function:

◆ class_colors()

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.
Here is the caller graph for this function:

◆ decode_detection()

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.
Here is the caller graph for this function:

◆ detect_image()

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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ draw_boxes()

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.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ load_network()

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

◆ network_dimensions()

darknet.network_dimensions (   net)

◆ network_height()

darknet.network_height (   net)
Here is the caller graph for this function:

◆ network_width()

darknet.network_width (   net)
Here is the caller graph for this function:

◆ non_max_suppression_fast()

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.

◆ print_detections()

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.
Here is the caller graph for this function:

◆ remove_negatives()

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.
Here is the caller graph for this function:

◆ remove_negatives_faster()

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.

Variable Documentation

◆ add_skipped_class

darknet.add_skipped_class = lib.darknet_add_skipped_class

◆ argtypes

darknet.argtypes

◆ clear_skipped_classes

darknet.clear_skipped_classes = lib.darknet_clear_skipped_classes

◆ copy_image_from_bytes

darknet.copy_image_from_bytes = lib.copy_image_from_bytes

◆ del_skipped_class

darknet.del_skipped_class = lib.darknet_del_skipped_class

◆ do_nms_obj

darknet.do_nms_obj = lib.do_nms_obj

◆ do_nms_sort

darknet.do_nms_sort = lib.do_nms_sort

◆ free_detections

darknet.free_detections = lib.free_detections

◆ free_image

darknet.free_image = lib.free_image

◆ free_network_ptr

darknet.free_network_ptr = lib.free_network_ptr

◆ free_ptrs

darknet.free_ptrs = lib.free_ptrs

◆ get_network_boxes

darknet.get_network_boxes = lib.get_network_boxes

◆ lib

darknet.lib = CDLL(libpath, RTLD_GLOBAL)

◆ libpath

str darknet.libpath = "/usr/lib/libdarknet.so"

◆ load_image

darknet.load_image = lib.load_image_v2

◆ load_net

darknet.load_net = lib.load_network

◆ load_net_custom

darknet.load_net_custom = lib.load_network_custom

◆ make_image

darknet.make_image = lib.make_image

◆ make_network_boxes

darknet.make_network_boxes = lib.make_network_boxes

◆ network_dimensions

darknet.network_dimensions = lib.darknet_network_dimensions

◆ network_predict

darknet.network_predict = lib.network_predict_ptr

◆ predict

darknet.predict = lib.network_predict_ptr

◆ predict_image

darknet.predict_image = lib.network_predict_image

◆ predict_image_letterbox

darknet.predict_image_letterbox = lib.network_predict_image_letterbox

◆ reset_rnn

darknet.reset_rnn = lib.reset_rnn

◆ restype

darknet.restype

◆ set_gpu

darknet.set_gpu = lib.cuda_set_device

◆ set_output_stream

darknet.set_output_stream = lib.darknet_set_output_stream

◆ set_verbose

darknet.set_verbose = lib.darknet_set_verbose

◆ show_version_info

darknet.show_version_info = lib.darknet_show_version_info

◆ version_short

darknet.version_short = lib.darknet_version_short

◆ version_string

darknet.version_string = lib.darknet_version_string