Java opencv mat type

Java opencv mat type

Methods inherited from class java.lang.Object

Field Detail

nativeObj

public final long nativeObj

Constructor Detail

Mat

Mat

Mat

public Mat​(int rows, int cols, int type)

Mat

public Mat​(int rows, int cols, int type, java.nio.ByteBuffer data)

Mat

public Mat​(int rows, int cols, int type, java.nio.ByteBuffer data, long step)

Mat

Mat

public Mat​(int[] sizes, int type)

Mat

Mat

Mat

Mat

public Mat​(Mat m, Range rowRange, Range colRange)

Mat

Mat

Mat

Method Detail

adjustROI

public Mat adjustROI​(int dtop, int dbottom, int dleft, int dright)

assignTo

assignTo

channels

checkVector

public int checkVector​(int elemChannels, int depth, boolean requireContinuous)

checkVector

public int checkVector​(int elemChannels, int depth)

checkVector

public int checkVector​(int elemChannels)

clone

col

colRange

public Mat colRange​(int startcol, int endcol)

colRange

dims

cols

convertTo

public void convertTo​(Mat m, int rtype, double alpha, double beta)

convertTo

convertTo

copyTo

copyTo

create

public void create​(int rows, int cols, int type)

create

create

public void create​(int[] sizes, int type)

copySize

cross

dataAddr

depth

diag

diag

diag

dot

elemSize

elemSize1

empty

eye

public static Mat eye​(int rows, int cols, int type)

eye

inv

inv

isContinuous

public boolean isContinuous()

isSubmatrix

public boolean isSubmatrix()

locateROI

mul

mul

matMul

ones

public static Mat ones​(int rows, int cols, int type)

ones

ones

push_back

release

reshape

reshape

reshape

public Mat reshape​(int cn, int[] newshape)

row

rowRange

public Mat rowRange​(int startrow, int endrow)

rowRange

rows

setTo

setTo

public Mat setTo​(Scalar value, Mat mask)

setTo

setTo

size

size

step1

step1

submat

public Mat submat​(int rowStart, int rowEnd, int colStart, int colEnd)

submat

public Mat submat​(Range rowRange, Range colRange)

submat

submat

t

total

type

zeros

public static Mat zeros​(int rows, int cols, int type)

zeros

zeros

finalize

protected void finalize() throws java.lang.Throwable

toString

public java.lang.String toString()

dump

public java.lang.String dump()

put

public int put​(int row, int col, double. data)

put

public int put​(int[] idx, double. data)

put

public int put​(int row, int col, float[] data)

put

public int put​(int[] idx, float[] data)

put

public int put​(int row, int col, int[] data)

put

public int put​(int[] idx, int[] data)

put

public int put​(int row, int col, short[] data)

put

public int put​(int[] idx, short[] data)

put

public int put​(int row, int col, byte[] data)

put

public int put​(int[] idx, byte[] data)

put

public int put​(int row, int col, byte[] data, int offset, int length)

put

public int put​(int[] idx, byte[] data, int offset, int length)

get

public int get​(int row, int col, byte[] data)

get

public int get​(int[] idx, byte[] data)

get

public int get​(int row, int col, short[] data)

get

public int get​(int[] idx, short[] data)

get

public int get​(int row, int col, int[] data)

get

public int get​(int[] idx, int[] data)

get

public int get​(int row, int col, float[] data)

get

public int get​(int[] idx, float[] data)

get

public int get​(int row, int col, double[] data)

get

public int get​(int[] idx, double[] data)

get

public double[] get​(int row, int col)

get

height

width

at

public Mat.Atable at​(java.lang.Class clazz, int row, int col)

at

public Mat.Atable at​(java.lang.Class clazz, int[] idx)

getNativeObjAddr

public long getNativeObjAddr()

Generated on Fri Jul 21 2023 23:28:50 GMT / OpenCV 4.8.0-88-gd69c1d8652

Читайте также:  Python информация об ошибке

Источник

