usnistgov / NFIQ2

Optical live-scan and ink fingerprint image quality assessment tool
https://www.nist.gov/services-resources/software/development-nfiq-20
Other
129 stars 57 forks source link

What should FingerprintImageDatas which are input to call the method named "computeQualityScore" be like? #307

Closed yzy888 closed 2 years ago

yzy888 commented 3 years ago

Describe the issue Hi, I have downloaded the code NFIQ2-master and have written my code to input one image and output the quality score. My code could be compiled successfully, but when it was running and the method named "computeQualityScore" was called, an error would occur.

Expected behavior I want to know how to process the image before I convert one mat to a FingerprintImageData object so that I could get one quality score by calling "computeQualityScore" method. Or if I want to get the quality score of one fingerprint image with nfiq2 successfully, what should the image be like? Are there any documents for me to refer to? Thank you.

OS information

NFIQ 2 version information 2.1.0

Code sample My code is as follows:

#include "stdafx.h"
#include <nfiq2.hpp>

#include <iostream>
#include <memory>
#include <opencv2\core.hpp>
#include <opencv2\highgui.hpp>
#include <nfir_lib.h>

static const uint16_t PPI = 500;
//load model file
NFIQ2::ModelInfo modelInfoObj{};
try {
    std::string modelPath = "E:/nist_plain_tir-ink.txt";
    modelInfoObj = NFIQ2::ModelInfo(modelPath);
}
catch (...) {
    std::cerr << "Could not parse model info file. Ensure it is the first argument on the cmd line\n";
    return (EXIT_FAILURE);
}

// This segment loads the model into memory so that it can be used to
// generate a NFIQ 2 score.
NFIQ2::Algorithm model{};
try {
    model = NFIQ2::Algorithm(modelInfoObj);
}
catch (...) {
    std::cerr << "Could not initialize model from model info file";
    return (EXIT_FAILURE);
}

//read one image and get a mat
cv::Mat matData = cv::imread("E:/101_2.tif");
cv::Mat postResample{}; 

//resample
try {
    NFIR::resample(matData, postResample, 72, PPI, "", "");
}
catch (const NFIR::Miscue &e) {
    std::cout << e.what() << std::endl;
}
catch (const cv::Exception& ex) {
    std::cout << "NFIR bin: Exception for '" << "'.\n OpenCV error message: "
        << ex.what() << ",Image format attempted";
}

//get a FingerprintImageData object
NFIQ2::FingerprintImageData rawImage = NFIQ2::FingerprintImageData(
    postResample.data, postResample.total(), postResample.cols, postResample.rows, 0, PPI);

// Pass the feature values through the random forest to obtain  an
// NFIQ 2 quality score
unsigned int nfiq2{};
try {
    nfiq2 = model.computeQualityScore(rawImage);
}catch (...) {
    std::cerr << "Error in calculating NFIQ 2 score\n";
    return (EXIT_FAILURE);
}
gfiumara commented 3 years ago

I believe your cv::Mat will, by default, be RGB. Images must be 8-bit grayscale. Additionally, computeQualityScore() should provide a good exception message, so try catching and printing it out instead of catching ...

yzy888 commented 3 years ago

OK, thank you, @gfiumara . I have edited the code as you said. I replaced the code cv::Mat matData = cv::imread("E:/101_2.tif"); with cv::Mat matData = cv::imread("E:/101_2.tif", cv::IMREAD_GRAYSCALE); and replaced the code catch (...) with catch (NFIQ2::Exception ex). Then I run the code and I could catch the error "Width is too large after trimming whitespace. WxH: 1711x2807, but maximum width is 799". Should I resize the mat before resample the image? Or should I do other work to get the quality score successfully?

Abdullah0991 commented 2 years ago

@yzy888 has you resolved this issue?

gfiumara commented 2 years ago

@yzy888 The description of the error is clear: the fingerprint area in the image is too large to be processed by NFIQ 2 (specifically FingerJet). Being 1711x2807 at 500 PPI would imply a 3.4" x 5.6" finger surface, which seems anthropometrically incorrect. Ensure you have parsed the image correctly.

gfiumara commented 2 years ago

Closing this issue due to topic (support request, not bug report) and inactivity.