isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.28k stars 2.28k forks source link

NameError: name 'read_image' is not defined #134

Closed HTLife closed 6 years ago

HTLife commented 6 years ago

I got an error NameError: name 'read_image' is not defined, when I tried to follow the instruction in Getting start page. How should I fix it??

$ python3 rgbd_redwood.py 
Read Redwood dataset
Traceback (most recent call last):
  File "rgbd_redwood.py", line 15, in <module>
    color_raw = read_image("../../TestData/RGBD/color/00000.jpg")
NameError: name 'read_image' is not defined
syncle commented 6 years ago

I think py3d may not be imported correctly. Can you try with #129?

HTLife commented 6 years ago

After following the instruction in #129 I still get the same error message. I am using pyenv to wrap all my python version to 3.5.2. Cmake detect 3.5.2 successfully.

$ cmake -DPYTHON_EXECUTABLE:FILEPATH=/home/rvl/.pyenv/shims/python ../src
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/lib/ccache/cc
-- Check for working C compiler: /usr/lib/ccache/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/lib/ccache/c++
-- Check for working CXX compiler: /usr/lib/ccache/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Compiling on Unix
-- Disable BUILD_LIBREALSENSE since it is not fully supported on Linux.
-- Open3D_USE_OPENMP=ON
-- Try OpenMP C flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Try OpenMP CXX flag = [-fopenmp]
-- Performing Test OpenMP_FLAG_DETECTED
-- Performing Test OpenMP_FLAG_DETECTED - Success
-- Found OpenMP: -fopenmp  
-- Open3D_BUILD_LIBREALSENSE=OFF
-- Open3D_BUILD_PYTHON_BINDING=ON
-- Open3D_BUILD_PYTHON_BINDING_TESTS=ON
-- Finding dependencies of Open3D
-- Dependencies are built from source if they are not found in the system
-- Found GLEW: /usr/include  
-- Use native build of GLEW
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'eigen3>=3.2.7'
--   Found eigen3, version 3.2.92
-- Use native eigen3
-- Checking for one of the modules 'libjpeg'
-- Use native build of libjpeg
-- Checking for one of the modules 'libpng>=1.6.0'
-- Build libpng from source
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of off64_t
-- Check size of off64_t - failed
-- Checking for one of the modules 'glfw3'
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so  
-- Use native build of glfw
-- Checking for one of the modules 'jsoncpp'
-- Use native build of jsoncpp
-- Build tinyfiledialogs from source
-- Found PythonInterp: /home/rvl/.pyenv/shims/python (found version "3.5.2") 
-- Found PythonLibs: /home/rvl/.pyenv/versions/3.5.2/lib/libpython3.5m.a
-- Performing Test HAS_CPP14_FLAG
-- Performing Test HAS_CPP14_FLAG - Success
-- pybind11 v2.2.1
-- Open3D_BUILD_TESTS=ON
-- Build experimental projects
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- LTO enabled
-- Configuring done
-- Generating done
-- Build files have been written to: /home/rvl/code/Open3D/build

I could import py3d with no error, but the read_image function could not be found.

$ python
Python 3.5.2 (default, Feb  8 2018, 15:16:25) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import py3d
>>> color_raw = read_image("../../TestData/RGBD/color/00000.jpg")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'read_image' is not defined
>>> color_raw = py3d.read_image("../../TestData/RGBD/color/00000.jpg")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'py3d' has no attribute 'read_image'
>>>
qianyizh commented 6 years ago

That's weird. We have not experienced this before. I suspect it is because py3d is not properly imported. I guess the first step of debugging is to identify if it is a problem of py3d importing, or a problem of this particular read_image function. Can you try this?

import py3d
help(py3d)

It should outputs a list of help information. If this passes. Can you try some other functions such as

pcd = py3d.PointCloud()
pcd1 = py3d.read_point_cloud('some_point_cloud.pcd')
syncle commented 6 years ago

Almost same time reply:

CMake message seems good. I have not seen this issue before. I think py3d does not linked with full attributes. Does pybind11 complain during compilation? Does help(py3d) displays any attribute? Can you delete build folder and rebuild again?

HTLife commented 6 years ago

@qianyizh help(py3d) could print document. However any function under py3d could not be called.

>>> pcd = py3d.PointCloud()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'py3d' has no attribute 'PointCloud'
HTLife commented 6 years ago

@qianyizh @syncle Rebuild and cd to /build/lib all function could be called successfully.

Run example under Basic folder will cause the same problem.

Open3D/build/lib/Tutorial/Basic$ python rgbd_redwood.py 
Read Redwood dataset
Traceback (most recent call last):
  File "rgbd_redwood.py", line 15, in <module>
    color_raw = read_image("../../TestData/RGBD/color/00000.jpg")
NameError: name 'read_image' is not defined
qianyizh commented 6 years ago

It looks like a pathing problem. Your python could not find the compiled py3d library. One workaround is to copy py3d.so to the python script directory and see if it works.

HTLife commented 6 years ago

@qianyizh It works! Thanks for quick support!!

~/code/Open3D/build/lib$ cp py3d.cpython-35m-x86_64-linux-gnu.so ./Tutorial/Basic/py3d.so
~/code/Open3D/build/lib/Tutorial/Basic$ python rgbd_redwood.py 
HTLife commented 6 years ago

For global solution, add this to .bashrc

export PYTHONPATH=$PYTHONPATH:/home/USERNAME/code/Open3D/build/lib

All example could be run successfully.

@qianyizh @syncle Thanks again for your help.