Top Related Projects
Open Source Computer Vision Library
Repository for OpenCV's extra modules
YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
Models and examples built with TensorFlow
OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation
Quick Overview
OpenCV Contrib is a repository containing extra modules and contributions for OpenCV, the popular open-source computer vision library. It includes experimental or non-free algorithms, as well as additional functionality that extends the capabilities of the main OpenCV library.
Pros
- Provides advanced and experimental algorithms not found in the main OpenCV library
- Regularly updated with new contributions from the community
- Offers specialized modules for specific computer vision tasks
- Allows for easy integration with the main OpenCV library
Cons
- Some modules may be less stable or well-documented compared to the main OpenCV library
- Requires separate installation and configuration in addition to the main OpenCV library
- May include algorithms with potential licensing restrictions
- Performance of some experimental algorithms may not be optimized
Code Examples
- Face detection using the face module:
import cv2
face_cascade = cv2.face.LBPHFaceRecognizer_create()
face_cascade.read('lbph_model.xml')
img = cv2.imread('image.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5)
for (x, y, w, h) in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 2)
cv2.imshow('Detected Faces', img)
cv2.waitKey(0)
- Text detection using the text module:
import cv2
import numpy as np
east = cv2.dnn.readNet('frozen_east_text_detection.pb')
img = cv2.imread('image.jpg')
blob = cv2.dnn.blobFromImage(img, 1.0, (320, 320), (123.68, 116.78, 103.94), swapRB=True, crop=False)
east.setInput(blob)
(geometry, scores) = east.forward(['feature_fusion/Conv_7/Sigmoid', 'feature_fusion/concat_3'])
# Process geometry and scores to get text bounding boxes
# (Additional processing steps omitted for brevity)
cv2.imshow('Detected Text', img)
cv2.waitKey(0)
- Object tracking using the tracking module:
import cv2
tracker = cv2.TrackerCSRT_create()
video = cv2.VideoCapture('video.mp4')
ret, frame = video.read()
bbox = cv2.selectROI(frame, False)
tracker.init(frame, bbox)
while True:
ret, frame = video.read()
if not ret:
break
success, bbox = tracker.update(frame)
if success:
(x, y, w, h) = [int(v) for v in bbox]
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)
cv2.imshow('Tracking', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video.release()
cv2.destroyAllWindows()
Getting Started
-
Install OpenCV and OpenCV Contrib:
pip install opencv-contrib-python
-
Import the required modules in your Python script:
import cv2
-
Use the desired modules and functions from OpenCV Contrib:
# Example: Using the xphoto module for white balance correction wb = cv2.xphoto.createSimpleWB() balanced_image = wb.balanceWhite(image)
Competitor Comparisons
Open Source Computer Vision Library
Pros of opencv
- Core functionality and widely used algorithms
- Better documentation and community support
- More stable and thoroughly tested
Cons of opencv
- Limited to mainstream computer vision features
- Slower to incorporate cutting-edge algorithms
- May lack specialized modules for specific use cases
Code Comparison
opencv:
#include <opencv2/opencv.hpp>
cv::Mat image = cv::imread("image.jpg");
cv::GaussianBlur(image, blurred, cv::Size(5, 5), 0);
cv::imshow("Blurred Image", blurred);
opencv_contrib:
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
cv::Ptr<cv::xfeatures2d::SURF> surf = cv::xfeatures2d::SURF::create();
std::vector<cv::KeyPoint> keypoints;
surf->detect(image, keypoints);
opencv is the main repository containing core OpenCV functionality, while opencv_contrib hosts additional modules and experimental algorithms. opencv offers stability and essential features, whereas opencv_contrib provides access to more specialized and cutting-edge computer vision techniques. The code comparison shows a basic image processing task in opencv and a more advanced feature detection algorithm from opencv_contrib.
Repository for OpenCV's extra modules
Pros of opencv_contrib
- Contains additional modules and extensions for OpenCV
- Provides cutting-edge algorithms and features not yet included in the main OpenCV repository
- Allows for easier experimentation with new computer vision techniques
Cons of opencv_contrib
- May have less stable or thoroughly tested code compared to the main OpenCV repository
- Requires additional setup and configuration to use with OpenCV
- Some modules might have dependencies on external libraries
Code Comparison
opencv_contrib:
#include <opencv2/xfeatures2d.hpp>
cv::Ptr<cv::Feature2D> sift = cv::xfeatures2d::SIFT::create();
std::vector<cv::KeyPoint> keypoints;
sift->detect(image, keypoints);
opencv:
#include <opencv2/features2d.hpp>
cv::Ptr<cv::Feature2D> orb = cv::ORB::create();
std::vector<cv::KeyPoint> keypoints;
orb->detect(image, keypoints);
The code comparison shows the usage of SIFT from opencv_contrib versus ORB from the main OpenCV repository. SIFT is a more advanced feature detection algorithm available in opencv_contrib, while ORB is a faster alternative included in the core OpenCV library.
YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
Pros of darknet
- Specialized for YOLO object detection, offering optimized performance
- Supports both CPU and GPU acceleration out of the box
- Simpler setup and usage for YOLO-specific tasks
Cons of darknet
- Limited to YOLO-based architectures and object detection tasks
- Smaller community and fewer resources compared to OpenCV
- Less comprehensive documentation and tutorials
Code Comparison
darknet:
network *net = load_network("cfg/yolov3.cfg", "yolov3.weights", 0);
image im = load_image("data/dog.jpg", 0, 0, net->w, net->h);
float *X = im.data;
network_predict(net, X);
opencv_contrib:
cv::dnn::Net net = cv::dnn::readNetFromDarknet("yolov3.cfg", "yolov3.weights");
cv::Mat frame = cv::imread("dog.jpg");
cv::Mat blob = cv::dnn::blobFromImage(frame, 1/255.0, cv::Size(416, 416));
net.setInput(blob);
std::vector<cv::Mat> outs;
net.forward(outs, net.getUnconnectedOutLayersNames());
Both repositories offer object detection capabilities, but darknet is more focused on YOLO implementations, while opencv_contrib provides a broader range of computer vision algorithms and tools. darknet may be easier to use for YOLO-specific tasks, while opencv_contrib offers more flexibility and integration with other OpenCV functions.
Models and examples built with TensorFlow
Pros of TensorFlow Models
- Extensive collection of pre-trained models for various AI tasks
- Strong integration with TensorFlow ecosystem and tools
- Regular updates and contributions from Google researchers
Cons of TensorFlow Models
- Steeper learning curve for beginners compared to OpenCV
- Heavier computational requirements for many models
- Less focus on traditional computer vision tasks
Code Comparison
TensorFlow Models:
import tensorflow as tf
from official.vision.image_classification import resnet_model
model = resnet_model.resnet50(num_classes=1000)
inputs = tf.keras.Input(shape=(224, 224, 3))
outputs = model(inputs)
OpenCV Contrib:
import cv2
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
img = cv2.imread('image.jpg')
faces = face_cascade.detectMultiScale(img, 1.1, 4)
The TensorFlow Models repository focuses on deep learning models and neural networks, while OpenCV Contrib provides additional modules for computer vision tasks, including traditional algorithms and some machine learning approaches. TensorFlow Models is better suited for complex AI tasks, while OpenCV Contrib excels in image processing and computer vision applications.
OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation
Pros of OpenPose
- Specialized for real-time multi-person keypoint detection
- Provides pre-trained models for human pose, hand, and facial keypoint detection
- Offers GPU acceleration for improved performance
Cons of OpenPose
- More limited in scope compared to opencv_contrib's diverse set of modules
- Steeper learning curve for users not familiar with pose estimation
- Less frequent updates and maintenance compared to opencv_contrib
Code Comparison
OpenPose:
#include <openpose/pose/poseExtractor.hpp>
op::PoseExtractorCaffe poseExtractor;
poseExtractor.initializationOnThread();
poseExtractor.forwardPass(netInputArray, imageSize, scaleInputToNetInputs);
opencv_contrib (using the face module):
#include <opencv2/face.hpp>
cv::Ptr<cv::face::Facemark> facemark = cv::face::FacemarkLBF::create();
facemark->loadModel("lbfmodel.yaml");
facemark->fit(frame, faces, landmarks);
Both repositories offer valuable contributions to computer vision tasks, with OpenPose focusing on pose estimation and opencv_contrib providing a wider range of specialized modules. The choice between them depends on the specific requirements of your project.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Repository for OpenCV's extra modules
This repository is intended for the development of so-called "extra" modules, contributed functionality. New modules quite often do not have stable API, and they are not well-tested. Thus, they shouldn't be released as a part of the official OpenCV distribution, since the library maintains binary compatibility, and tries to provide decent performance and stability.
So, all the new modules should be developed separately, and published in the
opencv_contrib
repository at first. Later, when the module matures and gains
popularity, it is moved to the central OpenCV repository, and the development team
provides production-quality support for this module.
How to build OpenCV with extra modules
You can build OpenCV, so it will include the modules from this repository. Contrib modules are under constant development and it is recommended to use them alongside the master branch or latest releases of OpenCV.
Here is the CMake command for you:
$ cd <opencv_build_directory>
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules <opencv_source_directory>
$ make -j5
As the result, OpenCV will be built in the <opencv_build_directory>
with all
modules from opencv_contrib
repository. If you don't want all of the modules,
use CMake's BUILD_opencv_*
options. Like in this example:
$ cmake -DOPENCV_EXTRA_MODULES_PATH=<opencv_contrib>/modules -DBUILD_opencv_legacy=OFF <opencv_source_directory>
If you also want to build the samples from the "samples" folder of each module, also include the "-DBUILD_EXAMPLES=ON" option.
If you prefer using the GUI version of CMake (cmake-gui), then, you can add opencv_contrib
modules within opencv
core by doing the following:
-
Start cmake-gui.
-
Select the opencv source code folder and the folder where binaries will be built (the 2 upper forms of the interface).
-
Press the
configure
button. You will see all the opencv build parameters in the central interface. -
Browse the parameters and look for the form called
OPENCV_EXTRA_MODULES_PATH
(use the search form to focus rapidly on it). -
Complete this
OPENCV_EXTRA_MODULES_PATH
by the proper pathname to the<opencv_contrib>/modules
value using its browse button. -
Press the
configure
button followed by thegenerate
button (the first time, you will be asked which makefile style to use). -
Build the
opencv
core with the method you chose (make and make install if you chose Unix makefile at step 6). -
To run, linker flags to contrib modules will need to be added to use them in your code/IDE. For example to use the aruco module, "-lopencv_aruco" flag will be added.
Update the repository documentation
In order to keep a clean overview containing all contributed modules, the following files need to be created/adapted:
-
Update the README.md file under the modules folder. Here, you add your model with a single-line description.
-
Add a README.md inside your own module folder. This README explains which functionality (separate functions) is available, links to the corresponding samples, and explains in somewhat more detail what the module is expected to do. If any extra requirements are needed to build the module without problems, add them here also.
Top Related Projects
Open Source Computer Vision Library
Repository for OpenCV's extra modules
YOLOv4 / Scaled-YOLOv4 / YOLO - Neural Networks for Object Detection (Windows and Linux version of Darknet )
Models and examples built with TensorFlow
OpenPose: Real-time multi-person keypoint detection library for body, face, hands, and foot estimation
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot