Reputation: 139
I am working on a fingerprint recognition project with OpenCV. Currently I need to extract the inner region in fingerprint (ellipse in image), but I am not sure how to do it.
Any suggestion is appreciated.
EDIT:
I need to check if a fingerprint from sensor device and another from identification card match or not. The fingerprint in sensor is as follow (left) meanwhile in identification card is as right fingerprint. In order to validate them, it is required to segment this fingerprint (outside the ellipse doesn't provide useful information but indeed adds "noise" for this purpose).
Thank you.
Upvotes: 1
Views: 904
Reputation: 1
int main() {
string path = "Resources/1/*";
vector<String> fn;
vector<Mat> data;
glob(path, fn, true);
int cntr = 0;
Mat inputImage, binaryimage;
for (size_t k = 0; k < fn.size(); ++k){
inputImage = imread(fn[k]);
cout << fn[k] << endl;
Mat gray;
cvtColor(inputImage,gray, COLOR_BGR2GRAY);
Mat normalizedImage;
cv::normalize(gray, normalizedImage, 15, 255, NORM_MINMAX);
imshow("inpnorm", normalizedImage);
Mat imgdil, imgerode;
Mat kernel = getStructuringElement(MORPH_ELLIPSE, Size(3, 3));
dilate(normalizedImage, imgdil, kernel);
//erode(imgdil, imgerode, kernel);
Mat normalizImg;
cv::normalize(imgdil, normalizImg, 25, 255, NORM_MINMAX);
cv::normalize(normalizImg, normalizImg, 25, 255, NORM_MINMAX);
Mat thre;
adaptiveThreshold(normalizImg, thre, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY_INV, 25, 1.9);
cv::normalize(thre, normalizImg, 15, 255, NORM_MINMAX);
cv::normalize(normalizImg, normalizImg, 15, 255, NORM_MINMAX);
cv::normalize(normalizImg, thre, 17, 255, NORM_MINMAX);
string savingName = "fingerprints00/" + to_string(++cntr) + ".jpg";
imwrite(savingName, thre);
imshow("original image", inputImage);
//imshow("norm", normalizImg);
imshow("thresh", thre);
moveWindow("original image",0,0);
moveWindow("thresh",600,0);
waitKey(0);
}
return 0;
}
opencv c++ for fingerprint extraction from finger image,change the path, thank me later
Upvotes: 0
Reputation: 6666
@API55's comment is correct, for clarity:
create a mask (white inside the ellipse and black outside) you can do this with ellipse function and -1 in the thickness. Then copy the image using the mask (bitwise_and for python or copyTo for c++ should do it)... you will always have a squared image, but you will have black (or the color you want) outside the ellipse
These steps are pretty much spot on,
below is an example of how to implement this in code:
( I lovingly borrowed from here)
Mat img = imread("small1.png", 0); // load gray
Rect region(10,10,40,40); // example roi
Mat roi(img, region); // part of img
Mat mask(Size(40,40), CV_8U, Scalar(0)); // all black
circle(mask, Point(20,20), 20, Scalar(255), -1, LINE_AA); // filled circle
Mat circRoi;
bitwise_and(roi, roi, circRoi, mask); // retain only pixels inside the circle
//
// now you can do your intensity calculation on circRoi
//
imshow("circle masked", mask);
imshow("masked roi", circRoi);
waitKey();
Useful Links
Upvotes: 1