📖
Wiki
Back to my personal website
  • Home
  • Equipment and Devices
    • 3D Printer
    • Laser Cutter
    • Motion Capture System
    • Sensors
      • RGB-D Cameras
      • Velodyne LiDAR
      • Zed Camera
      • RealSense D435i
      • IMU
    • eGPU
    • Nvidia AGX Xavier
    • CPU Benchmark
    • Installation Checklist
  • Development
    • Linux
      • Shell
      • GDB
      • Git
      • Tmux
      • Network
      • Tricks
      • Debug FAQ
    • CMake
      • Catkin Tools
      • CMakeLists
      • CMake Variables
      • CMake Commands
      • CMake: find_package()
    • ROS
      • Gazebo
      • wstool
      • roslaunch
      • rosbag
      • multi-threaded spinner
    • ROS2
      • Convert ROS1 bag to ROS2 bag
    • C++
      • C++ 11
      • C++ Examples
      • C++ Debug
      • Factory Method
      • Timing
    • Google Tools
      • GLog
      • GFlags
      • GTest
      • Style Guide
      • Clang Format
    • PCL
      • Point Type
      • Methods
      • Architecture
      • Code Explained
    • Open3D
      • Python API
      • Registration
      • Visualization
      • Tools
    • OpenCV
      • Documentation
      • Modules
    • Other Libraries
      • Eigen
      • Ceres
      • g2o
      • GTSAM
    • Website
  • Algorithm
    • SLAM
      • K-D Tree
      • Octree
      • Bag of Words
      • Distance Measures
      • Coordinate Systems
      • LOAM
      • Iterative Closest Point
      • Generalized ICP
      • Mahalanobis Distance
    • Computer Science
      • Computational Model
      • Sorting
      • Analysis
      • Complexity Classes (P, NP)
      • Divide and Conquer
      • Greedy Algorithm
      • Dynamic Programming
      • Tree
      • Graph
    • Computer Vision
      • Camera Models
      • Distortion
      • Motion Models
      • Shutter
      • Image Sensors
      • Epipolar Geometry
      • Multiple-View Geometry
    • Datasets
      • RGB-D Datasets
      • Point Cloud Datasets
      • LiDAR SLAM Datasets
  • Math
    • Optimization
      • Convex Optimization
      • Descent Methods
    • Probability
      • Moment
      • Covariance Matrix
      • Stochastic Process
    • Topology
      • References
      • Concepts
      • Topological Spaces
      • Representation of Rotations
      • Representation of 3-sphere
    • Algebra
      • Linear Algebra
      • Matrix Factorization
      • Condition Number
      • Matrix Lie Group
    • Differential Geometry
      • Manifold
      • Submanifold
      • Quotient Manifolds
      • Tangent Space
  • Quadrotor
    • PX4 Development
    • Companion Computer
    • Drone Hardware
    • Propeller Lock
    • Debug
  • Favorites
    • Bookmarks
Powered by GitBook
On this page
  • cv::Mat
  • cv::ORB
  • cv::FileStorage
  • Line Features

Was this helpful?

  1. Development
  2. OpenCV

Modules

cv::Mat

  • With C++ interface in OpenCV 2.0, Mat supports automatic memory management.

  • Mat has two data parts: the matrix header (constant size) and a pointer to the matrix containing the pixel values (varying size).

  • For computational efficiency, OpenCV uses a reference counting system.

    • Each Mat object has its own header, however the matrix may be shared.

    • The copy operators will only copy the headers and the pointer to the large matrix, not the data itself.

    • Making a modification using any of them will affect all the other ones as well.

  • To copy the matrix itself, use cv::Mat::clone() and cv::Mat::copyTo()

  • Color space options

    • RGB is the most common one (however OpenCV uses BGR instead)

    • The HSV and HLS decompose colors into their hue, saturation and value/luminance components (more natural way for us to describe colors)

    • YCrCb is used by the popular JPEG image format

    • CIE L*a*b* is a perceptually uniform color space

// cv::Mat::Mat Constructor
Mat M(2, 2, CV_8UC3, Scalar(0,0,255));

// Use C/C++ arrays and initialize via constructor
int sz[3] = {2,2,2};
Mat L(3, sz, CV_8UC(1), Scalar::all(0));

// MATLAB style initializer
Mat E = Mat::eye(4, 4, CV_64F);
Mat O = Mat::ones(2, 2, CV_32F);
Mat Z = Mat::zeros(3, 3, CV_8UC1);

// For small matrices you may use comma separated initializers
Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);

// Create a new header for an existing Mat object
Mat RowClone = C.row(1).clone();

// You can fill out a matrix with random values
Mat R = Mat(3, 2, CV_8UC3);
randu(R, Scalar::all(0), Scalar::all(255));

// Other common OpenCV data structures
Point2f P(5, 1);
Point3f P3f(2, 6, 7);
std::vector<float> v(20);  Mat(v);
std::vector<Point2f> vPoints(20);

// Typedefs in CV Core module
// typedef Mat_< Vec3f > 	cv::Mat3f
// typedef Matx< double, 3, 3 > 	cv::Matx33d

cv::ORB

cv::Mat image1 = cv::imread("../data/1.png", cv::IMREAD_COLOR);
cv::Mat image2 = cv::imread("../data/2.png", cv::IMREAD_COLOR);

cv::Ptr<cv::ORB> orb = cv::ORB::create();
std::vector<cv::KeyPoint> keypoints1, keypoints2;
orb->detect(image1, keypoints1);
orb->detect(image2, keypoints2);

cv::Mat descriptors1, descriptors2;
orb->compute(image1, keypoints1, descriptors1);
orb->compute(image2, keypoints2, descriptors2);

std::vector<cv::DMatch> matches;
cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");
matcher->match(descriptors1, descriptors2, matches, cv::Mat());

cv::Mat output_image;
cv::drawMatches(image1, keypoints1, image2, keypoints2, matches, output_image);
cv::namedWindow("Display window", cv::WINDOW_AUTOSIZE);
cv::imshow("Display window", output_image);
cv::waitKey(0);

cv::FileStorage

// XML/YAML File Open and Close
string filename = "I.xml";
FileStorage fs(filename, FileStorage::WRITE);

fs.open(filename, FileStorage::READ);

// Input and Output of text and numbers
fs << "iterationNr" << 100;

int itNr;
fs["iterationNr"] >> itNr;
itNr = (int) fs["iterationNr"];

// Input/Output of OpenCV Data structures
Mat R = Mat_<uchar >::eye  (3, 3),
    T = Mat_<double>::zeros(3, 1);
fs << "R" << R;    // Write cv::Mat
fs << "T" << T;
fs["R"] >> R;      // Read cv::Mat
fs["T"] >> T;

// Input/Output of vectors (arrays) and associative maps
// use cv::FileNode and cv::FileNodeIterator data structures

// Read and write your own data structures
// ...

Line Features

PreviousDocumentationNextOther Libraries

Last updated 3 years ago

Was this helpful?

OpenCV contrib modules

implements the LSD detector.

provides the line descriptors as one of the contrib modules. Not sure if this implements the Line Band Descriptors (LBD) that is commonly used for line matching.

Line Features Tutorial
cv::LineSegmentDetector
cv::line_descriptor