Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing new bindings with libuvc #90

Open
yurikleb opened this issue Nov 24, 2022 · 7 comments
Open

Implementing new bindings with libuvc #90

yurikleb opened this issue Nov 24, 2022 · 7 comments

Comments

@yurikleb
Copy link

We are using PYUVC to control and capture images via USB microscopes.
We need to be able to retrieve the "Pixel-Dimension/Distance" property from the microscope to know the real-world scale (in millimetres) of the images we capture.

The microscope manufacturer was able to provide us with a patch for libuvc to implement a "uvc_get_pixel_distance" method. However, they cannot advise us on how to implement a binding to this property/control in pyuvc.

What would be the best way to add such binding?

@papr
Copy link
Contributor

papr commented Nov 25, 2022

Happy to hear back from you!

For now, I suggest doing the following:

  1. Fork the pyuvc repository
  2. Check out the ga-build branch
  3. Init and update the submodules
    git submodule init
    git submodule update
  4. Ensure the full build works as expected
  5. Rebase your libuvc fork to https://github.com/pupil-labs/libuvc/tree/ga-build (i.e. checkout this branch and re-apply the patch)
  6. In your pyuvc fork, point the libuvc submodule to the patched libuvc at https://github.com/yurikleb/libuvc
  7. Add the c-function definition to https://github.com/pupil-labs/pyuvc/blob/ga-build/pyuvc-source/cuvc.pxd
  8. Extend the uvc.Capture class with a python function that calls the c function uvc_get_pixel_distance (as defined in the previous step, example)

If that all works as expected, we can think about merging this functionality into the official pyuvc.

@yurikleb
Copy link
Author

Thank you! Will give it a try and report in the next couple of days.

@yurikleb
Copy link
Author

yurikleb commented Nov 29, 2022

Hey @papr can you clarify what you mean in step 3 - init and update the submodules?
Is it just the regular steps under "Install From Source" section in the readme?

Basically, I got stuck in step 3, when trying to build pyuvc:

