This python_binding
project enables Softcam library to be used from Python scripts.
Your python code will look like this:
import softcam
cam = softcam.camera(320, 240, 60)
while True:
img = draw_something()
cam.send_frame(img)
- Build Softcam library according to README.md. You get
softcam.dll
in thedist
directory at the root of this repository. - Run
DownloadPybind11.bat
. This batch downloads Pybind11 archive and expands it to be used in the following build of binding. - In a Command Prompt session, activate your target Python environment.
- Run
LaunchVisualStudio.bat
in the environment. This batch prepares environment variables that point the directory of the Python environment and launch Visual Studio for the solution filepythin_binding.sln
with that environment variables. - On the Visual Studio, build solution with
Release
|x64
configuration. You will getsoftcam.pyd
in thex64/Release
directory.
Then you can run simple_usage.py
. Note that this script requires Numpy and OpenCV installed in your Python environment.
Bring softcam.pyd
and softcam.dll
together to anywhere you want to use Softcam in python scripts.
Note:
- The color component order should be BGR, not RGB.
- Different version of Python interpreter needs different build of
softcam.pyd
.- For example, if you have built
softcam.pyd
with Python 3.9, trying to use it on Python 3.8 will fail withImportError
.
- For example, if you have built
- You can not change the filename of
softcam.pyd
after build.- If you rename it to
foo.pyd
and runimport foo
orimport softcam
in your Python code, either will fail with theImportError
. - This is because the name of the module is embedded in the file in build time.
- If you rename it to