Skip to content

Commit

Permalink
erase tfl_black
Browse files Browse the repository at this point in the history
  • Loading branch information
gaoyi committed Dec 29, 2023
1 parent 58bb091 commit 90ed18a
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 32 deletions.
Empty file modified .gitignore
100644 → 100755
Empty file.
22 changes: 11 additions & 11 deletions Config/category2id_hashmap.txt
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ vehicle b404ed3c370c8c264e53b1867929db93e94012bb618bb263f514e32fd9e5bc29 11
barrier f0dc3075f012ecffa9225a29f5dda815bb4aac0c0f97edfb894152c1e7e0ec1d 12
portable 01e782826ae5182220bd6158f883d01ceb1bce659dc020e7c511f802a9aa7737 13
bendy 69a4fc72339ed264135236864a2c20d74cc8e8a87bd199f8e41dfba8615c15fa 14
RoadArrow_straight bed2ffc1cc3cab4848a291fbbbe6953b611e10a53001f9f8ac7bbfdcea9de809 15
RoadArrow_straight_right ac5d9bfe379d87fd2c56f3cf22190d16df532701368f207cb24a0a566ee511a7 16
RoadArrow_left b2158be770e88df8d8b6ebcc8ee35cb80d2ede6a21047f31a61e37fc2db4917c 17
RA_straight c8c9b36dd59aad2e40a59df78b7f143ca16b14fb2169345023896b38d28cc2c5 15
RA_straight_right bfd12aad78c5e9f4ed74c52bdd63105ddbca3c151d30f5f3a6bc532babe22365 16
RA_left 3284e6acaa0c40001de590789a918b2ebb6264f9d0e597952085fdbda6e025d5 17
stop_line 586e3a72234c910a8728987363317ee6f5f758e4e55d1d45e5d5571c4172d8ae 18
crosswalk 56421536c7a368a0bacb9fd125c0be4d96e187b3cbfa264cde540025e0efc865 19
RoadArrow_straight_left 9f04c3f993a2b1419d5cc428b121a2cd9276eb27e28e622365bc5e0289aaf301 20
RoadArrow_right a86a6c5680f213a6d8569f946fea835bfdc15e27111c5e1b86875d54b7fb8346 21
RoadArrow_left_right 00b24704bb8b83ff053fbd48b5a2dc5842616a6da3aebd075f321e84afbfbbfa 22
RoadArrow_u-turn 5abf1241122624bfa94b4368f13116a02501a8380376690172967973ecf87307 23
RoadArrow_right_bend 459f311afb46616e48a9c80aab7ab80e91156c063a10ace3044d85a621f5a171 24
RoadArrow_left_bend 462e66e0caf46eac3b569cd7d0c27a117ea1905c9312e7cd6502576b8d911de8 25
RoadArrow_left_u-turn 5e613ff31f74d5d33a9b23b580a4e8311963eab1d1f57e8274834d925441301c 26
RoadArrow_straight_u-turn 4f8bc2abac43ed80480b0aa5eaa8aa1839139d091a8e7284e727bb5cee05d3b2 27
RA_straight_left dd564634cc41c695af3e3d8aa52e71f4a60df81d5220ec33c03963471ec8e1a2 20
RA_right 95ab273bfd3c028a43044d4749999bd2c5f6b740e00663699fe8acd67cc9158e 21
RA_left_right fb23a29166c2f6f3d0d31f458da857bda6a3f43763c5cf23c5940d328f726a63 22
RA_u-turn 91b8f05e13d8eefb987ed3061568e6953c74a4a29768ecb3dbe870670b4222ea 23
RA_right_bend 0c1e10f3780e24d0a19369ae371fbae8a290fe05474af95208b29c94a84260ab 24
RA_left_bend 25ef19027755cdb52b545ba84eeea4821701df29e7d62343043a3cf0ec47cd52 25
RA_left_u-turn 6bacae4f1316cfcbf10d8a3dee512ba7ad6c1ef16df63937d47c462393cfaf7d 26
RA_straight_u-turn 85ebcbdf45012c79473600de6b99c0eb2579ec524dff7477f1a7209dc1fd3be4 27
TFL_black 77e4925888286cf6c011cea16de72435f5d2197a596ab404e0709c3b045ac0f1 28
TFL_red ccbf596a4032cc173bd6bd58e84ece0021033216f0697216f90ffbb4a954a203 29
TFL_green 22b22910bc2dd34d0d9791e968fb63634bd13cccc3bf2c54b5510f87e1b97697 30
Expand Down
Empty file modified Package.resolved
100644 → 100755
Empty file.
Empty file modified Package.swift
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified Sources/Models/axera_shape.swift
100644 → 100755
Empty file.
Empty file modified Sources/Models/coco_anno.swift
100644 → 100755
Empty file.
Empty file modified Sources/Models/python_util.swift
100644 → 100755
Empty file.
Empty file modified Sources/Models/python_util_tmp.swift
100644 → 100755
Empty file.
22 changes: 21 additions & 1 deletion Sources/Models/utils.swift
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import Foundation

