Closed Wotipati closed 6 years ago
From
Symbol not found: __ZN2cv7imwriteERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEERKNS_11_InputArrayERKNS0_6vectorIiNS4_IiEEEE
i guess that there is a problem with opencv linking. How did you install opencv?
Dear @paulinus. Thank you for your prompt reply.
Yes, I did install opencv using anaconda. Here is my environment.
I did run the scripts in this environment.
(py27) ➜ OpenSfM git:(master) conda list
# packages in environment at /Users/wotipati/anaconda3/envs/py27:
#
decorator 4.2.1 py27_0
intel-openmp 2018.0.0 h8158457_8
jpeg 9b he5867d9_2
libgfortran 3.0.1 h93005f0_2
libpng 1.6.30 1
mkl 2018.0.1 hfbd8650_4
networkx 2.1 py27_0
numpy 1.9.3 py27hb3dd696_3
opencv 2.4.12 np19py27_0 https://conda.binstar.org/jjhelmus
openssl 1.0.2l 0
pip 9.0.1 py27_1
pyproj 1.9.5.1 py27_0
python 2.7.13 0
readline 6.2 2
setuptools 27.2.0 py27_0
sqlite 3.13.0 0
tk 8.5.18 0
wheel 0.29.0 py27_0
zlib 1.2.8 3
Best regards
I've never tried the opencv version that comes with conda. Note that we use OpenCV from the C code also. I'm not sure how things get linked to the conda version. Can you check the directory that is being used to link opencv with the command
grep OpenCV cmake_build/CMakeCache.txt
?
These are results.
(py27) ➜ OpenSfM git:(master) grep OpenCV cmake_build/CMakeCache.txt
//Path where debug 3rdpaty OpenCV dependencies are located
OpenCV_3RDPARTY_LIB_DIR_DBG:PATH=
//Path where release 3rdpaty OpenCV dependencies are located
OpenCV_3RDPARTY_LIB_DIR_OPT:PATH=
OpenCV_CONFIG_PATH:FILEPATH=/Users/wotipati/anaconda3/envs/py27/share/OpenCV
//The directory containing a CMake configuration file for OpenCV.
OpenCV_DIR:PATH=/Users/wotipati/anaconda3/envs/py27/share/OpenCV
//Path where debug OpenCV libraries are located
OpenCV_LIB_DIR_DBG:PATH=
//Path where release OpenCV libraries are located
OpenCV_LIB_DIR_OPT:PATH=
//ADVANCED property for variable: OpenCV_3RDPARTY_LIB_DIR_DBG
OpenCV_3RDPARTY_LIB_DIR_DBG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OpenCV_3RDPARTY_LIB_DIR_OPT
OpenCV_3RDPARTY_LIB_DIR_OPT-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OpenCV_CONFIG_PATH
OpenCV_CONFIG_PATH-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OpenCV_LIB_DIR_DBG
OpenCV_LIB_DIR_DBG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OpenCV_LIB_DIR_OPT
OpenCV_LIB_DIR_OPT-ADVANCED:INTERNAL=1
I did uninstall OpenCV installed with conda and installed OpenCV using homebrew.
brew install opencv
But, when I run "bin/opensfm_run_all data/berlin", I got import error about opencv. Here is the log.
$ OpenSfM git:(master) bin/opensfm_run_all data/berlin
Traceback (most recent call last):
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/bin/opensfm", line 10, in <module>
from opensfm import commands
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/commands/__init__.py", line 2, in <module>
import extract_metadata
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/commands/extract_metadata.py", line 5, in <module>
from opensfm import dataset
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/dataset.py", line 9, in <module>
import cv2
ImportError: No module named cv2
$ OpenSfM git:(master) grep OpenCV cmake_build/CMakeCache.txt
//Path where debug 3rdpaty OpenCV dependencies are located
OpenCV_3RDPARTY_LIB_DIR_DBG:PATH=
//Path where release 3rdpaty OpenCV dependencies are located
OpenCV_3RDPARTY_LIB_DIR_OPT:PATH=
OpenCV_CONFIG_PATH:FILEPATH=/Users/wotipati/anaconda3/envs/py27/share/OpenCV
//The directory containing a CMake configuration file for OpenCV.
OpenCV_DIR:PATH=/usr/local/share/OpenCV
//Path where debug OpenCV libraries are located
OpenCV_LIB_DIR_DBG:PATH=
//Path where release OpenCV libraries are located
OpenCV_LIB_DIR_OPT:PATH=
//Details about finding OpenCV
FIND_PACKAGE_MESSAGE_DETAILS_OpenCV:INTERNAL=[/usr/local][v3.4.0()]
//ADVANCED property for variable: OpenCV_3RDPARTY_LIB_DIR_DBG
OpenCV_3RDPARTY_LIB_DIR_DBG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OpenCV_3RDPARTY_LIB_DIR_OPT
OpenCV_3RDPARTY_LIB_DIR_OPT-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OpenCV_CONFIG_PATH
OpenCV_CONFIG_PATH-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OpenCV_LIB_DIR_DBG
OpenCV_LIB_DIR_DBG-ADVANCED:INTERNAL=1
//ADVANCED property for variable: OpenCV_LIB_DIR_OPT
OpenCV_LIB_DIR_OPT-ADVANCED:INTERNAL=1
How do we use OpenCV from the C code ?
Ok, to use the version of OpenCV, you need to do two things.
First, make sure that python can find the packages installed by brew. You can do it by running
export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
After that, you should not get the ImportError: No module named cv2
.
Second, rebuild OpenSfM so that the build uses the new OpenCV version. Run
cd path_to_OpenSfM
rm -rf build cmake_build # make sure you are at the right path before running this.
python setup.py build
I'm sorry to bother you over and over.
Following your advice, I did
$ export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH
$ cd path_to_OpenSfM
$ rm -rf build cmake_build
$ python setup.py build
After that, I run
$ bin/opensfm_run_all data/berlin
But, I got import error about loky.
Here is the log.
$ OpenSfM git:(master) grep OpenCV cmake_build/CMakeCache.txt
//The directory containing a CMake configuration file for OpenCV.
OpenCV_DIR:PATH=/usr/local/share/OpenCV
//Details about finding OpenCV
FIND_PACKAGE_MESSAGE_DETAILS_OpenCV:INTERNAL=[/usr/local][v3.4.0()]
$ OpenSfM git:(master) bin/opensfm_run_all data/berlin
Traceback (most recent call last):
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/bin/opensfm", line 10, in <module>
from opensfm import commands
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/commands/__init__.py", line 2, in <module>
import extract_metadata
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/commands/extract_metadata.py", line 5, in <module>
from opensfm import dataset
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/dataset.py", line 11, in <module>
from opensfm import io
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/io.py", line 10, in <module>
from opensfm import features
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/features.py", line 9, in <module>
from opensfm import context
File "/Users/wotipati/Desktop/Morishima_Lab/OpenSfM/opensfm/context.py", line 8, in <module>
from loky import get_reusable_executor
ImportError: No module named loky
Then, I tried install loky
$ pip install loky
But I got Error.
$ OpenSfM git:(master) pip install loky
zsh: /Users/wotipati/anaconda3/envs/py27/bin/pip: bad interpreter: /anaconda/envs/py27/bin/python: no such file or directory
Failed to import the site module
Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
PYTHONPATH is currently: "/usr/local/lib/python2.7/site-packages:"
You should `unset PYTHONPATH` to fix this.
I can't find same probrem in your issue. Do you have any solutions?
Best regards,
I installed anaconda and Python 3 before.
So in my environment, default python interpreter is Python 3.
$ python
Python 3.6.3 |Anaconda, Inc.| (default, Oct 6 2017, 12:04:38)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
On the other hand, since OpenSfM require Python 2, I set up virtual environment with anaconda. In this environment, I can use Python2.
(py27) $ python
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:05:08)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>>
Is it likely to be the cause of the problem?
When you tried installing loky
, were you using python 2?
Dear @paulinus
When I tried installing loky
, I used Python 2.
I made a new virtual environment with anaconda and retried running OpenSfM. And then, it succeeded !!!
I'm sorry for confusing you. Thank you so much for your quick and polite response.
Here is my history. I couldn't understand the cause of that after all, but I hope it will help an anaconda user.
# After install OpenCV and Open GV ...
$ conda create -n py27 python=2.7 # creating a new environment with specific version of Python
$ source activate py27 # activate the new environment
$ export PYTHONPATH=/usr/local/lib/python2.7/site-packages:$PYTHONPATH # add python path to use OpenCV and OpenGV
# install some packages using pip
# These packages are installed to activated environment(this case: py27)
$ pip install loky
$ pip install networkx
$ pip install pyproj
$ pip install pyyaml
$ pip install exifread
$ pip install xmltodict
# Running
$ bin/opensfm_run_all data/berlin
happy that it worked!
I got errors at running "python setup.py build" and "bin/opensfm_run_all data/berlin" on MacOS.
I am on MacOS High Sierra 10.13.2, Python 2.7.13 and Opencv 2.4.12.
Here is the full log:
Do you have any solutions?