sudo pip3 install ./pyuvc
Processing ./pyuvc
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Requirement already satisfied: numpy in /usr/local/lib/python3.8/dist-packages (from pupil-labs-uvc==1.0.0b7) (1.23.3)
Building wheels for collected packages: pupil-labs-uvc
  Building wheel for pupil-labs-uvc (PEP 517) ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /tmp/tmpk3rxiatq build_wheel /tmp/tmppknkx1rm
       cwd: /tmp/pip-req-build-2l4qforj
  Complete output (111 lines):
  
  
  --------------------------------------------------------------------------------
  -- Trying "Ninja" generator
  --------------------------------
  ---------------------------
  ----------------------
  -----------------
  ------------
  -------
  --
  Not searching for unused variables given on the command line.
  -- The C compiler identification is GNU 9.4.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- The CXX compiler identification is GNU 9.4.0
  -- Detecting CXX compiler ABI info
  -- Detecting CXX compiler ABI info - done
  -- Check for working CXX compiler: /usr/bin/c++ - skipped
  -- Detecting CXX compile features
  -- Detecting CXX compile features - done
  -- Configuring done
  -- Generating done
  -- Build files have been written to: /tmp/pip-req-build-2l4qforj/_cmake_test_compile/build
  --
  -------
  ------------
  -----------------
  ----------------------
  ---------------------------
  --------------------------------
  -- Trying "Ninja" generator - success
  --------------------------------------------------------------------------------
  
  Configuring Project
    Working directory:
      /tmp/pip-req-build-2l4qforj/_skbuild/linux-x86_64-3.8/cmake-build
    Command:
      cmake /tmp/pip-req-build-2l4qforj/pyuvc-source -G Ninja -DCMAKE_INSTALL_PREFIX:PATH=/tmp/pip-req-build-2l4qforj/_skbuild/linux-x86_64-3.8/cmake-install/pyuvc-source/uvc -DPYTHON_VERSION_STRING:STRING=3.8.10 -DSKBUILD:INTERNAL=TRUE -DCMAKE_MODULE_PATH:PATH=/tmp/pip-build-env-8tsvem47/overlay/lib/python3.8/site-packages/skbuild/resources/cmake -DPYTHON_EXECUTABLE:PATH=/usr/bin/python3 -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPYTHON_LIBRARY:PATH=/usr/lib/x86_64-linux-gnu/libpython3.8.so -DPython_EXECUTABLE:PATH=/usr/bin/python3 -DPython_ROOT_DIR:PATH=/usr -DPython_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPython_FIND_REGISTRY:STRING=NEVER -DPython_NumPy_INCLUDE_DIRS:PATH=/usr/local/lib/python3.8/dist-packages/numpy/core/include -DPython3_EXECUTABLE:PATH=/usr/bin/python3 -DPython3_ROOT_DIR:PATH=/usr -DPython3_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPython3_FIND_REGISTRY:STRING=NEVER -DPython3_NumPy_INCLUDE_DIRS:PATH=/usr/local/lib/python3.8/dist-packages/numpy/core/include -DCMAKE_MAKE_PROGRAM:FILEPATH=/tmp/pip-build-env-8tsvem47/overlay/lib/python3.8/site-packages/ninja/data/bin/ninja -DUVC_DEBUGGING=OFF -DFORCE_LOCAL_LIBUVC_BUILD=OFF -DCMAKE_BUILD_TYPE:STRING=Release
  
  -- The C compiler identification is GNU 9.4.0
  -- Detecting C compiler ABI info
  -- Detecting C compiler ABI info - done
  -- Check for working C compiler: /usr/bin/cc - skipped
  -- Detecting C compile features
  -- Detecting C compile features - done
  -- FORCE_LOCAL_LIBUVC_BUILD=OFF
  -- Looking for libuvc...
  -- Setting RPATH to
  -- Found PythonInterp: /usr/bin/python3 (found version "3.8.10")
  -- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so (found version "3.8.10")
  -- Found Cython: /tmp/pip-build-env-8tsvem47/overlay/bin/cython
  -- Found NumPy: /usr/local/lib/python3.8/dist-packages/numpy/core/include (found version "1.23.3")
  -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1")
  -- Checking for module 'libturbojpeg'
  --   Found libturbojpeg, version 2.0.3
  -- Checking for module 'libusb-1.0'
  --   Found libusb-1.0, version 1.0.23
  -- Performing Test Weak Link MODULE -> SHARED (gnu_ld_ignore) - Success
  _modinit_prefix:PyInit_
  -- Configuring done
  CMake Error at CMakeLists.txt:103 (target_link_libraries):
    Target "uvc_bindings" links to:
  
      PLLibUVC::uvc
  
    but the target was not found.  Possible reasons include:
  
      * There is a typo in the target name.
      * A find_package call is missing for an IMPORTED target.
      * An ALIAS target is missing.
  
  
  
  -- Generating done
  CMake Warning:
    Manually-specified variables were not used by the project:
  
      Python3_EXECUTABLE
      Python3_FIND_REGISTRY
      Python3_INCLUDE_DIR
      Python3_NumPy_INCLUDE_DIRS
      Python3_ROOT_DIR
      Python_FIND_REGISTRY
      Python_INCLUDE_DIR
      Python_NumPy_INCLUDE_DIRS
      Python_ROOT_DIR
      SKBUILD
      UVC_DEBUGGING
  
  
  CMake Generate step failed.  Build files cannot be regenerated correctly.
  /tmp/pip-build-env-8tsvem47/overlay/lib/python3.8/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
    warnings.warn(msg, warning_class)
  Traceback (most recent call last):
    File "/tmp/pip-build-env-8tsvem47/overlay/lib/python3.8/site-packages/skbuild/setuptools_wrap.py", line 632, in setup
      env = cmkr.configure(
    File "/tmp/pip-build-env-8tsvem47/overlay/lib/python3.8/site-packages/skbuild/cmaker.py", line 334, in configure
      raise SKBuildError(
  
  An error occurred while configuring with CMake.
    Command:
      cmake /tmp/pip-req-build-2l4qforj/pyuvc-source -G Ninja -DCMAKE_INSTALL_PREFIX:PATH=/tmp/pip-req-build-2l4qforj/_skbuild/linux-x86_64-3.8/cmake-install/pyuvc-source/uvc -DPYTHON_VERSION_STRING:STRING=3.8.10 -DSKBUILD:INTERNAL=TRUE -DCMAKE_MODULE_PATH:PATH=/tmp/pip-build-env-8tsvem47/overlay/lib/python3.8/site-packages/skbuild/resources/cmake -DPYTHON_EXECUTABLE:PATH=/usr/bin/python3 -DPYTHON_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPYTHON_LIBRARY:PATH=/usr/lib/x86_64-linux-gnu/libpython3.8.so -DPython_EXECUTABLE:PATH=/usr/bin/python3 -DPython_ROOT_DIR:PATH=/usr -DPython_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPython_FIND_REGISTRY:STRING=NEVER -DPython_NumPy_INCLUDE_DIRS:PATH=/usr/local/lib/python3.8/dist-packages/numpy/core/include -DPython3_EXECUTABLE:PATH=/usr/bin/python3 -DPython3_ROOT_DIR:PATH=/usr -DPython3_INCLUDE_DIR:PATH=/usr/include/python3.8 -DPython3_FIND_REGISTRY:STRING=NEVER -DPython3_NumPy_INCLUDE_DIRS:PATH=/usr/local/lib/python3.8/dist-packages/numpy/core/include -DCMAKE_MAKE_PROGRAM:FILEPATH=/tmp/pip-build-env-8tsvem47/overlay/lib/python3.8/site-packages/ninja/data/bin/ninja -DUVC_DEBUGGING=OFF -DFORCE_LOCAL_LIBUVC_BUILD=OFF -DCMAKE_BUILD_TYPE:STRING=Release
    Source directory:
      /tmp/pip-req-build-2l4qforj/pyuvc-source
    Working directory:
      /tmp/pip-req-build-2l4qforj/_skbuild/linux-x86_64-3.8/cmake-build
  Please see CMake's output for more information.
  ----------------------------------------
  ERROR: Failed building wheel for pupil-labs-uvc
Failed to build pupil-labs-uvc
ERROR: Could not build wheels for pupil-labs-uvc which use PEP 517 and cannot be installed directly

I'm on Ubuntu 20.04.4 LTS, and do have version 0.15.0 of PYUVC installed.
I also had to install libjpeg-turbo-2.1.4 as I mentioned here

@papr
Copy link
Contributor

papr commented Nov 29, 2022

As a first step, please uninstall version 0.15.0 of PYUVC.

Secondly, please set this env var before running the pip install command:

export FORCE_LOCAL_LIBUVC_BUILD=ON

I have also added it to the README instructions.

@yurikleb
Copy link
Author

I just tried, and I am still getting the same error.
I do have my forked version of LIBUVC (without the latest patch) installed.
Does it matter?

@papr
Copy link
Contributor

papr commented Nov 29, 2022

To apply your custom libuvc changes, see steps 5 and 6. With the setting above, it should be building the libuvc that is checkout in the libuvc-source submodule.

@yurikleb Please check your cmake version. The build requires 3.24 or higher.

@yurikleb
Copy link
Author

I managed to compile PYUVC!
Thanks again for the support @papr

Notes for step 3 (on Linux) following the instructions here:
After installing libusb and libturbo-jpeg, clone the repo and set the system var:

git clone https://github.com/pupil-labs/pyuvc --recursive
export FORCE_LOCAL_LIBUVC_BUILD=ON

init and update submodules:

cd ./pyuvc
git submodule init
git submodule update

build:

cd ..
pip install ./pyuvc

Spent long time trying to debug this compiler error:
ninja: error: manifest 'build.ninja' still dirty after 100 tries, perhaps system time is not set
Which ended up being a problem with Windows which is setup to dual-boot alongside linux on my machine and scrambled the system time after the latest update. Well done Microsoft >_<

More updates to follow....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants