我有一个CSV文件(.txt),包含CNN的检测结果:
CSV文件示例:
filename,type,confidence,xmin,ymin,xmax,ymax
27cz1_SLRM_0, barrow,87, 128, 176, 176, 224
27cz1_SLRM_101, barrow,80, 480, 400, 512, 432
27cz1_SLRM_103, celtic_field,85, 0, 112, 96, 256
27cz1_SLRM_103, celtic_field,80, 256, 384, 384, 544
27cz1_SLRM_103, celtic_field,80, 160, 96, 304, 272
27cz1_SLRM_103, barrow,85, 416, 160, 464, 208
27cz1_SLRM_107, celtic_field,84, 96, 448, 224, 576
27cz1_SLRM_107, barrow,94, 256, 432, 304, 480
27cz1_SLRM_107, barrow,87, 128, 368, 176, 416
27cz1_SLRM_107, barrow,84, 64, 304, 112, 352
27cz1_SLRM_107, barrow,80, 64, 208, 96, 240
坐标文件示例:
27cz1_SLRM_0, 179927.5, 475140.0
27cz1_SLRM_101, 183062.5, 476565.0
27cz1_SLRM_103, 183632.5, 476565.0
27cz1_SLRM_107, 184772.5, 476565.0
为了减少误报的数量,我想去掉类celtic_field
的所有单个检测。你知道吗
在上面的例子中,来自27cz1_SLRM_103
的celtic_field
检测应该保留,但是来自27cz1_SLRM_107
的celtic_field
检测应该删除。你知道吗
作为进一步处理的一部分,CSV作为字典打开,并变成GEOJSON
条目(见下文)。这个工作很好,但我想包括以上。你知道吗
coords = {}
coords_file = csv.reader(open(coordinate_location))
for row in coords_file:
coords[row[0]] = [float(row[1]),float(row[2])]
# open output file
output_file = csv.DictReader(open(output_location))
# turn detections into polygons
for row in output_file:
img_name = row['filename']
detection_class = row['type'].strip()
confidence = row['confidence']
#combo = row['filename'] + row['type']
#detection_type = detection['tool_label']
if detection_class == 'celtic_field':
detectionDict = {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": []
},
"properties": {
"detection_type": detection_class,
"confidence": confidence
}
}
polyCoords = []
coordinate_x_1 = coords[img_name][0] + float(row['xmin']) * 0.5
coordinate_x_2 = coords[img_name][0] + float(row['xmin']) * 0.5
coordinate_x_3 = coords[img_name][0] + float(row['xmax']) * 0.5
coordinate_x_4 = coords[img_name][0] + float(row['xmax']) * 0.5
coordinate_y_1 = coords[img_name][1] - float(row['ymin']) * 0.5
coordinate_y_2 = coords[img_name][1] - float(row['ymax']) * 0.5
coordinate_y_3 = coords[img_name][1] - float(row['ymax']) * 0.5
coordinate_y_4 = coords[img_name][1] - float(row['ymin']) * 0.5
polyCoords.append([coordinate_x_1,coordinate_y_1])
polyCoords.append([coordinate_x_2,coordinate_y_2])
polyCoords.append([coordinate_x_3,coordinate_y_3])
polyCoords.append([coordinate_x_4,coordinate_y_4])
polyCoords.append([coordinate_x_1,coordinate_y_1])
detectionDict['geometry']['coordinates'].append(polyCoords)
output['features'].append(detectionDict)
多亏了你们很多人(尤其是比利·博纳罗斯)的帮助,我找到了一个可行的解决方案:
非常感谢!你知道吗
试试这个:
打印(df)
相关问题 更多 >
编程相关推荐