fehlfarbe / python-aruco

Python wrappers for ArUco library
Other
67 stars 16 forks source link

ArUco 3.1.12 #41

Closed a-altug closed 3 years ago

a-altug commented 3 years ago

Any update about ArUco 3.1.12?

fehlfarbe commented 3 years ago

I will take a look on it on Sunday :)

a-altug commented 3 years ago

Great. Thank you...

fehlfarbe commented 3 years ago

I created a new branch: https://github.com/fehlfarbe/python-aruco/tree/aruco-3.1.12 Can you try it?

a-altug commented 3 years ago

Yeap. It seems well.

But is pose estimation with Fractal Marker avaliable?

fehlfarbe commented 3 years ago

It is! I just updated the fractal example script and added an image and camera parameters of my Rollei Actioncam. Seems like the calibration tool doesn't like the wide angle lens so the pose/cube/axis looks weird but the code is working.

a-altug commented 3 years ago

Hey sorry but i think i did huge mistake :) previously i did pip install and now i get some errors with cmake and make

I overcomed about cmake error, OpenCV lib issiues by adding find_package( OpenCV 4.4.0 REQUIRED ) include_directories( ${OpenCV_INCLUDE_DIRS} ) to CMakeLists.txt which located in python-aruco-aruco-3.1.12

after cmake is done and when i did make

-- Found OpenCV: /usr/local (found suitable version "4.5.0", minimum required is "4.4.0") -- Found python module: setuptools (found version "39.0.1") -- Found python module: wheel (found version "0.36.1") -- Configuring done -- Generating done -- Build files have been written to: /home/altug/Downloads/python-aruco-aruco-3.1.12/build [ 33%] Built target pyaruco_swig_compilation Scanning dependencies of target pyaruco [ 66%] Building CXX object python/CMakeFiles/pyaruco.dir/aruco/arucoPYTHON_wrap.cxx.o In file included from /usr/include/python3.6m/numpy/ndarrayobject.h:18:0, from /usr/include/python3.6m/numpy/arrayobject.h:4, from /home/altug/Downloads/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:5483: /usr/include/python3.6m/numpy/ndarraytypes.h:774:0: warning: "NPY_ARRAY_C_CONTIGUOUS" redefined

define NPY_ARRAY_C_CONTIGUOUS 0x0001

/home/altug/Downloads/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:5474:0: note: this is the location of the previous definition

define NPY_ARRAY_C_CONTIGUOUS NPY_C_CONTIGUOUS

In file included from /usr/include/python3.6m/numpy/ndarraytypes.h:1809:0, from /usr/include/python3.6m/numpy/ndarrayobject.h:18, from /usr/include/python3.6m/numpy/arrayobject.h:4, from /home/altug/Downloads/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:5483: /usr/include/python3.6m/numpy/npy_1_7_deprecated_api.h:15:2: warning: #warning "Using deprecated NumPy API, disable it by " "#defining NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]

warning "Using deprecated NumPy API, disable it by " \

^~~ In file included from /usr/include/python3.6m/numpy/ndarrayobject.h:27:0, from /usr/include/python3.6m/numpy/arrayobject.h:4, from /home/altug/Downloads/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:5483: /usr/include/python3.6m/numpy/__multiarray_api.h:1392:0: warning: "PyArray_SetBaseObject" redefined

define PyArray_SetBaseObject \

/home/altug/Downloads/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:5475:0: note: this is the location of the previous definition

define PyArray_SetBaseObject(arr, x) (PyArray_BASE(arr) = (x))

[100%] Linking CXX shared library _pyaruco.so /usr/bin/ld: cannot find -laruco collect2: error: ld returned 1 exit status python/CMakeFiles/pyaruco.dir/build.make:102: recipe for target 'python/_pyaruco.so' failed make[2]: [python/_pyaruco.so] Error 1 CMakeFiles/Makefile2:142: recipe for target 'python/CMakeFiles/pyaruco.dir/all' failed make[1]: [python/CMakeFiles/pyaruco.dir/all] Error 2 Makefile:102: recipe for target 'all' failed make: *** [all] Error 2

