bbd 数据标注信息使用 AWK 抽取

这个标注信息比较规范,使用AWK较为方便, 不使用 python 了

            {
                "category": "traffic light",
                "attributes": {
                    "occluded": false,
                    "truncated": false,
                    "trafficLightColor": "green"
                },
                "manualShape": true,
                "manualAttributes": true,
                "box2d": {
                    "x1": 768.55365,
                    "y1": 237.006353,
                    "x2": 796.524897,
                    "y2": 252.740179
                },
                "id": 427
            },

抽取代码如下

BEGIN{
LIGHT = 0
}
{
	if($0 ~ /name/)
	{
		idx = index($0, ":")
		name = substr($0, idx+3, length($0) -1 - (idx+3))
	}
	if($0 ~ /category/ && $0 ~ /traffic light/)
	{
		LIGHT = 1
	}
	if(LIGHT == 1 && $0 ~ /trafficLightColor/)
	{
		idx = index($0, ":")
		Class = substr($0, idx+3, length($0) - (idx+3))
		#print NR , Class
		#LIGHT = 0
	}
	if(LIGHT == 1 && $0 ~ /x1/)
	{
		idx = index($0, ":")
		x1 = substr($0, idx+2, length($0) - (idx+2))
		#print NR , x1
		#LIGHT = 0
	}
	if(LIGHT == 1 && $0 ~ /y1/)
	{
		idx = index($0, ":")
		y1 = substr($0, idx+2, length($0) - (idx+2))
		#print NR , x1
		#LIGHT = 0
	}
	if(LIGHT == 1 && $0 ~ /x2/)
	{
		idx = index($0, ":")
		x2 = substr($0, idx+2, length($0) - (idx+2))
		#print NR , x1
		#LIGHT = 0
	}
	if(LIGHT == 1 && $0 ~ /y2/)
	{
		idx = index($0, ":")
		y2 = substr($0, idx+2, length($0) +1 - (idx+2))
		#print NR , x1
		LIGHT = 0
		
		print name",1280,720,"Class","x1","y1","x2","y2
	}
}

你可能感兴趣的:(Tools)