forked from pradana.aumars/videocr
use lazy map when performing parallel ocr
This commit is contained in:
parent
c63e508623
commit
da8cd05f08
@ -1,5 +1,5 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from concurrent import futures
|
from multiprocessing import Pool
|
||||||
import datetime
|
import datetime
|
||||||
import pytesseract
|
import pytesseract
|
||||||
import cv2
|
import cv2
|
||||||
@ -46,11 +46,11 @@ class Video:
|
|||||||
frames = (v.read()[1] for _ in range(num_ocr_frames))
|
frames = (v.read()[1] for _ in range(num_ocr_frames))
|
||||||
|
|
||||||
# perform ocr to frames in parallel
|
# perform ocr to frames in parallel
|
||||||
with futures.ProcessPoolExecutor() as pool:
|
with Pool() as pool:
|
||||||
ocr_map = pool.map(self._single_frame_ocr, frames, chunksize=10)
|
it_ocr = pool.imap(self._single_frame_ocr, frames, chunksize=10)
|
||||||
self.pred_frames = [
|
self.pred_frames = [
|
||||||
PredictedFrame(i + ocr_start, data, conf_threshold)
|
PredictedFrame(i + ocr_start, data, conf_threshold)
|
||||||
for i, data in enumerate(ocr_map)]
|
for i, data in enumerate(it_ocr)]
|
||||||
|
|
||||||
v.release()
|
v.release()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user