Any idea?

fehlfarbe commented 3 years ago

It can't find aruco libs: /usr/bin/ld: cannot find -laruco Did you compile and install aruco? If yes, can you please add aruco to your CMakeLists.txt?

# aruco is required
find_package(aruco REQUIRED )
link_directories(${aruco_LIB_DIR} )

Complete CMakeLists.txt with OpenCV + aruco:

# ----------------------------------------------------------------------------
#   Basic Configuration
# ----------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.0)
project(aruco VERSION "3.1.12" LANGUAGES CXX)
set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 11) # C++11...
set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
set(CMAKE_CXX_EXTENSIONS ON) #...with compiler extensions like gnu++11

# OpenCV is required
find_package(OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )

# aruco is required
find_package(aruco REQUIRED )
link_directories(${aruco_LIB_DIR} )

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
include(python)
a-altug commented 3 years ago

I did and got and error again and edit your config like that:

  # ----------------------------------------------------------------------------
  #   Basic Configuration
  # ----------------------------------------------------------------------------
  cmake_minimum_required(VERSION 3.0)
  project(aruco VERSION "3.1.12" LANGUAGES CXX)
  set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
  set(CMAKE_INCLUDE_CURRENT_DIR ON)
  set(CMAKE_CXX_STANDARD 11) # C++11...
  set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
  set(CMAKE_CXX_EXTENSIONS ON) #...with compiler extensions like gnu++11
  set(aruco_DIR "ARUCO3.1.12_BUILD_DIRECTORY      " )

  # OpenCV is required
  find_package(OpenCV REQUIRED )
  include_directories( ${OpenCV_INCLUDE_DIRS} )

  # aruco is required
  find_package(aruco REQUIRED )
  link_directories(${aruco_DIR} )

  list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  include(python)

after did make again there was an error too

  /python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:5174:10: fatal error: numpy/arrayobject.h: No such file or directory
   5174 | #include <numpy/arrayobject.h>

And I found numpy's include folder as;

  python3
  import numpy
  numpy.get_include()

and it gave me A_PATH_NUMPY_INCLUDE

then I coppied it to usr/local/include

  sudo cp -r A_PATH_NUMPY_INCLUDE/numpy /usr/local/include

on ubuntu pc (20.04, OpenCV 4.4.0) it is installed. will try on Jetson Nano. will be informed...

a-altug commented 3 years ago

On jetson nano i did same installation as ubuntu pc. after created .whl package and installed via pip there is an import error occured.

  Traceback (most recent call last):
    File "/home/altug/.local/lib/python3.6/site-packages/aruco/pyaruco.py", line 14, in swig_import_helper
      return importlib.import_module(mname)
    File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
    File "<frozen importlib._bootstrap>", line 994, in _gcd_import
    File "<frozen importlib._bootstrap>", line 971, in _find_and_load
    File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
    File "<frozen importlib._bootstrap>", line 658, in _load_unlocked
    File "<frozen importlib._bootstrap>", line 571, in module_from_spec
    File "<frozen importlib._bootstrap_external>", line 922, in create_module
    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  ImportError: /home/altug/.local/lib/python3.6/site-packages/aruco/_pyaruco.so: undefined symbol: _ZN5aruco14MarkerDetector6detectERKN2cv3MatERSt6vectorINS_6MarkerESaIS6_EES2_S2_fb

  During handling of the above exception, another exception occurred:

  Traceback (most recent call last):
    File "fractal.py", line 5, in <module>
      import aruco
    File "/home/altug/.local/lib/python3.6/site-packages/aruco/__init__.py", line 1, in <module>
      from .pyaruco import *
    File "/home/altug/.local/lib/python3.6/site-packages/aruco/pyaruco.py", line 17, in <module>
      _pyaruco = swig_import_helper()
    File "/home/altug/.local/lib/python3.6/site-packages/aruco/pyaruco.py", line 16, in swig_import_helper
      return importlib.import_module('_pyaruco')
    File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
      return _bootstrap._gcd_import(name[level:], package, level)
  ModuleNotFoundError: No module named '_pyaruco'

