# Face\_recognition

**URL:** <https://forum.opencv.org/t/face-recognition/3088>\
**Category:** Python\
**Tags:** videoio, dlib\
**Created:** [May 1, 2021, 4:04pm UTC](https://forum.opencv.org/t/face-recognition/3088 "2021-05-01T16:04:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mike](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mike/32/4250_2.png) [@mike](https://forum.opencv.org/u/mike)\
**Post date:** [May 1, 2021, 4:04pm UTC](https://forum.opencv.org/t/face-recognition/3088/1 "2021-05-01T16:04:10Z")

</div>

Hey, everyone! I am working with face recognition and i want the system to separate my face from others on the webcam image. Here is the code:

```
import cv2 as cv
import face_recognition as fr
face_known = fr.load_image_file(path to known face on my desktop)
encoding_F = fr.face_encodings(face_known)[0]
cap = cv.VideoCapture(1, cv.CAP_DSHOW)
cap.set(3, 1000)
cap.set(4, 700)

while True:
    tr, image = cap.read()
    encoding_S = fr.face_encodings(image)
    try:
        locat = fr.face_locations(image)
        for location in locat:
            for encoding in encoding_S:
                result = fr.compare_faces([encoding_F], encoding)
                face_dis = fr.face_distance([encoding_F], encoding)
                if result[0]:
                    cv.rectangle(image, (locat[0], locat[1]), (locat[2], locat[3]), (0,255,0), 2)
                    cv.putText(image, f'known {100*round(face_dis[0], 2)} %', (locat[0]+2, locat[1]-2), 
    cv.FONT_HERSHEY_TRIPLEX, 1, (0,255,0), 1)
                else:
                    cv.rectangle(image, (locat[0], locat[1]), (locat[2], locat[3]), (0, 0, 255), 2)
                    cv.putText(image, 'unknown', (locat[0] + 2, locat[1] - 2), 
    cv.FONT_HERSHEY_TRIPLEX, 1, (0,0,255), 1)
        cv.imshow('win', image)
        cv.waitKey(1)
    except IndexError:
        cv.imshow('win', image)
        cv.waitKey(1)

```

However, this code returns the following error:  
Traceback (most recent call last):  
File “C:\Users\mikha\PycharmProjects\pythonProject1\face\_rec.py”, line 34, in   
encoding\_S = fr.face\_encodings(image)  
File “C:\Users\mikha\PycharmProjects\pythonProject\venv\lib\site-packages\face\_recognition\api.py”, line 213, in face\_encodings  
raw\_landmarks = \_raw\_face\_landmarks(face\_image, known\_face\_locations, model)  
File “C:\Users\mikha\PycharmProjects\pythonProject\venv\lib\site-packages\face\_recognition\api.py”, line 156, in \_raw\_face\_landmarks  
face\_locations = \_raw\_face\_locations(face\_image)  
File “C:\Users\mikha\PycharmProjects\pythonProject\venv\lib\site-packages\face\_recognition\api.py”, line 105, in \_raw\_face\_locations  
return face\_detector(img, number\_of\_times\_to\_upsample)  
TypeError: **call** (): incompatible function arguments. The following argument types are supported:  
1. (self: \_dlib\_pybind11.fhog\_object\_detector, image: array, upsample\_num\_times: int=0) → \_dlib\_pybind11.rectangles  
Invoked with: \<\_dlib\_pybind11.fhog\_object\_detector object at  
0x0000012B20AEB070\>, None, 1Traceback (most recent call last):  
File “C:\Users\mikha\PycharmProjects\pythonProject1\face\_rec.py”, line 34, in  
  
encoding\_S = fr.face\_encodings(image)  
File “C:\Users\mikha\PycharmProjects\pythonProject\venv\lib\site-packages\face\_recognition\api.py”, line 213, in face\_encodings  
raw\_landmarks = \_raw\_face\_landmarks(face\_image, known\_face\_locations, model)  
File “C:\Users\mikha\PycharmProjects\pythonProject\venv\lib\site-packages\face\_recognition\api.py”, line 156, in \_raw\_face\_landmarks  
face\_locations = \_raw\_face\_locations(face\_image)  
File “C:\Users\mikha\PycharmProjects\pythonProject\venv\lib\site-  
packages\face\_recognition\api.py”, line 105, in \_raw\_face\_locations  
return face\_detector(img, number\_of\_times\_to\_upsample)  
TypeError: **call** (): incompatible function arguments. The following argument types are supported:  
1. (self: \_dlib\_pybind11.fhog\_object\_detector, image: array, upsample\_num\_times: int=0) → \_dlib\_pybind11.rectangles

```
Invoked with: <_dlib_pybind11.fhog_object_detector object at 0x0000012B20AEB070>, None, 1

```

I wonder if anyone can help…

---

<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:** [May 1, 2021, 4:40pm UTC](https://forum.opencv.org/t/face-recognition/3088/2 "2021-05-01T16:40:13Z")

</div>

> [@mike](#):
>
> Invoked with: \<\_dlib\_pybind11.fhog\_object\_detector object at  
> 0x0000012B20AEB070\>, None, 1Traceback

your image is invalid/empty/None, nothing came out of the capture  
you have to add a check here:

```auto
tr, image = cap.read()
if tr==False:
    print("no image")
    break
    

```

also please check (before the loop):

```
if not cap.isOpened():
     # bail out

```

and try another camera id, like 0

---

<div class="post-metadata">

**Author:** ![Daniel\_Adama](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/daniel_adama/32/1518_2.png) [@Daniel\_Adama](https://forum.opencv.org/u/Daniel_Adama)\
**Post date:** [May 1, 2021, 7:09pm UTC](https://forum.opencv.org/t/face-recognition/3088/3 "2021-05-01T19:09:31Z")

</div>

Yeah, you need to specify the input image

---

<div class="post-metadata">

**Author:** ![mike](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/mike/32/4250_2.png) [@mike](https://forum.opencv.org/u/mike)\
**Post date:** [May 2, 2021, 11:14am UTC](https://forum.opencv.org/t/face-recognition/3088/4 "2021-05-02T11:14:07Z")

</div>

Thanks a million!!!
