Код: Выделить всё
detected_objects.append({
"label": class_name,
"box": [int(x_start), int(y_start), int(x_end), int(y_end)],
"distance": float(distance)
})
#These are 2 seperate clips of code
@app.route('/detect', methods=['POST'])
def detect_objects():
# Read the image sent from Dart
file = request.files['image'].read()
npimg = np.frombuffer(file, np.uint8)
img = cv2.imdecode(npimg, cv2.IMREAD_COLOR)
# Run object detection and depth estimation
detected_objects, direction = detect_and_estimate_depth(img)
# Send response with object details and recommended direction
response = {
"objects": detected_objects, # Use it directly
"direction": str(direction)
}
return jsonify(response)
Я просто добавил float и int к каждому из объектов, чтобы он был "сериализуемым в формате JSON"
Подробнее здесь: https://stackoverflow.com/questions/791 ... t32-is-not