- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我试图用来自互联网(来自耶鲁大学)的样本训练分类器,但是当我输入一张训练图片作为测试样本时,我总是得到错误的预测(实际上它只输出类别“1”)。谁能给我一些提示?我在下面附上了我的代码。
(我认为问题可能出在训练样本上,因为它们已经灰度化了。我再次对它们进行了灰度化,因为错误 bad argument, size(1,30000), (10000,66)....
如果我不这样做,事情就会出现。)
import org.opencv.face.FaceRecognizer;
import org.opencv.core.Mat;
import org.opencv.core.MatOfInt;
import org.opencv.core.*;
import org.opencv.face.Face;
import org.opencv.imgcodecs.Imgcodecs;
import java.io.File;
import java.io.FilenameFilter;
import java.util.List;
import java.util.ArrayList;
import org.opencv.imgproc.Imgproc;
public class FaceRecognization {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
String trainingDir = "C:\\Users\\songli\\Desktop\\yale\\train";
String testImgPath = "C:\\Users\\songli\\Desktop\\yale\\5-6.bmp";
Mat testImg = Imgcodecs.imread(testImgPath);
Mat gray = new Mat();
File root = new File(trainingDir);
FilenameFilter bmpFilter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.toLowerCase().endsWith(".bmp");
}
};
File[] imageFiles = root.listFiles(bmpFilter);
List<Mat> list = new ArrayList<Mat>(imageFiles.length);
int[] labels = new int[imageFiles.length];
int counter = 0;
int label;
Mat grayImg = new Mat();
Mat grayTestImg = new Mat();
Mat img = new Mat();
for (File image : imageFiles) {
img = Imgcodecs.imread(image.getAbsolutePath());
// System.out.print(img.elemSize());
label = Integer.parseInt(image.getName().split("\\-")[0]);
grayImg.create(img.width(), img.height(), 1);
Imgproc.cvtColor(img, grayImg, Imgproc.COLOR_BGR2GRAY);
list.add(grayImg);
labels[counter] = label;
counter++;
}
// System.out.print(labels[11]);
MatOfInt labels1 = new MatOfInt();
labels1.fromArray(labels);
FaceRecognizer fr = Face.createEigenFaceRecognizer();
fr.train(list, labels1);
grayTestImg.create(testImg.width(), testImg.height(), 1);
Imgproc.cvtColor(testImg, grayTestImg, Imgproc.COLOR_BGR2GRAY);
int predictedlabel = fr.predict_label(grayTestImg);
// Imgcodecs.imwrite("C:\\Users\\songli\\Desktop\\testImg.jpg",
// testImg);
// int[] predLabel = new int[1];
// double[] confidence = new double[1];
// int result = -1;
// fr.predict(testImgGrey,predLabel,confidence);
// result = predLabel[0];
System.out.println("Predicted label: " + predictedlabel);
}
}
最佳答案
好了伙计们,我知道我错在哪里了。
Imgproc.cvtColor(img, grayImg, Imgproc.COLOR_BGR2GRAY); ->
Imgproc.cvtColor(img,img,Imgproc.COLOR_BGR2GRAY);
完成!
一个愚蠢的错误。对不起大家。
关于java - JAVA 中的 OpenCV 人脸识别器准确性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47746007/
我正在寻找一种用C# 编写的人脸、情感和语音识别方法。对于人脸识别,我早期使用的是 Emgu CV,它不准确,而且在弱光条件下性能非常低。我还需要找到用户的情绪。不管是悲伤还是快乐。但我发现使用 Em
我正在尝试使用 Apple 的 ARKit 3.0(Reality Kit)设置面部 anchor 但失败了。1. 以前只支持前置摄像头。现在还是这样吗?2.如何让Reality Kit的ARView
当我调试人脸 API 时抛出以下错误。 UnknownHostException@830035410936}“java.net.UnknownHostException:无法解析主机“api.proj
用例如下 我们的系统中有面孔列表 用户将上传一张图片 我们希望显示与上传图像匹配的面孔列表,例如置信度 >0.8 现在查看how to ,我的理解如下 使用人脸检测API,我们需要首先上传所有图像,包
用例如下 我们的系统中有面孔列表 用户将上传一张图片 我们希望显示与上传图像匹配的面孔列表,例如置信度 >0.8 现在查看how to ,我的理解如下 使用人脸检测API,我们需要首先上传所有图像,包
我正在寻找一种完美的方法来平滑二进制图像的边缘。问题是二值图像似乎是一个阶梯状的边界,这对我进一步的掩蔽过程来说非常不愉快。 我附加了一个原始二进制图像,该图像将被转换为平滑边缘,并且我还提供了预期的
我需要一个 java 库来确定哪个图像是“人体”;这是一张“人脸”;这是一个“动物”;这是一个“风景”等等。 有这样的东西吗? 谢谢 最佳答案 我不认为那里有什么方便的东西。特别是因为你在这里有非常广
自从过去 2 天以来,我一直在努力弄清楚出了什么问题?我正在使用 Microsoft 认知服务开发用于人脸识别的 Cordova android 应用程序。为了拍摄图像,我使用了 Cordova Ca
我是一名优秀的程序员,十分优秀!