GithubHelp home page GithubHelp logo

Comments (5)

fengyuentau avatar fengyuentau commented on July 26, 2024

Python's API (match) is actually calling the C++ implementation. So that must be something wrong in your code.


printf("ret=%.10lf\n",ret);

You dont need l to print a double when using printf. See a duplicate here: #140 (comment)

from opencv_zoo.

zhaodianbo avatar zhaodianbo commented on July 26, 2024

printf("ret=%.10f\n",ret); is not working! result is same as %.10lf
tried std::cout <<std::fixed << std::setprecision(10) << ret << std::endl; not working!

I also tested use Go, result is also wrong

from opencv_zoo.

zhaodianbo avatar zhaodianbo commented on July 26, 2024

Actually, I first tested with Go code and found that the comparison results were incorrect. That's why I used C++ code to test it. However, I found that the results were inconsistent with Python's results. The code is very simple, which confuses me.

from opencv_zoo.

fengyuentau avatar fengyuentau commented on July 26, 2024
-    cv::Mat feature1=getFaceFeature(faceDetector,faceRecognizer,image1);
-    cv::Mat feature2=getFaceFeature(faceDetector,faceRecognizer,image2);
+    cv::Mat feature1=getFaceFeature(faceDetector,faceRecognizer,image1).clone();
+    cv::Mat feature1=getFaceFeature(faceDetector,faceRecognizer,image1).clone();

Classic C++ misuse.

  1. Your feature is extracted in a function, so it is a local variable.
  2. When you call getFaceFeature the first time, feature is extracted and then returned, resulting in a shallow copy to feature1. In my changes above, .clone() makes it a deep copy.
  3. When you call getFaceFeature the second time, local variable feature is reused to save memory, and it is overwritten by the features of image2. This changes the values in feature1 as well due to shallow copy.
  4. So you get feature1 and feature2, both have exact same values, resulting in very high cosine score (because they are the same one!).

from opencv_zoo.

zhaodianbo avatar zhaodianbo commented on July 26, 2024

Thank you very much, the correct value was returned after using the clone() method. I will continue testing in the future, thx!
I check the source code of get feature, outputarray of mat type just give a shallow copy ,so mat need to clone if use it later.

from opencv_zoo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.