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

Fractal marker example #42

Open
milind1097 opened this issue Dec 24, 2020 · 14 comments
Open

Fractal marker example #42

milind1097 opened this issue Dec 24, 2020 · 14 comments

Comments

@milind1097
Copy link

Hello,

I was trying to understand and execute the fractal.py code. However, I got an error stating No module named 'aruco'. Also, I would like to ask that the function 'aruco.FractalDetector()' in fractal.py is included in aruco package? Can you please help me out with the steps that I need to take in order to install aruco?

Thank you in advance. :)

@milind1097
Copy link
Author

It displays the error "FileNotFoundError: [Errno 2] No such file or directory: './py3/aruco.py'" after running ./swigbuild.sh python3 command.

@fehlfarbe
Copy link
Owner

Hi @milind1097

you have two options:

  1. post the whole output of swigbuild.sh so I can try to find the error in the build process
  2. or use the latest branch aruco-3.1.12 with an extended fractal.py example and working fractal marker support. Please don't forget to pull the because I pushed an update some minutes ago and read the updated README.md for installation instructions because I changed the build process to CMake so swigbuild.sh isn't available anymore.

@milind1097

This comment has been minimized.

@milind1097
Copy link
Author

Hello @fehlfarbe ,

After installing aruco 3.1.12, I tried to create the python wrapper. I am getting a fatal error. The entire output is as follows.

