Skip to content

Commit

Permalink
fixed bugs in setup.py for Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
simbaforrest committed Sep 25, 2019
1 parent c2c4c49 commit a6ee74a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 26 deletions.
42 changes: 24 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,33 @@ Overview

This is the python3 wrapper for AprilTag implemented in cv2cg.

Currently it is tested under Windows10(VC2017, x64), OpenCV3.4.7(official prebuilt version), and python3.6 in Anaconda3.
Currently it is tested under Windows10(VC2017, x64)/Ubuntu 18.04, OpenCV3.4.7(official prebuilt version),
and python3.7/3.6 in Anaconda3.

Version
-------

0.0.4
0.0.5

Installation
------------

### Install from Pip

For Linux and Windows users, simply run the following command:
For Linux and Windows users, download the proper wheel file from https://github.com/ai4ce/pyAprilTag/releases,
then simply run the following command under the same folder of the wheel file to install:
```
pip install pyAprilTag
python -m pyAprilTag.demo
# expected output:
#[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39]
pip install pyAprilTag-0.0.4-cp37-cp37m-win_amd64.whl
```

### Install by Compiling from Source

For Mac users, you need to compile from source. **First install the C++ version of OpenCV 3.4.x.**
Then:
Following is for Mac users who need to compile from source, or other users who want to try installing from source.

0. clone repository recursively:
0. clone repository **recursively**, and install pre-built opencv 3.4.7 for python from conda-forge:
```
git clone --recursive https://github.com/ai4ce/pyAprilTag.git
conda install -c conda-forge opencv=3.4.7
```
1. prepare your build environment:
Expand All @@ -44,18 +42,26 @@ Then:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"
```
2. **Check the setup.py file, modify the OpenCV include and libs path according to your system.**
3. compile the project:
2. compile the project and you are done:
```
pip install -e .
```
Usage
-----
4. Enjoy!
```
python -m pyAprilTag.demo
```
```
python -m pyAprilTag.demo
# expected output:
#[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39]

python -m pyAprilTag.demo_plt
python -m pyAprilTag.demo_calib
python -m pyAprilTag.demo_calib_by_photo #remember to remove the calib_log folder in the current working directory
python -m pyAprilTag.vdemo_cv
python -m pyAprilTag.vdemo_plt
```
Contact
-------
Expand Down
1 change: 1 addition & 0 deletions python/pyAprilTag/vdemo_cv.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

# Read until video is completed
cnt = 0
cv2.namedWindow('Frame', cv2.WINDOW_NORMAL)
while cap.isOpened():
# Capture frame-by-frame
ret, frame = cap.read()
Expand Down
23 changes: 15 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ def get_conda_opencv_info(sys_name):
except ImportError as e:
print(str(e))
print('Please install opencv for python in your current Anaconda environment via the following:\n'
'conda install -c conda-forge opencv')
'conda install -c conda-forge opencv=3.4.7')
exit(-1)

assert(cv2.getVersionMajor() == 3) #currently we do not support opencv4

if sys_name == 'Linux':
opencv_lib_dir = os.path.abspath(os.path.join(os.path.dirname(cv2.__file__), *(['..'] * 2)))
available_opencv_libs = glob.glob(os.path.join(opencv_lib_dir, 'libopencv*.so'))
Expand All @@ -60,14 +62,18 @@ def get_conda_opencv_info(sys_name):
available_opencv_libs = [os.path.splitext(os.path.basename(it))[0].lstrip('lib')
for it in available_opencv_libs]

opencv_libs = [lib for lib in required_opencv_modules if lib in available_opencv_libs]
if sys_name == 'Windows':
opencv_libs = [lib for lib in available_opencv_libs
if any([lib.startswith(it) for it in required_opencv_modules])]
else:
opencv_libs = [lib for lib in required_opencv_modules if lib in available_opencv_libs]
return opencv_lib_dir, opencv_inc_dir, opencv_libs

sys_name = platform.system()
opencv_lib_dir, opencv_inc_dir, opencv_libs = get_conda_opencv_info(sys_name)
# print(opencv_lib_dir)
# print(opencv_inc_dir)
# print(opencv_libs)
print(opencv_lib_dir)
print(opencv_inc_dir)
print(opencv_libs)

extensions = [
Extension('pyAprilTag._apriltag',
Expand All @@ -82,7 +88,7 @@ def get_conda_opencv_info(sys_name):

setup(
name="pyAprilTag",
version="0.0.4",
version="0.0.5",
author="Chen Feng",
author_email="[email protected]",
description="python wrapper for AprilTag implemented in library cv2cg",
Expand All @@ -92,6 +98,7 @@ def get_conda_opencv_info(sys_name):
package_data={'pyAprilTag': ['data/*.png', 'data/**/*']},
include_package_data=True,
license="BSD",
cmdclass={'build_ext': BuildExt},
ext_modules=cythonize(extensions, compiler_directives={'language_level' : sys.version_info[0]})
cmdclass={'build_ext': build_ext if sys_name=='Windows' else BuildExt},
ext_modules=cythonize(extensions, compiler_directives={'language_level' : sys.version_info[0]}),
install_requires=['opencv>2,<4',]
)

0 comments on commit a6ee74a

Please sign in to comment.