MichalBusta / DeepTextSpotter

285 stars 101 forks source link

Input as image #15

Open qnkhuat opened 6 years ago

qnkhuat commented 6 years ago

As the title. Can I use image as the input? and how? Thanks 🥇

19931991 commented 6 years ago

Do you have solved the problem ? @qnkhuat

qnkhuat commented 6 years ago

I did not

19931991 commented 6 years ago

can we add q:1323369151@ qnkhuat

parquets commented 6 years ago

@19931991 can i add your q, I have the same problem, do you solve the problem?

xxlxx1 commented 6 years ago

modify a litte, i success

def test_pic(nets):

  global rec_t, image_size

  font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf", 16)
  font2 = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono-Bold.ttf", 18)

  impath = "images/demo.jpg"
  im = cv2.imread(impath)

  image_size = [640 / 64 * 64, 480 / 64 * 64]

  scaled = cv2.resize(im, (image_size[0], image_size[1]))  # 转为灰度图
  if nets[0].blobs['data'].data[...].shape[1] == 1:
    scaled = cv2.cvtColor(scaled, cv2.COLOR_BGR2GRAY )
    scaled = scaled.reshape((scaled.shape[0], scaled.shape[1], 1))

  detections_out, fps = froward_image(nets, scaled, im)

  img = Image.fromarray(im)
  draw = ImageDraw.Draw(img)

  for detection in detections_out:  
    text = detection[1][0]
    print(text)
    width, height = draw.textsize(text, font=font)
    center =  [detection[0][0][0] - width / 2, detection[0][0][1] - 10]

    sx = int(detection[0][0][0] - width / 2)
    ex = int(detection[0][0][0] + width / 2)
    sy = int(detection[0][0][1] - 10)
    ey = int(detection[0][0][1] + 10)

    im[sy:ey, sx:ex] = im[sy:ey, sx:ex] / 2 

    boxr  = ((detection[0][0][0], detection[0][0][1]), (detection[0][1][0], detection[0][1][1]), detection[0][2])
    box = cv2.boxPoints(boxr)  # 返回值为numpy数组,四个点坐标[[x,y],[x,y],[x,y],[x,y]]:(中心(x,y), (宽,高), 旋转角度)
    color = (0, 255, 0)
    vis.draw_box_points(im, box, color, thickness = 1)

  img = Image.fromarray(im)
  draw = ImageDraw.Draw(img)

  draw.text((10, 10), 'FPS: {0:.2f}'.format(fps),(0,255,0),font=font2)        

  #if frame_no < 30:
  #    draw.text((image_size[1] / 2 - 150, image_size[0] / 2 - 100), 'Raw Detections with Dictionary',(0,0,255),font=font3)

  for detection in detections_out:
    text = detection[1][0]
    width, height = draw.textsize(text, font=font)
    center =  [detection[0][0][0] - width / 2, detection[0][0][1] - 10]
    draw.text((center[0], center[1]), text, fill = (0,255,0),font=font)

  cv2.imwrite("images/demo_result_draw.jpg",scaled)  #灰度图

  pix = np.array(img)
  if pix.shape[0] > 1024:
    pix = cv2.resize(pix, (pix.shape[1] / 2, pix.shape[0] / 2))

  cv2.imwrite("images/demo_result_pix.jpg",pix)   #  有框,框里有结果