## DEV Community is a community of 660,470 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

# cv2.rectangle() function error

Samiul Baree Sifat
I am a CSE student.

I am writing a deep learning code that needs to detect very tiny faces. I found an implementation of tiny face detects paper in Github using TensorFlow. The code have to draw rectangles around faces in the image but the open cv cv2.rectangle() function giving TypeError. But I couldn't figure out exactly what is this error, searched the whole net found one or two issues talking about the argument being float is the problem.

This is my code to draw a rectangle in the given image:

``````    def overlay_bounding_boxes(raw_img, refined_bboxes, lw):

"""Overlay bounding boxes of face on images.
Args:
raw_img:
A target image.
refined_bboxes:
Bounding boxes of detected faces.
lw:
The line width of bounding boxes. If zero specified,
this is determined based on the confidence of each detection.
Returns:
None.
"""
# Overlay bounding boxes on an image with the color based on the confidence.
for r in refined_bboxes:
_score = expit(r[4])
cm_idx = int(np.ceil(_score * 255))
rect_color = [int(np.ceil(x * 255)) for x in util.cm_data[cm_idx]]  # parula
_lw = lw
if lw == 0:  # line width of each bounding box is adaptively determined.
bw, bh = r[2] - r[0] + 1, r[3] - r[0] + 1
_lw = 1 if min(bw, bh) <= 20 else max(2, min(3, min(bh / 20, bw / 20)))
_lw = int(np.ceil(_lw * _score))

_r = [int(x) for x in r[:4]]

cv2.rectangle(raw_img, (_r[0], _r[1]), _r[2], _r[3]), rect_color, int(_lw))
``````

The error it's giving is:

``````Traceback (most recent call last):

File "D:/PYTHON PROJECTS/Digital Attendance System (knn)/Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py", line 242, in <module>
main()
File "D:/PYTHON PROJECTS/Digital Attendance System (knn)/Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py", line 235, in main
evaluate(
File "D:/PYTHON PROJECTS/Digital Attendance System (knn)/Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py", line 200, in evaluate
overlay_bounding_boxes(raw_img, refined_bboxes, lw)
File "D:/PYTHON PROJECTS/Digital Attendance System (knn)/Tiny_Faces_in_Tensorflow-master/tiny_face_eval.py", line 62, in overlay_bounding_boxes
cv2.rectangle(raw_img, (_r[0], _r[1]), (_r[2],_r[3]), rect_color, _lw)
TypeError: function takes exactly 4 arguments (2 given)
``````

I checked every argument data type which is integer obviously as the solutions I've found issued by others that one of the arguments being float is the problem.

What is the actual problem here? Thanks in advance!