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
	}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值