Android OpenCV Create Rect

Android OpenCV Create Rect

本文关键字:Rect Create OpenCV Android      更新时间:2023-10-16

晚上好,需要一些帮助来获得 openCV 像素的正方形区域我试图从屏幕中央的 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)