OPENCV Study Notes Mat

Source: Internet
Author: User
Tags scalar

Mat:

The matrix header contains the size of matrices;

A pointer contains the values in the matrix. To create a mat:

Mat M (2,2,cv_8uc3,scalar (0,0,125));

Note: 2,2 represents matrix size;

CV_8UC3 says

Cv_[the number of bits per itrm][signed or Unsigned][type prefix]c[the channel number];

Scalar (0,0,125) represents the initial value.


Use the Create () function

M.create (4,4,CV_8UC (2));
Note: You cannot initialize a matrix using this method.


To create a special mat matrix:

0 Matrix--zeros ()

Mat Zero=mat::zeros (3,3,CV_8UC1);

Unit Matrix--eye ()
Mat I=mat::eye (4,4,cv_64f);

All 1 matrix--ones ()
Mat One=mat::ones (2,2,cv_32f);

Other common output items:

The point

POINT2F P (5, 1);
cout << "point (2D) =" << P << endl << Endl;


3D Point

point3f p3f (2, 6, 7);
cout << "point (3D) =" << p3f << endl << Endl;
Std::vector via Cv::mat
Vector<float> v;
V.push_back ((float) cv_pi); V.push_back (2); V.push_back (3.01f);
cout << "Vector of floats via Mat =" << Mat (v) << Endl << Endl;


Std::vector of Points
Vector<point2f> vpoints ();
for (size_t i = 0; i < vpoints.size (); ++i)
    vpoints[i] = point2f ((float) (i * 5), (float) (i% 7));
cout << "A vector of 2D Points =" << vpoints << endl << Endl;


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.