# Integrating the DLib Library on the Code

**URL:** <https://forum.opencv.org/t/integrating-the-dlib-library-on-the-code/15422>\
**Category:** Python\
**Tags:** facerecognition, programming\
**Created:** [November 6, 2023, 5:29am UTC](https://forum.opencv.org/t/integrating-the-dlib-library-on-the-code/15422 "2023-11-06T05:29:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bwajster](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/bwajster/32/7789_2.png) [@bwajster](https://forum.opencv.org/u/bwajster)\
**Post date:** [November 6, 2023, 5:29am UTC](https://forum.opencv.org/t/integrating-the-dlib-library-on-the-code/15422/1 "2023-11-06T05:29:37Z")

</div>

The code below is for facial recognition on OpenCV using the Jetson Nano.I’ve installed the DLib 19.24.2 Library and need help incorporating the DLib Library on the code below:

```auto
import face_recognition
import cv2
import os
import pickle
import time
print(cv2. __version__ )

Encodings=[]
Names=[]

with open('train.pkl','rb') as f:
Names=pickle.load(f)
Encodings=pickle.load(f)
font=cv2.FONT_HERSHEY_SIMPLEX

cam= cv2.VideoCapture(1)

while True:

_,frame=cam.read()
frameSmall=cv2.resize(frame,(0,0),fx=.25,fy=.25)
frameRGB=cv2.cvtColor(frameSmall,cv2.COLOR_BGR2RGB)
facePositions=face_recognition.face_locations(frameRGB,model='cnn')
allEncodings=face_recognition.face_encodings(frameRGB,facePositions)
for (top,right,bottom,left),face_encoding in zip(facePositions,allEncodings):
name='Unkown Person'
matches=face_recognition.compare_faces(Encodings,face_encoding)
if True in matches:
first_match_index=matches.index(True)
name=Names[first_match_index]
top=top*4
right=right*4
bottom=bottom*4
left=left*4
cv2.rectangle(frame,(left,top),(right, bottom),(0,0,255),2)
cv2.putText(frame,name,(left,top-6),font,.75,(0,0,255),2)
cv2.imshow('Picture',frame)
cv2.moveWindow('Picture',0,0)
if cv2.waitKey(1)==ord('q'):
break

cam.release()
cv2.destroyAllWindows()

```

The code above gives a really low output video frame rate(about ~1fps) on the Jetson nano, need help incorporating the DLib library on the code above.  
Also, how can I improve the output video frame rate on the Jetson Nano? I wish to acheive a outut video frame rate of about 25-30FPS.

Kindly please 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:** [November 6, 2023, 6:46am UTC](https://forum.opencv.org/t/integrating-the-dlib-library-on-the-code/15422/2 "2023-11-06T06:46:25Z")

</div>

- this is the opencv site, we cannot help much with dlib (or any other arbitrary python code). still, try swapping dlib for opencv’s DetectionModel or similar
- please _profile_ your code, so you don’t have to _guess_, where the bottleneck is
- you need face _recognition_ at 25 fps ? what for ? sounds absurd.
- request a smaller resolution from the cam, instead of manual resize to 1/4
