프로젝트

일반

사용자정보

개정판 213c18d3

ID213c18d3132936a0f1e3b8dd9bf31322d81abac8
상위 65eb78a7
하위 38cb750c, d0782d96

함의성이(가) 일년 이상 전에 추가함

gcloud test

Change-Id: I4605d97d807e2662bcfa5f241876477671a61b2d

차이점 보기:

DTI_PID/DTI_PID/TextDetector.py
284 284
        import math
285 285
        from AppWebService import AppWebService
286 286

  
287
        res_list = []
288

  
287 289
        try:
288 290
            app_doc_data = AppDocData.instance()
289 291

  
......
337 339
                _textImg = imgGray[top:bottom, left:right]
338 340
                textImg = _textImg.copy()
339 341

  
342
                text._canvas = None
343

  
340 344
                if textImg.shape[0] != text.getH() or textImg.shape[1] != text.getW():
341 345
                    continue
342 346

  
......
350 354

  
351 355
                    cv2.rectangle(_canvas, (x_position - line_gap, y_position - line_gap), (x_position + text.getW() + 2 * line_gap, y_position + text.getH() + 2 * line_gap), 100, 5)
352 356

  
357
                    text._canvas = QRect(x_position, y_position, text.getW(), text.getH())
358

  
353 359
                    x_position = x_position + text.getW() + gap
354 360
                    if y_max < text.getH():
355 361
                        y_max = text.getH()
......
359 365

  
360 366
                    cv2.rectangle(_canvas, (x_position - line_gap, y_position - line_gap), (x_position + text.getH() + 2 * line_gap, y_position + text.getW() + 2 * line_gap), 100, 5)
361 367

  
368
                    text._canvas = QRect(x_position, y_position, text.getH(), text.getW())
369

  
362 370
                    x_position = x_position + text.getH() + gap
363 371
                    if y_max < text.getW():
364 372
                        y_max = text.getW()
365 373

  
374
            cv2.imwrite(os.path.join(app_doc_data.getCurrentProject().getTempPath(), "request_img_before.png"), _canvas)
366 375
            indices = np.where(_canvas == [0])
367 376
            minx, maxx = min(indices[1]), max(indices[1])
368 377
            miny, maxy = min(indices[0]), max(indices[0])
369

  
370 378
            _canvas = _canvas[0:maxy + gap, 0:]
371

  
372 379
            cv2.imwrite(os.path.join(app_doc_data.getCurrentProject().getTempPath(), "request_img.png"), _canvas)
373 380

  
374 381
            app_web_service = AppWebService()
375 382
            img_infos = app_web_service.request_ocr_gcloud(_canvas)
376
            print(img_infos)
383

  
384
            for text in areaInfos:
385
                if not text._canvas:
386
                    continue
387

  
388
                string = ''
389
                contains = [img_info for img_info in img_infos if text._canvas.contains(QPoint(round((img_info[3][0] + img_info[1][0]) / 2), round((img_info[3][1] + img_info[1][1]) / 2)))]
390
                for img_info in sorted(contains, key=lambda param: param[1][0]):
391
                    string = string + img_info[0]
392
            
393
                if string:
394
                    res_list.append(ti.TextInfo(string, text.getX(), text.getY(), text.getW(), text.getH(), text.getAngle()))
377 395

  
378 396
        except Exception as ex:
379 397
            message = 'error occurred({}) in {}:{}'.format(repr(ex), sys.exc_info()[-1].tb_frame.f_code.co_filename,
380 398
                                                           sys.exc_info()[-1].tb_lineno)
381 399
            if worker is not None:
382 400
                worker.displayLog.emit(MessageType.Error, message)
401
        
402
        return res_list
383 403

  
384 404
    def get_text_box_using_craft(self, imgGray, offset_x, offset_y, web=False):
385 405
        """ get text box by using craft """
......
806 826
                                if worker:
807 827
                                    worker.displayLog.emit(MessageType.Error, message)
808 828
                else:
809
                    self.get_text_using_gcloud(imgSrc, tInfoList, offset, searchedSymbolList, worker)
829
                    self.textInfoList = self.get_text_using_gcloud(imgSrc, tInfoList, offset, searchedSymbolList, worker)
810 830

  
811 831
            if onlyTextArea:
812 832
                return

내보내기 Unified diff

클립보드 이미지 추가 (최대 크기: 500 MB)