milind@milind:/python-aruco-aruco-3.1.12$ mkdir build
milind@milind:
/python-aruco-aruco-3.1.12$ cd build
milind@milind:/python-aruco-aruco-3.1.12/build$ cmake ..
-- The CXX compiler identification is GNU 9.3.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr (found version "4.2.0")
Using aruco 3.1.12
/home/milind/python-aruco-aruco-3.1.12/include
-- Found PythonInterp: /usr/bin/python3.8 (found version "3.8.5")
-- Found NumPy: version "1.17.4" /usr/lib/python3/dist-packages/numpy/core/include
-- Found SWIG: /usr/bin/swig3.0 (found version "3.0.12")
Using SWIG 3.0.12
-- Found Python: /usr/bin/python3.8 (found version "3.8.5") found components: Interpreter Development
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so (found version "3.8.5")
-- Found python module: setuptools (found version "45.2.0")
-- Found python module: wheel (found version "0.34.2")
-- Configuring done
-- Generating done
-- Build files have been written to: /home/milind/python-aruco-aruco-3.1.12/build
milind@milind:
/python-aruco-aruco-3.1.12/build$ make
Scanning dependencies of target pyaruco_swig_compilation
[ 33%] Swig compile aruco.i for python
/home/milind/python-aruco-aruco-3.1.12/python/../include/cameraparameters.h:79: Warning 362: operator= ignored
/home/milind/python-aruco-aruco-3.1.12/python/../include/dictionary.h:80: Warning 314: 'is' is a python keyword, renaming to '_is'
/home/milind/python-aruco-aruco-3.1.12/python/../include/dictionary.h:117: Warning 389: operator[] ignored (consider using %extend)
/home/milind/python-aruco-aruco-3.1.12/python/../include/marker.h:147: Warning 362: operator= ignored
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector.h:215: Warning 325: Nested struct not currently supported (Params ignored)
/home/milind/python-aruco-aruco-3.1.12/python/../include/markermap.h:64: Warning 389: operator[] ignored (consider using %extend)
/home/milind/python-aruco-aruco-3.1.12/python/../include/markermap.h:65: Warning 389: operator[] ignored (consider using %extend)
/home/milind/python-aruco-aruco-3.1.12/python/../include/timers.h:171: Warning 314: 'print' is a python keyword, renaming to '_print'
/home/milind/python-aruco-aruco-3.1.12/python/../include/timers.h:171: Warning 314: 'print' is a python keyword, renaming to '_print'
/home/milind/python-aruco-aruco-3.1.12/python/../include/cameraparameters.h:138: Warning 503: Can't wrap 'operator <<' unless renamed to a valid identifier.
/home/milind/python-aruco-aruco-3.1.12/python/../include/cameraparameters.h:139: Warning 503: Can't wrap 'operator >>' unless renamed to a valid identifier.
/home/milind/python-aruco-aruco-3.1.12/python/../include/marker.h:154: Warning 503: Can't wrap 'operator <' unless renamed to a valid identifier.
/home/milind/python-aruco-aruco-3.1.12/python/../include/marker.h:170: Warning 503: Can't wrap 'operator <<' unless renamed to a valid identifier.
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector.h:321: Warning 509: Overloaded method aruco::MarkerDetector::getParameters() effectively ignored,
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector.h:318: Warning 509: as it is shadowed by aruco::MarkerDetector::getParameters() const.
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector_impl.h:163: Warning 509: Overloaded method aruco::MarkerDetector_Impl::getParameters() effectively ignored,
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector_impl.h:160: Warning 509: as it is shadowed by aruco::MarkerDetector_Impl::getParameters() const.
[ 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.8/numpy/ndarrayobject.h:12,
from /usr/include/python3.8/numpy/arrayobject.h:4,
from /home/milind/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:4188:
/usr/include/python3.8/numpy/ndarraytypes.h:788: warning: "NPY_ARRAY_C_CONTIGUOUS" redefined
788 | #define NPY_ARRAY_C_CONTIGUOUS 0x0001
|
/home/milind/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:4179: note: this is the location of the previous definition
4179 | #define NPY_ARRAY_C_CONTIGUOUS NPY_C_CONTIGUOUS
|
In file included from /usr/include/python3.8/numpy/ndarraytypes.h:1830,
from /usr/include/python3.8/numpy/ndarrayobject.h:12,
from /usr/include/python3.8/numpy/arrayobject.h:4,
from /home/milind/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:4188:
/usr/include/python3.8/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
17 | #warning "Using deprecated NumPy API, disable it with "
| ^~~~~~~
In file included from /usr/include/python3.8/numpy/ndarrayobject.h:21,
from /usr/include/python3.8/numpy/arrayobject.h:4,
from /home/milind/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:4188:
/usr/include/python3.8/numpy/__multiarray_api.h:1396: warning: "PyArray_SetBaseObject" redefined
1396 | #define PyArray_SetBaseObject
|
/home/milind/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:4180: note: this is the location of the previous definition
4180 | #define PyArray_SetBaseObject(arr, x) (PyArray_BASE(arr) = (x))
|
In file included from /home/milind/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:4192:
/home/milind/python-aruco-aruco-3.1.12/python/../include/aruco_cvversioning.h:3:10: fatal error: opencv2/core/core.hpp: No such file or directory
3 | #include <opencv2/core/core.hpp>
| ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

make[2]: *** [python/CMakeFiles/pyaruco.dir/build.make:63: python/CMakeFiles/pyaruco.dir/aruco/arucoPYTHON_wrap.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:151: python/CMakeFiles/pyaruco.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
milind@milind:~/python-aruco-aruco-3.1.12/build$

Can you please suggest me whats wrong?

Thanks. :)

@fehlfarbe
Copy link
Owner

Hi, can you please pull and build again?

@milind1097
Copy link
Author

milind1097 commented Dec 24, 2020

Hello @fehlfarbe ,

I tried building it again. The following is what I faced.

milind@Milind:~/python-aruco-aruco-3.1.12/build$ make
Scanning dependencies of target pyaruco_swig_compilation
[ 33%] Swig compile aruco.i for python
/home/milind/python-aruco-aruco-3.1.12/python/../include/cameraparameters.h:79: Warning 362: operator= ignored
/home/milind/python-aruco-aruco-3.1.12/python/../include/dictionary.h:80: Warning 314: 'is' is a python keyword, renaming to '_is'
/home/milind/python-aruco-aruco-3.1.12/python/../include/dictionary.h:117: Warning 389: operator[] ignored (consider using %extend)
/home/milind/python-aruco-aruco-3.1.12/python/../include/marker.h:147: Warning 362: operator= ignored
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector.h:215: Warning 325: Nested struct not currently supported (Params ignored)
/home/milind/python-aruco-aruco-3.1.12/python/../include/markermap.h:64: Warning 389: operator[] ignored (consider using %extend)
/home/milind/python-aruco-aruco-3.1.12/python/../include/markermap.h:65: Warning 389: operator[] ignored (consider using %extend)
/home/milind/python-aruco-aruco-3.1.12/python/../include/timers.h:171: Warning 314: 'print' is a python keyword, renaming to '_print'
/home/milind/python-aruco-aruco-3.1.12/python/../include/timers.h:171: Warning 314: 'print' is a python keyword, renaming to '_print'
/home/milind/python-aruco-aruco-3.1.12/python/../include/cameraparameters.h:138: Warning 503: Can't wrap 'operator <<' unless renamed to a valid identifier.
/home/milind/python-aruco-aruco-3.1.12/python/../include/cameraparameters.h:139: Warning 503: Can't wrap 'operator >>' unless renamed to a valid identifier.
/home/milind/python-aruco-aruco-3.1.12/python/../include/marker.h:154: Warning 503: Can't wrap 'operator <' unless renamed to a valid identifier.
/home/milind/python-aruco-aruco-3.1.12/python/../include/marker.h:170: Warning 503: Can't wrap 'operator <<' unless renamed to a valid identifier.
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector.h:321: Warning 509: Overloaded method aruco::MarkerDetector::getParameters() effectively ignored,
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector.h:318: Warning 509: as it is shadowed by aruco::MarkerDetector::getParameters() const.
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector_impl.h:163: Warning 509: Overloaded method aruco::MarkerDetector_Impl::getParameters() effectively ignored,
/home/milind/python-aruco-aruco-3.1.12/python/../include/markerdetector_impl.h:160: Warning 509: as it is shadowed by aruco::MarkerDetector_Impl::getParameters() const.
[ 33%] Built target pyaruco_swig_compilation
Scanning dependencies of target pyaruco
[ 66%] Building CXX object python/CMakeFiles/pyaruco.dir/aruco/arucoPYTHON_wrap.cxx.o
/home/milind/python-aruco-aruco-3.1.12/build/python/aruco/arucoPYTHON_wrap.cxx:4188:10: fatal error: numpy/arrayobject.h: No such file or directory
4188 | #include <numpy/arrayobject.h>
| ^~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[2]: *** [python/CMakeFiles/pyaruco.dir/build.make:63: python/CMakeFiles/pyaruco.dir/aruco/arucoPYTHON_wrap.cxx.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:151: python/CMakeFiles/pyaruco.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

@fehlfarbe
Copy link
Owner

fehlfarbe commented Dec 25, 2020

Hmm CMake should find and add numpy include directories or abort at the cmake .. step 🤔

Can you post the results of python3 -c "import numpy as n; print(n.__version__); print(n.get_include()); ?

If there is an error, install numpy via pip pip3 install --upgrade numpy and try again.

@milind1097
Copy link
Author

Hello,

This is what I got after running the above command.

milind@Milind:$ python3 -c "import numpy as n; print(n.version); print(n.get_include())";
1.19.4
/usr/local/lib/python3.8/dist-packages/numpy/core/include
milind@Milind:
$
$ pip3 install --upgrade numpy
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: numpy in /usr/local/lib/python3.8/dist-packages (1.19.4)
milind@Milind:$ python3 -c "import numpy as n; print(n.version); print(n.get_include())";
1.19.4
/usr/local/lib/python3.8/dist-packages/numpy/core/include
milind@Milind:
$

After upgrading also, I am getting the same version number of numpy.

@milind1097
Copy link
Author

Should I build it again? Have you made any changes after that in CMake file?

Thanks. :)

@fehlfarbe
Copy link
Owner

I found more errors in the CMake files (it was looking for Python2 numpy), so please pull and try again :)

