java - 我需要java中的函数opencv返回垫子中颜色的百分比,请
问题描述
我需要java中的函数opencv返回垫子中颜色的百分比,请
public boolean procentage(Mat imageOne, int porsontageDeChangemnt) {
boolean tr = false;
int width = (int) imageOne.width();
int height = (int) imageOne.height();
int maxPixel = width * height;
int cont = 0;
try {
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
double[] colorPixel = imageOne.get(i, j);
if (((int) colorPixel[0] == 255)) {
cont++;
}
}
}
} catch (Exception e) {
}
int c = (int) ((cont * 100) / maxPixel);
if (c >= porsontageDeChangemnt) {
tr = true;
}
if (c > porsontageDeChangemnt) {
tr = true;
}
return tr;
}
此行中的异常>> if (((int) colorPixel[0] == 255)) {
解决方案
所以你没有提供一个完整的实现,但我稍微修改了它以获得类似的运行。
如果您将代码一直分解到基本级别并尝试以下操作:
for (int j = 0; j < 300; j++) {
double[] colorPixel = null; //This what your code thinks it is doing
if (((int) colorPixel[0] == 255)) {
System.out.println(colorPixel.toString());
}
您将在当前所在的同一行上获得相同的异常。问题是您在某个时候将null
值传递给imageOne
方法procentage
。
如果您想获得更清晰的答案,则需要提出更清晰的问题,因为您在此处编写的代码中没有显示确切的问题。
推荐阅读
- javascript - 为什么 1+ +"2"+3 在 JavaScript 中计算为 6?
- python - PyInstaller 错误“Python 未作为框架安装”
- search-engine - Azure 搜索功能 - 隐藏、提升、黑名单
- batch-file - 根据 Windows 版本修改文件内容
- python - 在提供训练数据时,Keras 似乎比 tensorflow 慢
- java - 等于 2 个 Java 对象
- xamarin.forms - Android Emulator 部署速度
- amazon-web-services - 从计划的 lambda 函数创建重复的 AMI
- shell - awk 没有创建表。只有标签被打印
- java - 致命异常:java.lang.StringIndexOutOfBoundsException