This page define the C-language interface to SOD. This is not a tutorial. The API documentation is designed to be precise. Not easy to read. For a tutorial introduction, please refer to:
This version of the C-language interface reference is broken down into small pages for easy viewing.
Exported Objects
This is a list of all abstract objects and datatypes exported & manipulated by SOD:
Compile-Time Directives
Compile-time directives to omit/enable features not provided in the default build:
Exported Functions
The SOD API is broken down into five independent categories:
CNN/RNN Interfaces
CNN/RNN Training Interfaces
RealNets Interfaces
RealNets Training Interfaces
Image/Frame Processing Interfaces
Raw Pixels Access & Conversion Interfaces
Image Creation & Blob Loading/Saving Interfaces
OpenCV Integration Interfaces
Miscellaneous
This is a list of all abstract objects and datatypes exported by the SOD library. There are few objects, but most applications only use a handful.
typedef struct sod_cnn sod_cnn;
An instance of the opaque sod_cnn structure hold all layers of a standard Convolutional Neural Network (CNN) or Recurrent Neural Network (RNN). The syntax is based on the darknet framework and the task vary depending on the specified architecture (i.e. object detection & classification for CNN, text generation for RNN). The life of a sod_cnn instance goes something like this:
typedef struct sod_realnet sod_realnet;
RealNets are simple container for multiple neural networks architecture and were introduced to the public in the first release of SOD. By taking advantage of each network architecture since most of them are specialized (i.e. CNNs for object classification, ANNs for pattern extraction and so forth) and stack one network on top of another, one could achieve amazing results. For example detecting & extracting facial shapes has never been easier and quick (few milliseconds) by stacking up together in a RealNets container a set of decision trees and a simple Artificial Neural Network. The life of a sod_realnet instance goes something like this:
Notice that RealNets are designed to analyze & extract useful information from video stream rather than static images thanks to their fast processing speed (less than 10 milliseconds on 1920*1080 HD stream) and low memory footprint making them suitable for use on mobile devices. You are encouraged to connect the RealNets APIs with the OpenCV Video capture interfaces or any proprietary Video capture API to see them in action.
typedef struct sod_img sod_img;
struct sod_img {
int h; /* Image/frame height */
int w; /* Image/frame width */
int c; /* Image depth/Total number of color channels e.g. 1 for grayscale images, 3 RGB, etc. */
float *data; /* Blob */
};
Internally, each in-memory representation of an input image or video frame is kept in an instance of the sod_img structure. Basically, a sod_img is just a record of the width, height and number of color channels in an image, and also the pixel values for every pixel. Images pixels are arranged in CHW format. This means in a 3 channel image with width 400 and height 300, the first 400 values are the 1st row of the 1st channel of the image. The second 400 pixels are the 2nd row. after 120,000 values we get to pixels in the 2nd channel, and so forth.
Practically, all the exported interfaces deal with a sod_img instance and over 70 interfaces provide advanced image/frame processing routines. These includes sod_canny_edge_image(), sod_hilditch_thin_image(), sod_hough_lines_detect()
, sod_image_find_blobs(), sod_otsu_binarize_image(), sod_crop_image(), sod_resize_image(), sod_dilate_image(), sod_image_draw_bbox() and so forth. You are invited to take a look at the list of image processing interfaces for their complete documentation.
A sod_img can be loaded from disk via sod_img_load_from_file(), from memory (i.e. network socket) using sod_img_load_from_mem() or dynamically created via sod_make_image(). An OpenCV compile-time directive is provided to help you integrate OpenCV with SOD. When enabled, primitives such as sod_img_load_cv_ipl(), sod_img_load_from_cv_stream() and so on are available to call. This let you record video frames from external sources such as your Webcam, CCTV , etc. and convert them back to a working sod_img instance.
Raw pixels values can be manipulated via a set of public interfaces such as sod_img_add_pixel(), sod_img_get_pixel(), sod_img_set_pixel(), etc. or directly via the data pointer member of this structure. In that case, you have to be careful of the target pixel location that must be in range unlike the exposed public interfaces that take care of checking range location for you.
typedef struct sod_box sod_box;
struct sod_box {
int x; /* The x-coordinate of the upper-left corner of the rectangle */
int y; /* The y-coordinate of the upper-left corner of the rectangle */
int w; /* Rectangle width */
int h; /* Rectangle height */
float score; /* Confidence threshold. A value between 0..1 */
const char *zName; /* Detected object name. I.e. person, face, dog, car, plane, cat, bicycle, etc. */
void *pUserData; /* External pointer used by some modules such as the face landmarks, NSFW classifier, pose estimator, etc. */
};
A bounding box or bbox for short is represented by an instance of the sod_box structure. A sod_box instance always store the coordinates of a rectangle obtained from a prior successful call to one of the object detection routines of a sod_cnn or sod_realnet handle such as sod_cnn_predict() or from the connected component labeling interface sod_image_find_blobs(). Besides the rectangle coordinates, the zName and score fields member of this structure hold useful information about the object it surround.
Finally, the drawing interfaces sod_image_draw_bbox(), sod_image_draw_bbox_width(), sod_image_draw_box(), sod_image_draw_box_grayscale() or sod_crop_image() let you draw/extract a rectangle on/from an input image using the sod_box coordinates.
typedef struct sod_pts sod_pts;
struct sod_pts {
int x; /* The x-coordinate, in logical units of the point offset. */
int y; /* The y-coordinate, in logical units of the point offset. */
};
An instance of the sod_pts structure describe a 2D point in space with integer coordinates (usually zero-based). This structure is rarely manipulated by SOD and is used mostly by the Hough line detection interface sod_hough_lines_detect() and line drawing routine sod_image_draw_line().
typedef struct sod_realnet_trainer sod_realnet_trainer;
An instance of sod_realnet_trainer is used for training RealNet models on a modern CPU. The life of this handle goes as follows:
typedef unsigned int sod_realnet_model_handle;
Since Realnets are just container for various neural networks architecture, each loaded & registered network is given an unique ID returned via calls to sod_realnet_load_model_from_mem() or sod_realnet_load_model_from_disk(). With this in hand, you can configure your network via sod_realnet_model_config() by passing the handle ID which uniquely identify the target network to configure.
For most purposes, SOD can be built just fine using the default compilation options. However, if required, the compile-time options documented below can be used to omit SOD features such as the CNN/RNN layer which consume a lot of memory or to integrate SOD with other libraries such as OpenCV. Every effort has been made to ensure that the various combinations of compilation options work harmoniously and produce a working library.
Introduced in version 1.1.9
If this directive is defined, memory mapping is omitted from the build. This is particularly useful for restricted embedded devices lacking memory mapping.
Introduced in version 1.1.9
If this directive is defined, the entire RealNets interfaces are omitted from the build.
Introduced in version 1.1.9
Define this directive if you are targeting a non Windows/UNIX (Linux, Mac, BSD, etc.) Operating System.
If this directive is defined, built-in OpenCV integration interfaces such as sod_img_load_cv_ipl(), sod_img_load_from_cv(), sod_img_load_from_cv_stream(), sod_img_fill_from_cv_stream(), sod_img_save_to_cv_jpg() are included in the build. In which case, you need to link your code against OpenCV and adjust the OpenCV include paths accordingly.
If this directive is defined, all built-in image reading interfaces such as sod_img_load_from_file(), sod_img_load_from_mem(), sod_img_set_load_from_directory(), etc. are omitted from the build. In which case, you have to rely on your own code to read images from external sources and convert them back to a working sod_img object.
If this directive is defined, all built-in image writing interfaces such as sod_img_save_as_png() or sod_img_blob_save_as_png() are omitted from the build. In which case, you have to rely on your own code (take a look at the OpenCV integration interfaces) to write a sod_img object back to an external source.
If this directive is defined, the entire CNN/RNN layer and its exported interfaces such as sod_cnn_create(), sod_cnn_predict(), etc. are completely omitted from the build. You are aware that a CNN is a memory & CPU hog. The smallest CNN detection model consume about 75 ~ 160MB of RAM unlike the RealNet architecture which is memory efficient. In some cases where resources is limited, this directive is of particular interest if you want a small library footprint.
If this directive is defined, the RealNet training interfaces are included in the build. You'll be able to train your own RealNet models on the CPU using just few calls and your training dataset. RealNets training interfaces are documented here.