Hi,
I am using dlib for a project in my company.Since the whole model currently runs on odroid xu4, computation takes some more time so i decided to do some optimizations.I am using python API.
To either change the coordinates of the returned dlib.rectangle object or convert python tuple to dlib.rectangle type object.
I looked into the docs but found get_rect, grow_rect listed in python API but doing dir(dlib) didn't show any of these methods. Also dlib.rectangle object returned by get_frontal_face_detector is read-only.
How can i solve this issue?
I remember I faced the same problem.
The dlib get_frontal_face_detector returns read-only tuple of FaceBox RectangleS.
You want to change them?
If you want to make a new dlib rectangle from them, you may have to do
faceBoxRectangleS = tuple of dlib.rectangle(left=someNewLeftValue, top=someNewTopValue, right=someNewRightValue, bottom=someNewBottomValue)
It worked!!. Thanks @satoyoshiharu .
@satoyoshiharu @shang-vikas , I have a similar issue but I don't understand this solution very well, a complete line of code would be insightful, can you help me out? Here is my code...
face_detector = dlib.get_frontal_face_detector()
detected_faces = face_detector(image, 1)
for face in detected_faces:
# These are the specific changes that I want to make to face.top, face.left etc..
top = max(0, face.top())
bottom = min(face.bottom(), image.shape[0])
left = max(0, face.left())
right = min(face.right(), image.shape[1])
# Finally, I have to pass this face object into the encode_faces function that I have created
encoding = encode_faces(image, face)
If detections is list of rectangle coordinates obtained from Opencv
left = detections[0]
top = detections[1]
right = detections[2]
bottom = detections[3]
dlibRect = dlib.rectangle(left, top, right, bottom)
dlibRect will be dlib type rectangle.
can everyone here use triple ``` to encapsulate your code? thanks
while you use Python, you should use:
left, top, right, bottom = rect
dlibrect = dlib.rectangle(int(left), int(top), int(right), int(bottom))
because when i use @Varat7v2 code i counter a mistake:
Boost.Python.ArgumentError: Python argument types in
rectangle.__init__(rectangle, float, float, float, float)
did not match C++ signature:
__init__(struct _object * __ptr64, long left, long top, long right, long bottom)
__init__(struct _object * __ptr64)
PS F:FACE_REGmb_tiny_RFB> python
Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Most helpful comment
I remember I faced the same problem.
The dlib get_frontal_face_detector returns read-only tuple of FaceBox RectangleS.
You want to change them?
If you want to make a new dlib rectangle from them, you may have to do
faceBoxRectangleS = tuple of dlib.rectangle(left=someNewLeftValue, top=someNewTopValue, right=someNewRightValue, bottom=someNewBottomValue)