<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      【cv-python基礎】不同數據集的解析

      前言

      數據集使用之前需要對標注文件進行解析,故此記錄。

      代碼實現

      1. APA數據集解析

      # 20240612: parse jsonfile to labeled image.
      import argparse
      import json
      import os
      import os.path as osp
      import cv2 as cv
      import numpy as np
      
      jsonfilename = "freespace_3Dbox_APA.json"
      imagepath = "image_APA"
      polygon = {'Chock block', 'Convex Mirror', 'Crosswalk', 'Curb', 'Dashed line', 'Directional arrow', 'Fire Extinguisher', 'Fire hydrant', 'Floating edge', 'Free space', 'Motor vehicle', 'Non-motorized vehicle', 'Other Obstacles', 'Parking line', 'Parking number', 'Pedestrian', 'Pylon', 'Solid line', 'Speed bump', 'Steel pipe', 'Traffic cone', 'Wheel lock', 'background'}
      bbox2d = {'Chock block 2D', 'Convex Mirror 2D', 'Fire Extinguisher 2D', 'Fire hydrant 2D', 'Motor vehicle 2D', 'Non-motorized vehicle 2D', 'Other Obstacles 2D', 'Pedestrian 2D', 'Steel pipe 2D', 'Traffic cone 2D', 'Tyre', 'Wheel lock 2D'}
      bbox3d = {'Motor vehicle 3D'}
      
      colors = {# BGR
              'Chock block'              : (251, 56, 56), 
              'Chock block 2D'           : (247,136, 58), 
              'Convex Mirror'            : ( 48,132, 48), 
              'Convex Mirror 2D'         : ( 56,148,228), 
              'Crosswalk'                : (243, 27,243), 
              'Curb'                     : ( 22,220,220), 
              'Dashed line'              : (255,192,203), 
              'Directional arrow'        : (  0,  0,128), 
              'Fire Extinguisher'        : (  0,255,  0), 
              'Fire Extinguisher 2D'     : (255,255,  0), 
              'Fire hydrant'             : (247, 72,249), 
              'Fire hydrant 2D'          : (103,198,209), 
              'Floating edge'            : ( 88,139, 70), 
              'Free space'               : (172,227, 65), 
              'Motor vehicle'            : ( 76,213,174), 
              'Motor vehicle 2D'         : ( 50, 83, 83), 
              'Motor vehicle 3D'         : (159,156, 73), 
              'Non-motorized vehicle'    : ( 10,239,189), 
              'Non-motorized vehicle 2D' : (183, 68,121), 
              'Other Obstacles'          : (193, 52,240), 
              'Other Obstacles 2D'       : ( 53,223, 54), 
              'Parking line'             : (  4,178,106), 
              'Parking number'           : (104, 28,162), 
              'Pedestrian'               : (  8,197,115),
              'Pedestrian 2D'            : ( 61,205,183),
              'Pylon'                    : (  5,129,227), 
              'Solid line'               : (239, 18, 44), 
              'Speed bump'               : (107,251,229), 
              'Steel pipe'               : (101, 49,243), 
              'Steel pipe 2D'            : ( 26,130, 36), 
              'Traffic cone'             : ( 54,175,167), 
              'Traffic cone 2D'          : ( 39,219,102), 
              'Tyre'                     : (142, 16,198),
              'Wheel lock'               : (174,143,124), 
              'Wheel lock 2D'            : (229,208,251), 
              'background'               : (  0,  0,  0)
          }
      def parse_data_polygon(tagtype, datastr):
          # print('datastr: ', datastr)
          if isinstance(datastr, str):
              data = eval(datastr)
          assert isinstance(data, list)
          # print('data: ', data)
      
          pts = []
          # list - list - float
          # print('data len: ', len(data))
          # print('data[-1] len: ', len(data[-1]))
          # print('data: ', data)
          # print('data type: ', type(data))
          if len(data)==4 and isinstance(data[0], float):
              print("BBOX2D ANNOtation ERRORRRRRR, error tagtype is: ", tagtype)
          else:
              for onedata in data:
                  if len(onedata) == 1:
                      break
                  pts.append(list(map(int, onedata[1:]))) # [x,y]
          return pts
      
      def parse_data_bbox2d(datastr):
          # print('datastr: ', datastr)
          if isinstance(datastr, str):
              data = eval(datastr)
          assert isinstance(data, list)
          # print('data: ', data)
          box = list(map(int, data)) # [x, y, w, h]
          return box
      
      def parse_json(path, dataset):
          i = 0
          for imgdata in dataset:
              # one image anno data.
              result = imgdata['result']
              i = i + 1
              # if not result or (i>1):
              if not result:
                  # break
                  continue
              file_obj = imgdata['file_obj']
              imgname = osp.split(file_obj)[-1]
              imgdata= cv.imread(osp.join(path, imagepath, imgname))
              # print("file_obj: ", file_obj)
              print("imgname: ", imgname)
              sgname = imgname.replace('.png', '_sg.png')
              odname = imgname.replace('.png', '_od.png')
              sgfile = osp.join(path, 'sg', sgname)
              odfile = osp.join(path, 'od', odname)
              # sgimg = cv.imread(osp.join(path, imagepath, imgname))
              sgimg = np.zeros_like(imgdata)
              odimg = cv.imread(osp.join(path, imagepath, imgname))
              mask = np.zeros_like(imgdata)
              maskname = imgname.replace('.png', '_mask.png')
              maskfile = osp.join(path, 'mask', maskname)
              # print("result type: ", type(result))
              # print("result len: ", len(result))
              # print("result[0]: ", result[0])
      
              # draw Free space
              for res in result:
                  tagtype = res['tagtype']
                  # print("tagtype--------------------------------------------------------------: \n\n", tagtype)
                  if tagtype != 'Free space':
                      continue
                  # Free space
                  points= parse_data_polygon(tagtype, res['data'])
                  # plot polygon in seg image
                  points_np = np.array(points, np.int32)
                  if points:
                      cv.fillPoly(mask, [points_np], colors[tagtype])
      
              for res in result:
                  tagtype = res['tagtype']
                  if tagtype == 'Free space':
                      continue
                  if tagtype == 'Motor vehicle 3D': 
                      # print("tagtype--------------------------------------------------------------: ", tagtype)
                      points= parse_data_polygon(tagtype, res['data'])
                      # plot bbox3d in od image
                      points_np = np.array(points, np.int32)
                      if points:
                          cv.polylines(odimg, [points_np], True, colors[tagtype])
                  elif tagtype == 'Floating edge': 
                      # print("tagtype--------------------------------------------------------------: ", tagtype)
                      points= parse_data_polygon(tagtype, res['data'])
                      # plot floating edge in seg image
                      points_np = np.array(points, np.int32)
                      if points:
                          cv.polylines(mask, [points_np], False, colors[tagtype], 5)
                  elif tagtype in polygon: 
                      # print("tagtype--------------------------------------------------------------: ", tagtype)
                      points= parse_data_polygon(tagtype, res['data'])
                      # plot polygon in seg image
                      points_np = np.array(points, np.int32)
                      # print('points_np: ', points_np)
                      if points:
                          cv.fillPoly(mask, [points_np], colors[tagtype])
                  elif tagtype in bbox2d: 
                      x, y, w, h = parse_data_bbox2d(res['data']) # Rect(xywh)
                      # rect = cv.Rect(x, y, w, h)
                      # plot bbox2d in od image
                      cv.rectangle(odimg, (x,y), (x+w, y+h), colors[tagtype]) # (leftup, rightdown) 
                      # cv.rectangle(odimg, rect, color) #  
              cv.addWeighted(imgdata, 0.7, mask, 0.3, 0, sgimg)
              # save seg and od image.
              cv.imwrite(sgfile, sgimg)
              cv.imwrite(odfile, odimg)
              cv.imwrite(maskfile, mask)
      
      def json2annoimg(path):
          jsonfile=os.path.join(path, jsonfilename)
          dataset=json.load(open(jsonfile, 'r'))
          num=len(dataset)
          parse_json(path, dataset)
      
      if __name__ == "__main__":
          path = os.path.dirname(os.path.realpath(__file__))
          json2annoimg(path)
      View Code

       數據集特點:標注文件中含有語義分割、目標檢測的類別,語義分割一般使用polygon標注,目標檢測使用box標注,懸空邊使用brokenline標注,解析標注文件的目的是將標注的信息繪制到圖像。

      參考

      1. RGB顏色查詢 第3頁 - 在線工具 - 字客網

      posted on 2024-06-17 18:33  鵝要長大  閱讀(37)  評論(0)    收藏  舉報

      導航

      主站蜘蛛池模板: A级毛片100部免费看| 红安县| 四虎国产精品永久入口| 婷婷六月色| 偷拍精品一区二区三区| 自拍视频在线观看成人| 亚洲精品福利一区二区三区蜜桃| 女同性恋一区二区三区视频| 日韩人妻无码精品久久| 欧美激情一区二区三区成人 | 国产亚洲精品久久久久久无亚洲 | 国产精品爽黄69天堂a| 狠狠躁天天躁中文字幕无码| 麻豆久久天天躁夜夜狠狠躁| 中国农村真卖bbwbbw| 草草浮力影院| 国产免费午夜福利片在线| 麻花传媒在线观看免费| 野花韩国高清电影| 夜夜躁狠狠躁日日躁| 国产精品欧美一区二区三区不卡| 2019亚洲午夜无码天堂| 亚洲一线二线三线品牌精华液久久久| 精品国产高清中文字幕| 亚洲人成电影网站色| 亚洲制服无码一区二区三区| 日本区二区三区不卡视频| 真实国产老熟女无套中出| 亚洲熟妇精品一区二区| 熟女精品视频一区二区三区| 国产高颜值极品嫩模视频| 国内精品无码一区二区三区| 国产一区二区三区禁18| 国产性一交一乱一伦一色一情| 日本久久高清一区二区三区毛片| 亚洲综合伊人久久大杳蕉 | 苍井空毛片精品久久久| 久久久久无码精品亚洲日韩| 国产精品国产三级在线专区| 日韩人妻中文字幕精品| 久久国产精品无码网站|