【发布时间】:2020-11-15 10:25:10
【问题描述】:
我正在尝试检测图像上的人,目的是将边界框和置信度值的信息作为具有相应置信度和边界框的值保存到文本文件中。但我收到错误TypeError: write() argument must be str, not bytes 或 TypeError: write() argument must be str, not numpy.ndarray
for i in np.arange(0, person_detections.shape[2]):
confidence = person_detections[0, 0, i, 2]
if confidence > 0.5:
idx = int(person_detections[0, 0, i, 1])
if CLASSES[idx] != "person":
continue
person_box = person_detections[0, 0, i, 3:7] * np.array([W, H, W, H])
(startX, startY, endX, endY) = person_box.astype("int")
preds = np.append(person_box, confidence) # Add confidence to array
preds_string = preds.tostring() # Convert array to string
# To convert back to numpy array
bbox = np.fromstring(preds_string, dtype=int)
info = open("output.txt","w")
info.write(bbox)
info.close
我无法将它们保存并写入文本文件,这是我上面的代码,如果可能,我将不胜感激,谢谢
【问题讨论】:
标签: python loops file detection