晚上好,需要一些帮助来使用 openCV 获得 rgb 像素的正方形区域 我试图从屏幕中央的 50x50 区域获取像素,但没有取得任何成功。 如果我使用输出我不会得到任何像素如果使用原始垫(图像)它得到顶角 请有人帮忙
@Override
public void onPreviewFrame(Mat image) {
int w = image.cols();
int h = image.rows();
Mat roi=new Mat(image, new Rect(h/2 , w/2 , 50, 50));
Mat output = roi.clone();
int rw=output.cols();
int rh=output.rows();
//double [] arrp = output.get(rh, rw);//if i use the output i dont get any pixel
double [] arrp = image.get(rh, rw);//if use original mat its getting the top corner
Log.i("",+(int)arrp[2]+" "+ (int)arrp[1]+" "+(int)arrp[0]);
}
最佳答案
我假设你可以使用 copyTo
:
Mat output(50, 50, image.type());
image(Rect(h/2 , w/2 , output.size())).copyTo(output);
矩阵类有一个运算符 (const Rect &roi),它返回一个子矩阵(没有深度数据复制)。 : http://docs.opencv.org/modules/core/doc/basic_structures.html#id6
编辑:
没看到是安卓版的。我认为没有运算符,所以你必须使用 submat
函数:
image.submat(Rect(h/2 , w/2 , output.size())).copyTo(output)
关于java - Android OpenCV 创建矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20643070/