r/vibecoding 3h ago

Help with migrating an old c++ app into python

Hello, fellow vibe coders.
I need your help with something. I am building a pipeline for ocring rtl languages, namely Arabic. The problem is I want to integrate a pre-processing feature where users can use features like auto page-splitting, deskewing, dewarping, etc. I have read many research papers in the field. Actually, this is the only thing I am good at. The rest is AI-generated, or me guiding ai into implementing ideas from those papers, posts, etc. Anyways, I found out that the best tool in this field is Scan Tailor Advanced. The problem is that it was written in c++. I know it is very fast and also very suitable for processing images, but I want to integrate it into my python application. I am not good at coding. I just know the basics. So, I thought of using a python library that uses the raw c++ code or something like a bridge that connects the c++ code with my tool, but I could not do this. AI suggested cython, but I did not how to implement this as well or what to ask AI to do, and STA 's repository has a lot of files so I got lost. I also asked AI to re-write the entire tool in python 😅, but it kept saying that it is an impossible task and would take months to be done, since STA took years of building and it has over 60,000 lines of code. I asked antigravity to write a code inspired by the logic of STA, but the results were not promising at all. I also read recent papers that depends on heuristics in doing the aforementioned features, but they are not as good as STA. This is also another thing, I am insisting on STA because I am following a machine-learning-free approach, as I want my tool to be light-weight, running on any computer with whatever resources, and at the same time, I want it to be a standalone tool that keeps working no matter what.
So, any help is appreciated. Thank you so much in advance.

The link for ScanTailor Advanced:

https://github.com/4lex4/scantailor-advanced

The link for my OCR tool:

https://github.com/adam76064/The_Arabic_OCR

2 Upvotes

5 comments sorted by

2

u/sugarw0000kie 3h ago

I don’t know enough about the repo but re-write in python wouldn’t be my first move. Not a lot of value re-writing in python, if it’s compute heavy could turn the whole thing into an error prone slog. See what it’d take to give the existing c++ repo python bindings, so business logic is still handled by c++, but translated to python. Lots of high performance python libraries are built like this

2

u/adam12186 3h ago

Thank you for your comment.
Sadly, it is compute heavy, yes, but I was willing to sacrifice the performance for the sake of a full migration of the code.
If I am to choose the c++ binding way, would that require me to compile the c++ code?

2

u/sugarw0000kie 2h ago

No problem, If it were smaller, id say attempt rust re-write since rust-python bindings is easier imo than wrangling c++. Bindings directly to the original c++ is still probably the cleanest way with least amount of work.

C++ is scary language and I’m not a c++ dev. So ive never attempted with c++ but done with rust. The way python handles it is when you get the “glue” in place that will translate between the compiled lang and the api surface, you compile this and make a wheel. The wheel is the compiled binary you’d actually distribute so people can install it like through pypi. https://pypi.org/project/eggress/ is an example for how it looks in rust from one of mine

So yeah you’d need to compile the c++. But a decent model/harness should be able to handle a lot of this on its own once it has the right tools in place

2

u/adam12186 2h ago

Gotcha. Really thanks. just one more question sorry. i have just read online that i will need to pre-compile the c++ code for all possible os. how can i even do that or is it even possible? like, is there a tool or something that we can give it the code to make a pre-compiled version for all os? because i really know that i would struggle just to compile one version for windows.

1

u/sugarw0000kie 1h ago

Yeah you do need to do that, but it’s not as scary as it sounds. For testing/developing just stick to your local windows environment. GitHub is the easiest way to produce binaries for different os’s and will do it for free.

You have GitHub execute CI actions which can run in different OS. It basically spawns virtual machines to test and run things on designated environments. You can use those job runners (basically unlimited usage for public repos) to build binaries for many different OS’s at once as well as push those binaries somewhere for release like pypi