Explain the Mat class in Java OpenCV library

In OpenCV, images are stored in Using Mat object. It is nothing but an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.

If you try to read an image using the OpenCV library it will be read to a Mat object.

Mat matrix = Imgcodecs.imread(filePath);

You can instantiate this class manually using one of the following constructors −

  • Mat() − A no-arg constructor, used to create an empty matrix and pass this to other OpenCV methods.
  • Mat(int rows, int cols, int type) − This constructor accepts three parameters of integer type representing the number of rows and columns in a 2D array and the type of the array (that is to be used to store data).
  • Mat(int rows, int cols, int type, Scalar s) − Including the parameters of the previous one, this constructor additionally accepts an object of the class Scalar as a parameter.
  • Mat(Size size, int type) − This constructor accepts two parameters, an object representing the size of the matrix and an integer representing the type of the array used to store the data.
  • Mat(Size size, int type, Scalar s) − Including the parameters of the previous one, this constructor additionally accepts an object of the class Scalar as a parameter.

Following are the prominent methods of this class −

  • Mat col(int x) − This method accepts an integer parameter representing the index of a column and retrieves and returns that column.
  • Mat row(int y) − This method accepts an integer parameter representing the index of a row and retrieves and returns that row.
  • int cols() − This method returns the number of columns in the matrix.
  • int rows() − This method returns the number of rows in the matrix.
  • Mat setTo(Mat value) − This method accepts an object of the Mat type and sets the array elements to the specified value.
  • Mat setTo(Scalar s) − This method accepts an object of the Scalar type and sets the array elements to the specified value.
Читайте также:  Пояснение работы парсера

Источник

Overview

MAT object is a use of to store images in OpenCV data structure , Automatic allocation of memory That is, according to the read picture to assign the corresponding size memory space, there is no memory leak problem, is an object-oriented data structure. It is divided into head and Data part 。
Use MAT to store such a picture

Code

public class DemoMat   static  System.loadLibrary(Core.NATIVE_LIBRARY_NAME); > public static void main(String[] args)   Mat src= Imgcodecs.imread("aa.jpg");// Read a picture using the Imread IMREAD using the Imgcodecs class System.out.println(src);// Print the head information of the SRC > > 

We directly output an instance of MAT, you can see the following information.

Head information

400 × 266 × CV_8UC3: 400 pixels × 266 pixels × data type

IsCont: Whether to contact storage

Issubmat: Whether is a sub-matrix

NativeObj: Local Object Address

DataAddr: Address of the stored image

type of data

The above CV_8UC3, after the underscore number Represents the number, The first symbol after the number Indicates the type used to store the pixel, and the next symbol represents the number of channels.

U: unsigned int, no symbol integer

S: Signed Int, with symbol integer

F: float, single precision floating point, Float type itself is symbol

Integer corresponding to various data types

Data part

The memory space points to DataAddr is the data part, that is, where the picture is stored.

A multidimensional matrix of data.
Code

public class DemoMat   static  System.loadLibrary(Core.NATIVE_LIBRARY_NAME); > public static void main(String[] args)   Mat src= Imgcodecs.imread("aa.jpg");// read the picture byte [] b= new byte[3];/ / Define an array of storage channel elements (this example uses three-way channel) for (int i=0;isrc.rows();i++) // Traverse, column for (int j=0;jsrc.cols();j++)  src.get(i,j,b);/ / Get each calculation and store it in the B array System.out.print(Arrays.toString(b)); > System.out.println(); >java > > 

Results of the

meaning

The above output is a three-dimensional array that can be seen as a two-dimensional array element is a dimension group, and the number of rows and columns of the two-dimensional array represents the size of the picture (in pixels), and its element The data type used by the bit array represents, as the above data type is three-way. The storage order of the channel is B, g, and r.
The following figure represents the elementary one-dimensional array of two-dimensional array. The channel storage in OpenCV is followed Sequence of B, G, and R Store.

The figure below shows a storage structure of a picture.

