简体   繁体   中英

How to limit the number of threads in Python with Pytesseract

I am using Pytesseract to run Tesseract v5.0.1. I get worse character recognition when I run it on my Windows desktop PC than than when I run it on my Windows Surface Pro with the same image. On the Surface Pro the image I am processing takes 24 seconds to process while on my desktop PC it only takes 4 seconds. I am assuming that more threads are being used when it is being processed on my desktop PC. I would like to limit the number of threads on the desktop PC to see if this improves character recognition. I have tried the following code and it does not appear to change anything as it still processes in 4 seconds:

import os
os.environ["OMP_NUM_THREADS"]= '1'
os.environ["OMP_THREAD_LIMIT"] = '1'
os.environ["MKL_NUM_THREADS"] = '1'
os.environ["NUMEXPR_NUM_THREADS"] = '1'
os.environ["VECLIB_MAXIMUM_THREADS"] = '1'
os.environ["PAPERLESS_AVX2_AVAILABLE"]="false"
os.environ["OCR_THREADS"] = '1'

The desktop PC has a AMD FX-8320 Eight-Core Processor with 4 cores and 8 logical processors. The Surface Pro has a Intel Core m3-7Y30 CPU with 2 cores and 4 logical processors.

I add this in the beginning of my code and it works for me:

os.environ['OMP_THREAD_LIMIT'] = '1'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM