zoukankan      html  css  js  c++  java
  • 使用多线程开启OCR

    需求:经过opencv 或者其他算法对一张图片里面的文字内容进行切割,获取到切割内容的坐标信息,再使用ocr进行识别。一张一张识别太慢了,我们可以开启多线程识别。代码如下

     1     threads = []   
     2     for coord in coord_list:    # 获取到的坐标列表进行遍历,一个元素一个矩形
     3         recv_thread = threading.Thread(target=ocr_discern, args=(coord, im,))   # ocr_discern为进行ocr识别的方法,参数coord为坐标, im为整张图片的二维数组
     4         threads.append(recv_thread)    # 把创建的线程放到列表中
     5     for t in threads:    # 开启线程守护
     6         t.setDaemon(True)
     7         t.start()
     8     for t in threads:
     9         t.join()   # 让主线程等待所有子线程结束,再返回结果
    10     print(text_coord_list)    # text_coord_list为识别结果,在ocr_discern函数中,将识别结果及对应的坐标关系,放到text_coord_list中。
    11     print('elapsed time:', time.time() - time1)
  • 相关阅读:
    ORM框架
    优酷项目1
    新年第一天
    前端第十天
    前端第九天
    前端第八天
    前端第七天
    前端第六天
    前端第五天
    月亮与六便士
  • 原文地址:https://www.cnblogs.com/pyweb/p/11375800.html
Copyright © 2011-2022 走看看