it is in build direction but not added system's python dist_package

fehlfarbe commented 3 years ago

Hmm...can you remove find_package(aruco REQUIRED ) from CMakeLists.txt and try again?

Your error ImportError: /home/altug/.local/lib/python3.6/site-packages/aruco/_pyaruco.so: undefined symbol: _ZN5aruco14MarkerDetector6detectERKN2cv3MatERSt6vectorINS_6MarkerESaIS6_EES2_S2_fb

means that the method

void detect(const cv::Mat& input, std::vector<Marker>& detectedMarkers, cv::Mat camMatrix = cv::Mat(), cv::Mat distCoeff = cv::Mat(), float markerSizeMeters = -1, bool setYPerperdicular = false);

cannot be found in the lib. Indeed its only declared in the markerdetector.hheader but never defined/implemendet. I found several methods that are declared but not defined and I had to remove them from the original aruco headers. That's the reason why I added the (modified) headers to this repo instead including the original headers. The find_package(aruco REQUIRED ) macro somehow adds the include path to the original headers so it tries to find the not implemented methods in the lib and crashs because they don't exist.

a-altug commented 3 years ago

I guess I found a solution.

First i did (after I did "make" to Aruco C lib)

  sudo make install
  sudo ldconfig

so any -laruco or other errors are done.

then to build python-aruco I need to give OpenCVConfig.cmake directory by myself and others stay still as above

    # ----------------------------------------------------------------------------
    #   Basic Configuration
    # ----------------------------------------------------------------------------
    cmake_minimum_required(VERSION 3.0)
    project(aruco VERSION "3.1.12" LANGUAGES CXX)
    set(PROJECT_SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_CXX_STANDARD 11) # C++11...
    set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required...
    set(CMAKE_CXX_EXTENSIONS ON) #...with compiler extensions like gnu++11
    set(aruco_DIR ~/Downloads/aruco-3.1.12/build)
    set(OpenCV_INCLUDE_DIRS /usr/local/lib/cmake/opencv4)

    # OpenCV is required
    find_package(OpenCV REQUIRED )
    include_directories( ${OpenCV_INCLUDE_DIRS} )

    # aruco is required
    #find_package(aruco REQUIRED )
    link_directories(${aruco_DIR} )

    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
    include(python)

then all is done and example/fractal.py works..

but there is an error for example/example.py

/usr/local/lib/python3.6/dist-packages/cv2/python-3.6/cv2.cpython-36m-aarch64-linux-gnu.so
4.5.0
/home/altug/.local/lib/python3.6/site-packages/aruco/__init__.py
Marker: 4
    0 [ 1243.14343262   520.17724609]
    1 [ 1249.09960938   560.70373535]
    2 [ 1213.24890137   566.99719238]
    3 [ 1206.82019043   523.38995361]
center: [ 1228.078125    542.8170166]
M: [[  6.46964252e-01   6.85988247e-01  -3.32952499e-01  -9.99999000e+05]
 [ -3.32952499e-01   6.46964252e-01   6.85988247e-01  -9.99999000e+05]
 [  6.85988247e-01  -3.32952499e-01   6.46964252e-01  -9.99999000e+05]
 [  0.00000000e+00   0.00000000e+00   0.00000000e+00   1.00000000e+00]]
3D points: <Swig Object of type 'vector< cv::Point3f > *' at 0x7f5a566c30>
Traceback (most recent call last):
  File "example.py", line 45, in <module>
    for p in points3d:
TypeError: 'SwigPyObject' object is not iterable
swig/python detected a memory leak of type 'aruco::MarkerDetector::Params *', no destructor found.
swig/python detected a memory leak of type 'vector< cv::Point3f > *', no destructor found.
fehlfarbe commented 3 years ago

Thanks for the pointers. I will test the build process in a fresh docker container because my system has several opencv and aruco versions installed (thanks to ROS^^). The example.py should work with the latest commit. I just commented the erroneous line. I'm still working on the conversion between vector< cv::Point3f > * and Python list but I can't figure out why it doesn't work. This will take more time to go down the rabbit hole :)