ImageAI
ImageAI copied to clipboard
OpenCV: TypeError: an integer is required (got type list)
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)
Hi, did you end up solving this problem? I have the same issue currently
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.
Same issue
same issue
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)
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)
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)
Did you solve this issue?
嗨,你最终解决了这个问题吗?我目前有同样的问题
不,我没有。我放弃了该程序,因为我无法工作。
你解决了这个问题吗?