MAT object constructor

Mat()

Create an empty MAT instance.
Code

Mat mat = new Mat(); System.out.println(mat); 

Results of the

Mat(long addr)

Copy a MAT instance after entering the address.
Code

 Mat src= Imgcodecs.imread("aa.jpg"); System.out.println(src); Mat mat = new Mat(src.nativeObj);// Income address System.out.println(mat); System.out.println(mat==src); 

Results of the

Mat(int row,int cols,int type)

The incoming line, column, and data type are instantiated.
Code

//Mat mat=new Mat(5,5,16); Mat mat=new Mat(5,5, CvType.CV_8UC3);// 5 row 5 column CV_8UC3 type System.out.println(mat); 

Results of the

Mat(Size size,int type)

The rows in the constructor MAT (int Row, int COLs, int Type) are replaced with the SIZE object.
Code

Mat mat=new Mat(new Size(5,5),CvType.CV_8UC3); System.out.println(mat); 

Results of the

Mat(int rows,int cols,int type,Scalar s)

S: Color
Code

Mat mat=new Mat(50,50,CvType.CV_8UC3,new Scalar(0,0,255)); HighGui.imshow("title",mat); HighGui.waitKey(0); 

Results of the

Mat(Size size,int type,Scalar s)

The row of constructor MAT (int Rows, int COLs, INT TYPE, SCALAR S) is replaced with the SIZE object.

MAT object common method

int depth()

Returns the data type of the channel, that is, the first 3 digits of the underline in CV_8UC3.
Correspondence.

CV_8U = 0, CV_8S = 1, CV_16U = 2, CV_16S = 3, CV_32S = 4, CV_32F = 5, CV_64F = 6, CV_16F = 7; 
Mat mat01=new Mat(5,5,CvType.CV_8UC3); Mat mat02=new Mat(5,5,CvType.CV_16U); System.out.println("CV_8U:"+mat01.depth()+"\n"+"CV_16U:"+mat02.depth()); 

Results of the

void copyTo(Mat mat)

Copy yourself to MAT.
Code

Mat src= Imgcodecs.imread("aa.jpg"); Mat s=new Mat(); src.copyTo(s);// Copy to S System.out.println(src); System.out.println(s); System.out.println(s==src);// Used to verify that it is equal 

Results of the

void convertTo(Mat dst,int type)

DST: Copy the MAT instance
TYPE: Data Type
ConvertTO: You can change the depth of MAT, for example, can change the MAT type from CV_8UC3 to CV_16SC3

ConvertTO: You can not change the number of MATs, such as can’t change your MAT’s Type to CV_8UC1 from CV_8UC3, even if you fill in the number of conversion type channels, the output number is the same as the number of channels.
Code

Mat src= Imgcodecs.imread("aa.jpg"); Mat mat=new Mat(); src.convertTo(mat,CvType.CV_8U);// cannot be convertible System.out.println(src); System.out.println(mat); src.convertTo(mat,CvType.CV_16FC3);// Convertible System.out.println(src); System.out.println(mat); 

Results of the

Mat clone()

Returns a copy MAT object.

Mat src= Imgcodecs.imread("aa.jpg"); Mat mat=new Mat(); mat=src.clone(); System.out.println(src); System.out.println(mat); 

Results of the

void create(xxx)

The CREATE object can change the size of the image, the type, and the instance of calling this function.
Code

Mat src= Imgcodecs.imread("aa.jpg"); src.create(400,400,CvType.CV_8U); HighGui.imshow("title",src);// Display image using the IMSHOW () method of the HIGHGUI class HighGui.waitKey(0); 

Original image

Results of the

int channels()、int rows()、int cols()

Channels (): Number of channels

COLS (): Column number
Code

Mat src= Imgcodecs.imread("aa.jpg"); System.out.println("Row:"+src.rows()+"\n"+"List:"+src.cols()+"\n"+"Number of channels:"+src.channels()); 

Results of the

Источник

Оцените статью