Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

threr is no contrib files #1

Open
leafgrey opened this issue May 29, 2023 · 3 comments
Open

threr is no contrib files #1

leafgrey opened this issue May 29, 2023 · 3 comments

Comments

@leafgrey
Copy link

dose not contain OpenCV's extra modules

@kamilszewc
Copy link
Owner

Hi @leafgrey, what modules would you like to have? There may be a small difference between operating systems since the compilation procedure of native libraries was different. Give more information, please.

@leafgrey
Copy link
Author

leafgrey commented May 30, 2023

hello @kamilszewc ,thx for your reply,

我想使用 java opencv 做一个能够使用人脸认证身份得程序
我自己编译了多次,只得到了jar文件,无法得到正确的 dll(win)和so(linux)文件,我编译得到的dll文件和so文件只有2.77MB,但是官方给的文件有103MB,
这里有一份 示例代码,但是它并不能正常运行,我感觉是因为 opencv_java470.dll 中并不包含 opencv_contrib 中的文件

I want to use Java OpenCV to build a program that can use facial authentication for identity authentication.
I have compiled times by myself and only obtained the jar file, unable to obtain the correct DLL (win) and SO (Linux) files.
The DLL and SO files I compiled were only 2.77MB, but the official(org.opencv) provided DLL was 103MB,
Here is an example code, but it does not run well. I think that it is because there is no opencv_contrib modules in opencv_java470.dll.

demo code:

static {
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
  // 1. 加载人脸识别模型,并初始化人脸检测器和特征提取器.
  String faceCascadePath = "path/to/haarcascade_frontalface_default.xml";
  CascadeClassifier faceDetector = new CascadeClassifier(faceCascadePath);
  LBPHFaceRecognizer faceRecognizer = LBPHFaceRecognizer.create();
  // 2. 加载已知人脸图像,提取其特征向量.
  String faceImgBase = "E:\\test_opencv\\face\\";
  String knownFaceImagePath = faceImgBase + "1.jpg";
  Mat knownFaceImage = Imgcodecs.imread(knownFaceImagePath);
  Mat knownFaceFeatures = extractFaceFeatures(faceDetector, knownFaceImage);
  // 3. 获取待认证人脸图像,提取其特征向量.
  String faceToAuthenticatePath = faceImgBase + "2.jpg";
  Mat faceToAuthenticate = Imgcodecs.imread(faceToAuthenticatePath);
  Mat faceToAuthenticateFeatures = extractFaceFeatures(faceDetector, faceToAuthenticate);
  // 4. 对比待认证人脸特征向量与已知人脸特征向量,计算相似度.
  double similarity = compareFaceFeatures(faceRecognizer, knownFaceFeatures, faceToAuthenticateFeatures);
  // 5. 根据相似度判断是否认证成功.
  System.out.println("相似度: " + similarity);
}
private static Mat extractFaceFeatures(CascadeClassifier faceDetector, Mat image) {
  Mat grayImage = new Mat();
  Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_BGR2GRAY);
  Imgproc.equalizeHist(grayImage, grayImage);
  MatOfRect faces = new MatOfRect();
  faceDetector.detectMultiScale(grayImage, faces, 1.1, 2, 0, new Size(30, 30), new Size());
  Rect[] facesArray = faces.toArray();
  if (facesArray.length == 0) {
    throw new RuntimeException("face not found");
  }
  Rect faceRect = facesArray[0];
  Mat faceROI = grayImage.submat(faceRect);
  Mat resizedFace = new Mat();
  Imgproc.resize(faceROI, resizedFace, new Size(100, 100));
  return resizedFace;
}
private static double compareFaceFeatures(LBPHFaceRecognizer faceRecognizer, Mat knownFaceFeatures, Mat faceToAuthenticateFeatures) {
  faceRecognizer.train(Arrays.asList(knownFaceFeatures), new Mat(1, 1, CvType.CV_32SC1, new Scalar(0)));
  int[] label = new int[1];
  double[] confidence = new double[1];
  faceRecognizer.predict(faceToAuthenticateFeatures, label, confidence);
  return confidence[0];
}

然后我在github上找到了你已经编译过的opencv依赖程序,但是看起来你并没有把opencv_contrib相关的模块编译进去
and then i surprised found your project,i see the hope, but, seems u did not compile the opencv's extra modules too.

i am not good at en.. u can refre the extra project https://github.com/opencv/opencv_contrib

@leafgrey
Copy link
Author

leafgrey commented Jun 1, 2023

hi !Will there be any plans to include the compilation of opencv_contrib modules in future versions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants