I am trying to subtract two float values from a .json file, but I keeping getting the an error. All of the other threads/documentation are more focused on subtracting from two separate dictionaries so I haven't found anything that works. Any help would be appreaciated.
traceback (most recent call last):
File "c:/Yolo_v4/darknet/build/darknet/x64/vision.py", line 46, in <module>
if(data["objects"][4] - data["objects"][12]) < 40:
TypeError: unsupported operand type(s) for -: 'dict' and 'dict'
Python:
input_file_path = 'C:\Yolo_v4\darknet\build\darknet\x64\result.json'
input_file = open(input_file_path, 'r')
results = json.load(input_file)
for data in results: # Loops over processed images
file_path = data['filename']
print("Processing image: " + file_path)
objects = data['objects']
for o in objects: # Loops over detected objects in image
class_id = o['class_id']
class_name = o['name']
coords = o['relative_coordinates']
xmid = coords['center_x']
ymid = coords['center_y']
width = coords['width']
height = coords['height']
confidence = o['confidence']
for i in range(len(data["objects"])):
for j in range(len(data["objects"])):
if j<=i:
# Avoid comparing same elements again.
# Eg. no need to compare 3 and 1 since you already did 1 and 3
pass
if(data["objects"][4] - data["objects"][12]) < 40:
print("Within Range")
.json:
[
{
"frame_id":1,
"filename":"C:\Yolo_v4\darknet\build\darknet\x64\f003.png",
"objects": [
{"class_id":41, "name":"z", "relative_coordinates":{"center_x":0.082398, "center_y":0.647144, "width":0.135836, "height":0.048884}, "confidence":0.971427},
{"class_id":4, "name":"3", "relative_coordinates":{"center_x":0.225985, "center_y":0.466635, "width":0.097890, "height":0.050788}, "confidence":0.925511},
]
}
]
Edit: Added full error file and more of the python code
question from:
https://stackoverflow.com/questions/65929457/cant-subtract-two-individual-dictionary-values 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…