Mat容器

 

 

#include <opencv2/core.hpp>         //the basic building blocks of the library
#include <opencv2/imgcodecs.hpp>    //provides functions for reading and writing
#include <opencv2/highgui.hpp>      //contains the functions to show an image in a window
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
    Mat a = (cv::Mat_<int>(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);

    Mat c0(5, 5, CV_8UC1, Scalar(4, 5, 6));
    Mat c1(5, 5, CV_8UC2, Scalar(4, 5, 6));
    Mat c2(5, 5, CV_8UC3, Scalar(4, 5, 6));

    cout << a.at<int>(0, 0) << endl; // 1

    cout << (int)c0.at<uchar>(0, 1) << endl; // 4 

    Vec2b vc = c1.at<Vec2b>(0, 1);
    cout << vc << endl; //[4, 5]
    cout << (int)vc[0] << endl; // 4
    cout << (int)c1.at<Vec2b>(1, 1)[1] << endl; // 5

    cout << (int)(*(c2.data + c2.step[0]*2 + c2.step[1]*1 + 2)); // 6

    return 0;
}

 

#include <opencv2/opencv.hpp>         //the basic building blocks of the library
#include <opencv2/core.hpp>         //the basic building blocks of the library
#include <opencv2/imgcodecs.hpp>    //provides functions for reading and writing
#include <opencv2/highgui.hpp>      //contains the functions to show an image in a window
#include <iostream>
using namespace cv;
using namespace std;

int main()
{
    Mat c0(3, 3, CV_32FC3, Scalar(4, 5, 6));
    Mat c1(3, 3, CV_32FC3, Scalar(5, 6, 4));
    Mat c2(3, 3, CV_32FC3, Scalar(6, 4, 5));

    cout << "和:" << c0 + c1 << endl;
    cout << "差:" << c0 - c1 << endl;
    cout << "数乘:" << 2 * c0 << endl;
    cout << "数除:" << c0 / 2.0 << endl;
    cout << "减数:" << c0 - 1.0 << endl;

    cout << "对应位相乘:" << endl << c0.mul(c1) << endl;

    cout << "两个矩阵最小值:" << endl << min(c0, c1) << endl;

    return 0;
}

猜你喜欢

转载自blog.csdn.net/m0_46521579/article/details/132465680
Mat
今日推荐