Algorithm options in OpenCV

OpenCV has many algorithms covering the same subject. When implementing a new processing pipeline, sometimes there is more than one choice for a step in the pipeline. For example, in Chapter 14, Explore Structure from Motion with the SfM Module, we made an arbitrary decision to use AKAZE features for finding landmarks between the images to estimate camera motion, and sparse 3D structure, however; there are many more kinds of 2D features available in OpenCV's features2D module. A more sensible mode of operation should have been to select the type of feature algorithm to use based on its performance, with respect to our needs. At the very least, we need to be aware of the different options.

Again, we looked to create a convenient way to see whether there are multiple options for the same task. We created a table where we list specific computer vision tasks that have multiple algorithm implementations in OpenCV. We also strived to mark whether algorithms have a common abstract API, and thus, easily and completely interchangeable within the code. While OpenCV offers the cv::Algorithm base class abstraction for most if not all of its algorithms, the abstraction is at a very high level and gives very little power to polymorphism and interchangeability. From our review, we exclude the machine learning algorithms (the ml module and the cv::StatsModel common API) since they are not proper computer vision algorithms, as well as low-level image processing algorithms, which do in fact have overlapping implementations (for example, the Hough detector family). We also exclude the GPU CUDA implementations that shadow several core topics such as object detection, background segmentation, 2D features, and more, since they are mostly replicas of the CPU implementations.

The following are topics with multiple implementations in OpenCV:

Topic Implementations Base API?

Optical flow

video module: SparsePyrLKOpticalFlow,  

FarnebackOpticalFlowDISOpticalFlow,  

VariationalRefinement

optflow contrib module: DualTVL1OpticalFlowOpticalFlowPCAFlow

Yes

Object tracking

track contrib module: TrackerBoosting,  

TrackerCSRTTrackerGOTURNTrackerKCF

TrackerMedianFlowTrackerMILTrackerMOSSE

TrackerTLD

External: DetectionBasedTracker

Yes1

Object detection

objdetect module: CascadeClassifier

HOGDescriptorQRCodeDetector,

linemod contrib module: Detector

aruco contrib module: aruco::detectMarkers

No2

 

2D features

OpenCV's most established common API.

features2D module: AgastFeatureDetector, AKAZE, BRISKFastFeatureDetector, GFTTDetector,

KAZE, MSER, ORB,

SimpleBlobDetector

xfeatures2D contrib module: BoostDescBriefDescriptorExtractor,

DAISY, FREAK, HarrisLaplaceFeatureDetector, LATCH, LUCIDMSDDetector, SIFT, StarDetector, SURF, VGG

Yes

Feature matching

BFMatcherFlannBasedMatcher

Yes

Background subtraction

video module: BackgroundSubtractorKNN

BackgroundSubtractorMOG2

bgsegm contrib module: BackgroundSubtractorCNT,  

BackgroundSubtractorGMGBackgroundSubtractorGSOC,  

BackgroundSubtractorLSBPBackgroundSubtractorMOG

Yes

Camera calibration

calib3d module: calibrateCamera,

calibrateCameraRO, stereoCalibrate

aruco contrib module: calibrateCameraArcuo, calibrateCameraCharuco

ccalib contrib module: omnidir::calibrate, omnidir::stereoCalibrate

No

Stereo reconstruction

calib3d module: StereoBM, StereoSGBM

stereo contrib module: StereoBinaryBM, StereoBinarySGBM

ccalib contrib module: omnidir::stereoReconstruct

Partial3

Pose estimation

solveP3P, solvePnP, solvePnPRansac

No

 

1 Only for the classes in the track contrib module.
2 Some classes share functions with the same name, but no inherited abstract class.
3 Each module has a base within itself, but not shared across modules.

When approaching a problem with a few algorithmic options, it's important not to commit too early to one execution path. We may use the preceding table above to see options exist, and then explore them. Next, we will discuss how to select from a pool of options.