Python versus C++

Asked

Viewed 82 times

-1

Hi, I’m a novice programmer. I wrote a program for processing images in Python that worked perfectly, although its execution is very slow, due to the large number of operations involved. I decided to transcribe the same program to C++ and successfully compile and run it. However, the execution in C++ did not obtain the same result, generating a slightly different figure than that obtained by Python. I have already checked thoroughly and apparently there are no errors in the transcription of Python for C++. I ask, is it possible, because of the differences in the structure of the two languages, that there are differences in the results obtained?

  • Your question no longer states that there may be differences in the results obtained?

  • 3

    If we can’t compare the algorithms used between A and B, it can’t help you.

  • 4

    Not only in language differences but mainly in developer limitation in both languages. Knowing that they are different languages, the solutions will be different. You simply cannot transcribe a code from language A to language B, ipsis Litteris, expecting the same result. Given my humble experience in Python, I would say that it is more likely that the delay is due to some implementation error than limitation of the language itself.

1 answer

1

According to the documentation of Opencv

How Opencv-Python bindings are generated?

In Opencv, all Algorithms are implemented in C++. But These Algorithms can be used from Different Languages like Python, Java etc. This is made possible by the bindings generators. These generators create a bridge between C++ and Python which Enables users to call C++ functions from Python. (https://docs.opencv.org/3.2.0/da/d49/tutorial_py_bindings_basics.html)

So as the documentation says, Opencv implementations in Python and C++ use the same core code, however there may be some data structure that undergoes some kind of different rounding between languages generating minimally distinct results, or some other kind of anomaly, but this would probably occur outside the context of Opencv.

To analyze the situation we would need implementations in both languages.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.