<java>如何在OpenCV中获取整个屏幕的RGB像素值

时间:2017-01-11 20:51:30

标签: java opencv computer-vision pixel javacv

这是我的代码到目前为止,但我收到了PreferenceFragmentCompat

等错误

有关如何解决此问题的任何建议?任何帮助表示赞赏;)

OpenCV Error: One of arguments' values is out of range (index is out of range) in cvPtr2D, file ..\..\..\..\opencv\modules\core\src\array.cpp, line 1797
Exception in thread "main" java.lang.RuntimeException: ..\..\..\..\opencv\modules\core\src\array.cpp:1797: error: (-211) index is out of range in function cvPtr2D

1 个答案:

答案 0 :(得分:0)

cvGet2D()期望列前的行。并且索引是从0开始的,所以你的循环只是超出范围。并且s应该是2D数组,因此您不会继续覆盖您的数据。试试这个:

CvScalar[][] s = new CvScalar[img.height()][img.width()];
for (int i = 0; i < img.height(); i++) {
    for (int j = 0; j < img.width(); j++) {
        s[i][j] = cvGet2D(img, i, j);
    }
}