From the internet I have learnt that Python does not have any standard modules to access the webcam. In order to capture a photo using the WebCam, we need to use an open source module called opencv (cv2 for python) which is written in C++. My question is why does python interpreter not throw an error when a piece of C++ code is used inside a Python code? How can it interpret something which is not python?
Asked
Active
Viewed 47 times
-2
-
11. The de facto reference implementation of Python is written in C and is *literally* called cpython. 2. How do you think Python talks to the *operating system* written in C/C++? 3. All of this is covered very well elsewhere, e.g. [here on this very site](https://stackoverflow.com/questions/9451929/base-language-of-python), or [here](https://realpython.com/python-bindings-overview/), or [the official docs](https://docs.python.org/3/library/ctypes.html), or... – Jared Smith May 24 '22 at 11:33
-
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 24 '22 at 12:27
1 Answers
-1
The python functions act as wrappers, meaning they just provide a python interface but behind the scenes they just execute the C++ code. So all you need is some code that lets you interpret the data that is sent from C++ and find the python equivalent like https://docs.python.org/3/library/ctypes.html and you're done. Though in case of OpenCV people have already done that for you so you can use the python stuff as if it were written in python.

haxor789
- 604
- 6
- 18