我的问题是我有ymin,xmin,ymax,xmax和盒子形状。
我无法提取检测到的对象,它只会显示所有图像而不是框。
我试过的
image_url = "https://upload.wikimedia.org/wikipedia/commons/6/60/Naxos_Taverna.jpg" #@param
downloaded_image_path = download_and_resize_image(image_url, 1280, 856, True)
import cv2
...
for i in range(min(boxes.shape[0], max_boxes)):
if scores[i] >= min_score:
ymin, xmin, ymax, xmax = tuple(boxes[i])
display_str = "{}: {}%".format(class_names[i].decode("ascii"),
int(100 * scores[i]))
color = colors[hash(class_names[i]) % len(colors)]
image_pil = Image.fromarray(np.uint8(image)).convert("RGB")
print(image_pil)
image = np.array(image_pil)
print(type(image))
import cv2
rect = cv2.rectangle(image, ((xmin), (ymin)), ((xmax), (ymax)), (0, 0, 255), 1)
print(ymin, xmin, ymax, xmax)
cv2_imshow(rect)
我使用以下API:https://www.tensorflow.org/hub/tutorials/object_detection一个物体检测的例子
ymin,xmin,ymax,xmax:0.6325336 0.2925815 0.92287964 0.40271035
对象类型:b'Chair'
最佳答案
ymin,xmin,ymax,xmax:0.6325336 0.2925815 0.92287964 0.40271035
(xmin, ymin), (xmax, ymax)
,添加不必要的括号((),())
会将整数定义为元组,这将导致错误。xmin = int(0.2925815 * img.shape[1])
xmax = int(0.40271035 * img.shape[1])
ymin = int(0.6325336 * img.shape[0])
ymax = int(0.92287964 * img.shape[0])
rect = cv2.rectangle(img, (xmin, ymin), (xmax, ymax), (0, 0, 255), 1)