Skip to main content

Posts

Showing posts with the label Mat class

OpenCV : Mat class method

You can get your mat object information (dimmension, rows, cols, size ....) and resize, reshape, copy Mat object by using Mat class method. 1. Get Information of Mat object cout << "dimmension : " << mat7 . dims << endl; cout << "rows : " << mat7 . rows << endl; cout << "columns : " << mat7 . cols << endl; cout << "size : " << mat7 . size () << endl << endl; cout << "number of total elements: " << mat7 .total() << endl; cout << "type :" << mat7 .type() << endl; cout << "depth :" << mat7 .depth() << endl; cout << "channels :" << mat7 .channels() << endl; 2. Resize Mat object Mat_ <int> mat10( 2 , 4 ); mat10 << 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ; mat10 .resize( 1 ); // resize to one row mat10 .resize( 2 ); // resize to two rows mat10 .resize( ...

OpenCV : Create Mat Object

What is Mat Class  The basic Image Container, an n-dimensional dense numerical single-channel or multi-channel array. 1. Costructor  You can create Mat object by different ways. Mat mat ( 3 , 3 , CV_32F ); Mat mat2 ( 10 , 2 , CV_64FC2 ); // 2x10 64 bit float 2 channel Mat img ( Size ( 5 , 3 ), CV_32FC3 ); // 5x3 32bit float 3 channel Mat mat3 ( 2 , 3 , CV_8U , Scalar(255) ); // 3x2 8bit unsign_int, all elements set 255 Warining When you create mat object by using Size or Point class, yout have to reverse rows and columns. 2. Set Elements When you create Mat object without data, the elements is set to '0' by defaults. If you want to change elements, you can use setTo , Mat:: ones , Mat:: zeros , Mat:: eye method. Mat mat ( 3 , 3 , CV_32F ); mat .setTo( 10 ); // all elements set to 10 Mat mat7 = Mat :: ones( 3 , 5 , CV_32F ); // all elements set to '1' Mat mat8 = Mat :: zeros( 2 , 3 , CV_32F ); // all elements set to '0' Mat mat9 = Mat :: e...