You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add gaurds to redirect C++'s stdout/stderr streams to python's stdout/stderr streams (#68)
C++'s stdout/stderr and Python's stdout/stderr streams are two different
streams.. normally this is not a problem but colab ignores C++'s
streams. To make colab see C++'s streams they need to be redirected to
Python's streams
if the statement `py::call_guard<py::scoped_ostream_redirect,
py::scoped_estream_redirect>()` is added to a function's definition then
its stdout/stderr gets redirected. I do that for the decoding methods
for simplex and tesseract.
so statements like with `verbose=True` will have their stdout redirected
```py3
>> tesseract_dec.decode(...)
len(pq) = 0 num_pq_pushed = 1
num_detectors = 3 max_num_detectors = 65538 cost = 6.811496946171
activated_errors =
activated_detectors = 19, 20, 25,
activated_errors = 880,
activated_detectors =
Decoding complete. Cost: 6.811496946171 num_pq_pushed = 100
```
I also added a context manager that can be used to do this from inside
python
```py3
import tesseract_decoder
with tesseract_decoder.ostream_redirect(stdout=..., stderr=...):
# since the call happens inside the context manager its streams get captured
a_function_whose_stdout_isnot_redirected()
```
0 commit comments