# Fingerprint in python with opencv

**URL:** <https://forum.opencv.org/t/fingerprint-in-python-with-opencv/15010>\
**Category:** Python\
**Tags:** programming\
**Created:** [October 27, 2023, 11:59am UTC](https://forum.opencv.org/t/fingerprint-in-python-with-opencv/15010 "2023-10-27T11:59:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![aamirquerishi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/aamirquerishi/32/8982_2.png) [@aamirquerishi](https://forum.opencv.org/u/aamirquerishi)\
**Post date:** [October 27, 2023, 11:59am UTC](https://forum.opencv.org/t/fingerprint-in-python-with-opencv/15010/1 "2023-10-27T11:59:57Z")

</div>

Sir this is my code

```auto

import glob
import cv2
import numpy as np
import os
fingerprint_test = cv2.imread("D:/mfapython/muhammadisthebest.tif")
cv2.imshow("Original", cv2.resize(fingerprint_test, None, fx=1, fy=1))
cv2.waitKey(0)
cv2.destroyAllWindows()

for file in [file for file in os. listdir("d:/mfapython/fingerprintdatabase/*.tif")]:
    fingerprint_database_image = cv2.imread("./database/"+file)
    fingerprint_database_image = [cv2.imread(file) for file in glob.glob("d:/mfapython/fingerprintdatabase/*.tif")]
    sift = cv2.SIFT_create()
    keypoints_1, descriptors_1 = sift.detectAndCompute(fingerprint_test, None)
    keypoints_2, descriptors_2 = sift.detectAndCompute(fingerprint_database_image, None)

```

see error

```auto

cv2.error: OpenCV(4.8.1) D:\a\opencv-python\opencv-python\opencv\modules\features2d\src\sift.dispatch.cpp:512: error: (-5:Bad argument) image is empty or has incorrect depth (!=CV_8U) in function 'cv::SIFT_Impl::detectAn
computer
image is empty or has incorrect depth (!=CV_8U) in function 'cv::SIFT_Impl::detectAn

```

this line gives me the error

please guide me on how to resolve this error

Regard’s

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 27, 2023, 12:48pm UTC](https://forum.opencv.org/t/fingerprint-in-python-with-opencv/15010/2 "2023-10-27T12:48:22Z")

</div>

> [@aamirquerishi](#):
>
> ```auto
> fingerprint_database_image = cv2.imread("./database/"+file)
> fingerprint_database_image = [cv2.imread(file) for file in glob.glob("d:/mfapython/fingerprintdatabase/*.tif")]
> 
> ```

what do you want to do here ?  
why do you assign _twice_ to `fingerprint_database_image` ?  
why an image _list_ ?

---

<div class="post-metadata">

**Author:** ![aamirquerishi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/aamirquerishi/32/8982_2.png) [@aamirquerishi](https://forum.opencv.org/u/aamirquerishi)\
**Post date:** [October 28, 2023, 3:23pm UTC](https://forum.opencv.org/t/fingerprint-in-python-with-opencv/15010/3 "2023-10-28T15:23:28Z")

</div>

sir sir, you are right now this is my code, and faced a new error in the last line

import glob  
import cv2  
import numpy as np  
import os  
fingerprint\_test = cv2.imread(“e:/21cccc/mfaamir.tif”)  
cv2.imshow(“Original”, cv2.resize(fingerprint\_test, None, fx=1, fy=1))  
cv2.waitKey(0)  
cv2.destroyAllWindows()  
#for file in [file for file in os.listdir(“E:/21cccc/database/_.tif")]:  
for file in [file for file in os.listdir(“E:/21cccc/database”)]:  
fingerprint\_database\_image = [cv2.imread(file) for file in glob.glob("E:/21cccc/database/_.tif”)]  
sift = cv2.SIFT\_create()  
keypoints\_1, descriptors\_1 = sift.detectAndCompute(fingerprint\_test, None)  
keypoints\_2, descriptors\_2 = sift.detectAndCompute(fingerprint\_database\_image, None)

see error

Traceback (most recent call last):  
File “e:\py\newfortest.py”, line 15, in   
keypoints\_2, descriptors\_2 = sift.detectAndCompute(fingerprint\_database\_image, None)  
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
cv2.error: OpenCV(4.7.0) 👎 error: (-5:Bad argument) in function ‘detectAndCompute’

> Overload resolution failed:
> 
> - image is not a numpy array, neither a scalar
> - Expected Ptrcv::UMat for argument ‘image’

thank’s in advance for your valuable reply  
regard’s

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 28, 2023, 3:28pm UTC](https://forum.opencv.org/t/fingerprint-in-python-with-opencv/15010/4 "2023-10-28T15:28:01Z")

</div>

it does not expect a _list_ of images (again !)

then, please, you MUST CHECK the outcome of imread() !  
you MUST !!! ALWAYS !!!  
if it does not load, you produce errors way down later in your code, and you dont know why …

---

<div class="post-metadata">

**Author:** ![aamirquerishi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/aamirquerishi/32/8982_2.png) [@aamirquerishi](https://forum.opencv.org/u/aamirquerishi)\
**Post date:** [October 28, 2023, 4:28pm UTC](https://forum.opencv.org/t/fingerprint-in-python-with-opencv/15010/5 "2023-10-28T16:28:35Z")

</div>

sorry sir I disturb you again and again  
Please send me the sample code for how to load the fingerprint image  
and compare it with the current image

please send me the sample code

thank you in advance for your help

regards

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 29, 2023, 6:42am UTC](https://forum.opencv.org/t/fingerprint-in-python-with-opencv/15010/7 "2023-10-29T06:42:04Z")

</div>

no i won’t

maybe you can [read a bit here](https://www.packtpub.com/product/opencv-3-blueprints/9781784399757) (ch 6)

but in the end, you will need actual programming & research skills to achieve something, that’s SOTA.
