# Porting C++ to Python

**URL:** <https://forum.opencv.org/t/porting-c-to-python/7957>\
**Category:** C++\
**Created:** [March 15, 2022, 3:11pm UTC](https://forum.opencv.org/t/porting-c-to-python/7957 "2022-03-15T15:11:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![WhaSukGo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/whasukgo/32/4745_2.png) [@WhaSukGo](https://forum.opencv.org/u/WhaSukGo)\
**Post date:** [March 15, 2022, 3:11pm UTC](https://forum.opencv.org/t/porting-c-to-python/7957/1 "2022-03-15T15:11:39Z")

</div>

I’m trying to write a [Python](https://github.com/seungjun45/Water-Filling/blob/master/Shading_removal/water_filling.cpp) version of this [project](https://github.com/seungjun45/Water-Filling/blob/master/Shading_removal/water_filling.cpp) (written in C++).

I believe I used the same OpenCV functions and procedure, but I couldn’t get it write.

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [March 16, 2022, 12:19pm UTC](https://forum.opencv.org/t/porting-c-to-python/7957/2 "2022-03-16T12:19:29Z")

</div>

please understand, that noone here will just go and translate the whole thing for you.

so, please, start on your own, and come back with small, isolated problems, where your attempt failed.

---

<div class="post-metadata">

**Author:** ![kbarni](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/kbarni/32/26_2.png) [@kbarni](https://forum.opencv.org/u/kbarni)\
**Post date:** [March 16, 2022, 1:17pm UTC](https://forum.opencv.org/t/porting-c-to-python/7957/4 "2022-03-16T13:17:49Z")

</div>

The algorithm is quite simple, there shouldn’t be serious problems rewriting it in Python…

… **BUT** … using `for` loops in Python is VERY slow. So you must find a way to write this algorithm using matrix operations.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [March 16, 2022, 1:41pm UTC](https://forum.opencv.org/t/porting-c-to-python/7957/5 "2022-03-16T13:41:09Z")

</div>

> [@kbarni](#):
>
> … **BUT** … using `for` loops in Python is VERY slow. So you must find a way to write this algorithm using matrix operations.

or use `numba`, but that’s a task for _after_ the code works. get it working first.
