def ctpn(self, sess, net, img): im, im_scale = self.check_img(img) timer = Timer() timer.tic() scores, boxes = test_ctpn(sess, net, im) timer.toc() print(('Detection took {:.3f}s for ' '{:d} object proposals').format(timer.total_time, boxes.shape[0])) # Visualize detections for each class CONF_THRESH = 0.9 NMS_THRESH = 0.3 dets = np.hstack((boxes, scores[:, np.newaxis])).astype(np.float32) keep = nms(dets, NMS_THRESH) dets = dets[keep] keep = np.where(dets[:, 4] >= 0.7)[0] dets = dets[keep, :] text_lines = self.connect_proposal(dets[:, :], dets[:, 4], im.shape[:2]) tmp = im.copy() text_recs = draw_boxes(tmp, text_lines, caption="im_name", wait=True) # self.show_results(tmp,im_scale, text_recs, thresh=0.9) return tmp, text_recs
def ctpn(sess, net, image_name): timer = Timer() timer.tic() img = cv2.imread(image_name) img, scale = resize_im(img, scale=TextLineCfg.SCALE, max_scale=TextLineCfg.MAX_SCALE) scores, boxes = test_ctpn(sess, net, img) text_filter = TextFilter() boxes = text_filter.detect(boxes, scores[:, np.newaxis], img.shape[:2]) draw_boxes(img, image_name, boxes, scale) timer.toc() print(('Detection took {:.3f}s for ' '{:d} object proposals').format(timer.total_time, boxes.shape[0]))
def ctpn(img): timer = Timer() timer.tic() img, scale = resize_im(img, scale=TextLineCfg.SCALE, max_scale=TextLineCfg.MAX_SCALE) scores, boxes = test_ctpn(sess, net, img) textdetector = TextDetector() boxes = textdetector.detect(boxes, scores[:, np.newaxis], img.shape[:2]) timer.toc() print("\n----------------------------------------------") print(('Detection took {:.3f}s for ' '{:d} object proposals').format(timer.total_time, boxes.shape[0])) return scores, boxes, img, scale