Hexo

  • Home

  • Archives

Opencv Matrix Operations

Posted on 2019-08-26 Edited on 2019-08-27

OpenCV Matrix Operations

Since OpenCV is the most widely used image processing library, the matrix operation and basic linear algebra is inevidable.

1. Initialization

Remeber that you have to initialize a Mat from a array.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <opencv2/core/core.hpp>
using namespace std;
using namespace cv;

void addMatrixExample() {
float a[2][2] = {{1, 2},
{3, 4}};
float b[2][2] = {{5, 6},
{7, 8}};

Mat A = Mat(2, 2, CV_32FC1, a);
Mat B = Mat(2, 2, CV_32FC1, b);
Mat C;
C = A + B;
cout << "C =" << endl << " " << C << endl << endl;
}

int main() {
addMatrixExample();
}

2. Point

1
2
3
4
5
6
7
typedef Point_<int> Point2i;
typedef Point2i Point;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;
typedef Point3_<int> Point3i;
typedef Point3_<float> Point3f;
typedef Point3_<double> Point3d;

From the above we can see that Point, Point2i, Point_<int> are exactly the same.

CPP-Primer-Notes
CPP Primer: Chapter 3 String, Vectors, and Arrays
  • Table of Contents
  • Overview

Zepyhrus

12 posts
  1. 1. OpenCV Matrix Operations
    1. 1.1. 1. Initialization
    2. 1.2. 2. Point
© 2020 Zepyhrus
Powered by Hexo v3.9.0
|
Theme – NexT.Mist v7.3.0