data.py 文件源码

python
阅读 33 收藏 0 点赞 0 评论 0

项目:DeepTextSpotter 作者: MichalBusta 项目源码 文件源码
def transform_boxes(self, im, scaled, word_gto):

      image_size = (scaled.shape[1], scaled.shape[0])

      o_size = (im.shape[1], im.shape[0])
      normo = math.sqrt(im.shape[1] * im.shape[1] + im.shape[0] * im.shape[0] )
      normo2 = math.sqrt(image_size[1] * image_size[1] + image_size[0] * image_size[0] )
      scalex = o_size[0] / float(image_size[0])
      scaley = o_size[1] / float(image_size[1])

      gto_out = []
      for gt_no in range(len(word_gto)):
          gt = word_gto[gt_no]
          gtbox  = ((gt[0] * o_size[0], gt[1] * o_size[1]), (gt[2] * normo, gt[3] * normo), gt[4] * 180 / 3.14)
          gtbox = cv2.boxPoints(gtbox)
          gtbox = np.array(gtbox, dtype="float")

          #draw_box_points(im,  np.array(gtbox, dtype="int"), color = (0, 255, 0))
          #cv2.imshow('orig', im)

          gtbox[:,0] /=  scalex
          gtbox[:,1] /=  scaley

          dh = gtbox[0, :] - gtbox[1, :]
          dw = gtbox[1, :] - gtbox[2, :]


          h = math.sqrt(dh[0] * dh[0] + dh[1] * dh[1]) / normo2
          w = math.sqrt(dw[0] * dw[0] + dw[1] * dw[1]) / normo2

          #if w * normo2 < 5 or h * normo2  < 5 or np.isinf(w) or np.isinf(h):
              #print("warn: removig too small gt {0}".format(gt))
          #    continue

          gt[2] = w
          gt[3] = h

          gt[4] = math.atan2((gtbox[2, 1] - gtbox[1, 1]), (gtbox[2, 0] - gtbox[1, 0]))

          gt[8] = gtbox
          if self.debug:
            print('gtbox : ' + str(gtbox))
          gto_out.append(gt)
          #draw_box_points(scaled,  np.array(gtbox, dtype="int"), color = (0, 255, 0))
          #cv2.imshow('scaled', scaled)
          #cv2.waitKey(0)

      return gto_out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号