gpt4 book ai didi

java - opencv Mat 对象

转载 作者:行者123 更新时间:2023-12-01 22:24:46 24 4
gpt4 key购买 nike

我是opencv新手我想了解opencv Mat类

对于get方法

我尝试第一个int get(int row, int col, byte[] data) 本例

  Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );


System.out.println(mat.dump());


byte[] data = new byte[mat.cols() * mat.rows() * (int)mat.elemSize()];

System.out.println(data.length);-->9

System.out.println( mat.get(0, 0, data)); -->9

但是我听不懂

1)第三个参数byte[] data的作用

2) 和结果

最佳答案

//create image as 3 * 3 identity matrix - imagine a black square with a white diagonal
//CV_8UC1 => each image pixel to be stored in a single unsigned char ( 1 byte )
//implies each pixel could take value between 0 and 255
Mat img = Mat.eye( 3, 3, CvType.CV_8UC1 );
//allocate memory to read entire img as an array
//image.elemSize() => number of bytes per image pixel
byte[] imgValues = new byte[img.cols() * img.rows() * (int)img.elemSize()];
//print number of elements in array which is 3 * 3 * 1 = 9
System.out.println(imgValues.length);
//entire content in img from offset(0,0) is read into imgValues and
//returned is number of bytes read which is 9
int numBytesRead = img.get(0, 0, imgValues);
System.out.println(numBytesRead);

建议:阅读单 channel (灰度)和多 channel 图像。然后尝试使用 CV_8UC3 而不是 CV_8UC1 并查看更改。

关于java - opencv Mat 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29020172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com