@milind1097
Copy link
Author

Hello,

It worked. Thanks. :)

I have 2 questions if you could help me out with it.

  1. I tried running the code example.py file and fractal.py. However, I could see that in fractal.py output, only 3 outer corners of the marker is being marked/detected. The same goes for the inner marker. Can you please suggest me what can be done to detect all the markers? I believe it is something that has to be done with the aruco.FractalDetector command.

  2. I am working on aruco as well as fractal markers currently. For aruco, we were previously using opencv2 aruco library for getting the aruco markers from dictionary eg: DICT_5x5_100 etc. Is it possible to do the same with this aruco package? As I can see when I use 2 import commands, it does not take the opencv2 aruco module.

Following is what I was trying to do:

import cv2, PIL
from cv2 import aruco # For generating aruco markers
import aruco # For fractal markers
import matplotlib.pyplot as plt
import matplotlib as mpl

Output:

milind@Milind:/aruco_analyzer-master/aruco_analyzer$ /usr/bin/python3 /home/milind/aruco_analyzer-master/aruco_analyzer/test.py
Traceback (most recent call last):
File "/home/milind/aruco_analyzer-master/aruco_analyzer/test.py", line 8, in
detector = aruco.Dictionary_get(aruco.DICT_5X5_100)
AttributeError: module 'aruco' has no attribute 'Dictionary_get'
milind@Milind:
/aruco_analyzer-master/aruco_analyzer$

@fehlfarbe
Copy link
Owner

Great! 😄

  1. Actually I don't know. I never used the fractal marker before. I assume the detector has a problem with the wide angle lens of my camera? Maybe you can take a look at the examples of the aruco C++ lib.
  2. OpenCV aruco is a different implementation of aruco marker detection/generation. This aruco wrapper is based in the [original aruco library](https://www.uco.es/investiga/grupos/ava/node/26]. You shouldn't mix them like in you example. Maybe you can do
import cv2.aruco # access methods with cv2.aruco
import aruco # this aruco wrapper

# do opencv aruco stuff
dict = cv2.aruco.Dictionary_get(DICT_5x5_100)
# do aruco wrapper stuff
fractal_detector = aruco.FractalDetector()

But in general I would only use one of the libraries.

@milind1097
Copy link
Author

Okay thank you. :)

I will try this again but initially when I tried, it was only taking library from aruco and not from cv2.aruco.

Can you guide me if it is possible to obtain the distance between the marker and the camera using the translation and rotation vector?

Thank you once again. :D

@fehlfarbe
Copy link
Owner

If you want the distance between camera and center of the marker you just need the magnitude of tvec:

mag = math.sqrt(tvec[0]**2 + tvec[1]**2 + tvec[2]**2)

Assuming your intrinsics are well calibrated and converted to meters, the result is also in meters.

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