java - Android OpenCV 创建矩形

标签 java android c++ opencv

晚上好,需要一些帮助来使用 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/

相关文章:

java - 使用 Java 正则表达式删除字符串中的所有其他字符

android - 重新安装时未重置 SharedPreferences

c++ - 为什么会出现切片?

c++ - Microsoft Visual C 运行时中未处理的异常

c++ - 通过原始蒙皮生成 3D 模型

java - 安全:filter-chain pattern match url have symbol '?'

java - 不使用大括号的嵌套 IF 条件语句的规则

java - 如何以正确的顺序从 jar 文件加载类

java - Android 使用 ArrayList 添加和删除到不同的 ListView

android - Android应用程序可以阻止用户录制音频/视频吗