// function to check if box A inside box B
func checkBox(insA: AxeraInstance, insB: AxeraInstance) -> Bool {
// calculate intersection
switch insA.children[0].cameras[0].frames[0].shape {
case let .rectangle(rectA):
switch insB.children[0].cameras[0].frames[0].shape {
case let .rectangle(rectB):
// check if boxA inside boxB
if rectA.x >= rectB.x && rectA.y >= rectB.y && rectA.x + rectA.width <= rectB.x + rectB.width && rectA.y + rectA.height <= rectB.y + rectB.height {
return true
}
return false
default:
return false
}
default:
return false
}
}

func extractCocoSeg(axera_inst: AxeraInstance) -> [[Double]] {
var polygon_points_array = [[Double]]()
for child in axera_inst.children {
Expand Down Expand Up @@ -252,7 +272,7 @@ func supercategory2category(supercategory: String, type: String, color: String,
}
case "路面箭头":
if type != "unknown" {
res = "RoadArrow_" + type
res = "RA_" + type
}

case "交通标志":
Expand Down
76 changes: 56 additions & 20 deletions Sources/cli.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct SwiftCOCO: ParsableCommand {
}

private func convert3D(axeraAnnoPath: [String], axeraImgPath: String, scalingType: String) {
let hwRatioThreshold = 4.0
print("Processing 3D annotations")
var jsonsURLs = [URL]()
for path in axeraAnnoPath {
Expand Down Expand Up @@ -141,6 +142,28 @@ struct SwiftCOCO: ParsableCommand {
if bbox2d_8p.count == 0 {
continue
}
var cur_box_x_max = min(1920, bbox2d_8p[0].x)
var cur_box_y_max = min(1080, bbox2d_8p[0].y)
var cur_box_x_min = max(0, bbox2d_8p[0].x)
var cur_box_y_min = max(0, bbox2d_8p[0].y)
for i in 0 ..< bbox2d_8p.count {
if bbox2d_8p[i].x < cur_box_x_min {
cur_box_x_min = max(0, bbox2d_8p[i].x)
}
if bbox2d_8p[i].x > cur_box_x_max {
cur_box_x_max = min(1920, bbox2d_8p[i].x)
}
if bbox2d_8p[i].y < cur_box_y_min {
cur_box_y_min = max(0, bbox2d_8p[i].y)
}
if bbox2d_8p[i].y > cur_box_y_max {
cur_box_y_max = min(1080, bbox2d_8p[i].y)
}
}
let hwRatio = (Double(cur_box_y_max - cur_box_y_min) / Double(cur_box_x_max - cur_box_x_min))
if hwRatio > hwRatioThreshold {
continue
}
// create image entry if not exist
let file_path = imageURL + "/" + cur_json.deletingPathExtension().appendingPathExtension("jpg").lastPathComponent
if file_name2id[file_path] == nil {
Expand Down Expand Up @@ -184,24 +207,6 @@ struct SwiftCOCO: ParsableCommand {
coco_json.categories.append(CocoCategory(id: curCategoryId!, name: category, supercategory: supercategory))
}
// create coco instance
var cur_box_x_max = min(1920, bbox2d_8p[0].x)
var cur_box_y_max = min(1080, bbox2d_8p[0].y)
var cur_box_x_min = max(0, bbox2d_8p[0].x)
var cur_box_y_min = max(0, bbox2d_8p[0].y)
for i in 0 ..< bbox2d_8p.count {
if bbox2d_8p[i].x < cur_box_x_min {
cur_box_x_min = max(0, bbox2d_8p[i].x)
}
if bbox2d_8p[i].x > cur_box_x_max {
cur_box_x_max = min(1920, bbox2d_8p[i].x)
}
if bbox2d_8p[i].y < cur_box_y_min {
cur_box_y_min = max(0, bbox2d_8p[i].y)
}
if bbox2d_8p[i].y > cur_box_y_max {
cur_box_y_max = min(1080, bbox2d_8p[i].y)
}
}
var coco_anno_seg = [[Double]]()
var curSeg = [Double]()
curSeg.append(cur_box_x_min)
Expand Down Expand Up @@ -368,7 +373,11 @@ struct SwiftCOCO: ParsableCommand {
}

// create a set to store different names
for inst in axera_img_anno.instances! {
var blackBoxes = [AxeraInstance]()
for idx in 0 ..< axera_img_anno.instances!.count {
var inst = axera_img_anno.instances![idx]

// for inst in axera_img_anno.instances! {
let supercategoryName = inst.categoryName
// TODO: intergreate this swich syntax to logging system
switch supercategoryName {
Expand Down Expand Up @@ -415,6 +424,9 @@ struct SwiftCOCO: ParsableCommand {
let categoryName = supercategory2category(supercategory: supercategoryName, type: inst.attributes?["type"] ?? "unknown", color: inst.attributes?["color"] ?? "unknown", typeCN: inst.attributes?["类型"] ?? "unknown")
if categoryName == "unknown" {
continue
} else if categoryName == "TFL_black" {
blackBoxes.append(inst)
continue
} else {
counter[supercategoryName] = counter[supercategoryName] ?? [:]
counter[supercategoryName]![categoryName] = (counter[supercategoryName]![categoryName] ?? 0) + 1
Expand Down Expand Up @@ -461,6 +473,15 @@ struct SwiftCOCO: ParsableCommand {
coco_json.images.append(cocoImage)
}

if categoryName.starts(with: "TFL") {
for blackBox in blackBoxes {
let intersected = checkBox(insA: inst, insB: blackBox)
if intersected {
inst.children[0].cameras[0].frames[0].shape = blackBox.children[0].cameras[0].frames[0].shape
break
}
}
}
let coco_anno_seg = extractCocoSeg(axera_inst: inst)
let coco_anno_bbox = calBboxFromCocoSeg(polygon_points_array: coco_anno_seg)
let cur_box_area = coco_anno_bbox[2] * coco_anno_bbox[3]
Expand Down Expand Up @@ -605,7 +626,10 @@ struct SwiftCOCO: ParsableCommand {
}

// create a set to store different names
for inst in axera_img_anno.instances! {
var blackBoxes = [AxeraInstance]()
for idx in 0 ..< axera_img_anno.instances!.count {
var inst = axera_img_anno.instances![idx]
// for inst in axera_img_anno.instances! {
let supercategoryName = inst.categoryName
// TODO: intergreate this swich syntax to logging system
switch supercategoryName {
Expand Down Expand Up @@ -652,6 +676,9 @@ struct SwiftCOCO: ParsableCommand {
let categoryName = supercategory2category(supercategory: supercategoryName, type: inst.attributes?["type"] ?? "unknown", color: inst.attributes?["color"] ?? "unknown", typeCN: inst.attributes?["类型"] ?? "unknown")
if categoryName == "unknown" {
continue
} else if categoryName == "TFL_black" {
blackBoxes.append(inst)
continue
} else {
counter[supercategoryName] = counter[supercategoryName] ?? [:]
counter[supercategoryName]![categoryName] = (counter[supercategoryName]![categoryName] ?? 0) + 1
Expand Down Expand Up @@ -698,6 +725,15 @@ struct SwiftCOCO: ParsableCommand {
coco_json.images.append(cocoImage)
}

if categoryName.starts(with: "TFL") {
for blackBox in blackBoxes {
let intersected = checkBox(insA: inst, insB: blackBox)
if intersected {
inst.children[0].cameras[0].frames[0].shape = blackBox.children[0].cameras[0].frames[0].shape
break
}
}
}
let coco_anno_seg = extractCocoSeg(axera_inst: inst)
let coco_anno_bbox = calBboxFromCocoSeg(polygon_points_array: coco_anno_seg)
let cur_box_area = coco_anno_bbox[2] * coco_anno_bbox[3]
Expand Down
Empty file modified Tests/MyTests/MyTests.swift
100644 → 100755
Empty file.

0 comments on commit 90ed18a

Please sign in to comment.