ImageAI icon indicating copy to clipboard operation
ImageAI copied to clipboard

OpenCV: TypeError: an integer is required (got type list)

Open alcarazzam opened this issue 5 years ago • 8 comments

Environment

Python 3.7.4 ImageAI 2.1.3 opencv-python 4.1.0.25 tensorflow 1.13.1

Details

When running the following script using a custom model, ImageAI raises an error when drawing the rectangle of the recognized object.

from imageai.Detection.Custom import CustomObjectDetection

detector = CustomObjectDetection()
detector.setModelTypeAsYOLOv3()
detector.setModelPath("chess-pieces-dataset/models/detection_model-ex-02--loss-25.59.h5") 
detector.setJsonPath("chess-pieces-dataset/json/detection_config.json")
detector.loadModel()


detections = detector.detectObjectsFromImage(input_image="test.jpg", output_image_path="test-detected.jpg")

for detection in detections:
    print(detection["name"], " : ", detection["percentage_probability"], " : ", detection["box_points"])

Error:

File "[...]/venv/lib/python3.7/site-packages/imageai/Detection/Custom/__init__.py", line 1369, in draw_boxes_and_caption
    image_frame = cv2.rectangle(image_frame, (x1, y1), (x2, y2), class_color, 2)
TypeError: an integer is required (got type list)

alcarazzam avatar Aug 26 '19 10:08 alcarazzam

Hi, did you end up solving this problem? I have the same issue currently

RyanThomas0 avatar Feb 27 '20 17:02 RyanThomas0

Hi, did you end up solving this problem? I have the same issue currently

No, I don't. I drop the program since I couldn't manage to work.

alcarazzam avatar Feb 29 '20 12:02 alcarazzam

Same issue

vrjmath avatar Apr 16 '20 20:04 vrjmath

same issue

kartikpateldev avatar Jun 23 '20 08:06 kartikpateldev

It helped me to do the following in another application where I also use cv2.rectangle, to cast the variables image_frame = cv2.rectangle(image_frame, (int(x1), int(y1)), (int(x2), int(y2)), class_color, 2)

RDLL avatar Feb 20 '21 21:02 RDLL

i am facing the same issue when using iamgeai :

/usr/local/lib/python3.7/dist-packages/imageai/Detection/Custom/init.py:1234: RuntimeWarning: overflow encountered in exp return 1. / (1. + np.exp(-x))

TypeError Traceback (most recent call last) in () ----> 1 detections = detector.detectObjectsFromImage(input_image='/content/drive/MyDrive/number_plate/train/images/Cars102.png', output_image_path='nplate1-detected.jpg') 2 3 for obj in detections: 4 print (obj['name']) 5 print (obj['percentage_probability'])

1 frames /usr/local/lib/python3.7/dist-packages/imageai/Detection/Custom/init.py in draw_boxes_and_caption(self, image_frame, v_boxes, v_labels, v_scores, show_names, show_percentage) 1364 class_color = self.label_color(self.__labels.index(v_labels[i])) 1365 -> 1366 image_frame = cv2.rectangle(image_frame, (x1, y1), (x2, y2), class_color, 2) 1367 1368 label = ""

TypeError: an integer is required (got type list)

karthikkodakandla avatar Mar 30 '21 07:03 karthikkodakandla

Did you solve this issue?

2292269971 avatar Oct 28 '23 10:10 2292269971

嗨,你最终解决了这个问题吗?我目前有同样的问题

不,我没有。我放弃了该程序,因为我无法工作。

你解决了这个问题吗?

2292269971 avatar Oct 28 '23 10:10 2292269971