Skip to content

Commit

Permalink
Done for linux, working on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaZhu committed Jun 21, 2024
1 parent 83b998d commit db68070
Show file tree
Hide file tree
Showing 10 changed files with 350 additions and 121 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@
[submodule "opensfm/src/third_party/ceres-solver"]
path = opensfm/src/third_party/ceres-solver
url = https://github.com/ceres-solver/ceres-solver.git
[submodule "opensfm/src/third_party/SuiteSparse"]
path = opensfm/src/third_party/SuiteSparse
url = https://github.com/DrTimothyAldenDavis/SuiteSparse.git
183 changes: 93 additions & 90 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM quay.io/pypa/manylinux2014_x86_64
# FROM ubuntu:20.04
#FROM quay.io/pypa/manylinux2014_x86_64
FROM ubuntu:20.04

ENV PLAT=manylinux_2_17_x86_64
ENV PLAT=manylinux_2_31_x86_64
ARG DEBIAN_FRONTEND=noninteractive
ARG TWINE_USERNAME
ARG TWINE_PASSWORD
Expand All @@ -27,87 +27,65 @@ ENV TWINE_PASSWORD=$TWINE_PASSWORD
# && apt-get clean \
# && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \

# Install apt-getable dependencies
#RUN yum install -y \
# build-essential \
# cmake \
# git \
# libeigen3-dev \
# libopencv-dev \
# libceres-dev \
# python3-dev \
# python3-numpy \
# opencv \
# python3-pip \
# python3-pyproj \
# python3-scipy \
# python3-yaml \
# curl \
# && yum clean all \

## Установим Miniconda
#RUN curl -sSL https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -o miniconda.sh && \
# bash miniconda.sh -b -p /opt/conda && \
# rm miniconda.sh
#
## Добавим conda в PATH
#ENV PATH=/opt/conda/bin:$PATH
#
## Установим Ceres Solver 2.1 или 2.2 через conda
#RUN conda install -c conda-forge ceres-solver=2.2 opencv
#ENV CMAKE_PREFIX_PATH="/opt/conda/pkgs/ceres-solver-2.2.0-hfae76b8_3/lib/cmake/Ceres/"
#RUN yum install -y opencv opencv-devel \
# blas-devel \
# lapack-devel \
# metis-devel \
# tbb-devel \
# wget \
# openblas-devel \
# atlas-devel \
# suitesparse-devel

#RUN /opt/python/cp39-cp39/bin/pip install --upgrade pip && \
# /opt/python/cp39-cp39/bin/pip install auditwheel
RUN apt-get update \
&& apt-get install -y \
python3-dev \
python3-numpy \
python3-opencv \
python3-pip \
libblas-dev \
liblapack-dev \
libmetis-dev \
libtbb-dev \
wget \
libopenblas-dev \
libatlas-base-dev \
git \
cmake \
build-essential \
# libsuitesparse-dev \
curl
#
##RUN yum install -y opencv opencv-devel \
## ceres-solver ceres-solver-devel \
## eigen3 \
## glog-devel \
## gflags-devel \
## suitesparse-devel \
## blas-devel \
## lapack-devel \
## openblas-devel
#RUN mkdir /source
#WORKDIR /source
#RUN git clone https://github.com/gflags/gflags.git
#WORKDIR /source/gflags/
#RUN git checkout tags/v2.2.2
#RUN mkdir /source/gflags/build/
#WORKDIR /source/gflags/build/
#RUN cmake -DCMAKE_CXX_FLAGS="-fPIC" ..
#RUN make -j8
#RUN make install
#
RUN yum install -y opencv opencv-devel \
blas-devel \
lapack-devel \
metis-devel \
tbb-devel \
wget \
openblas-devel \
atlas-devel

RUN mkdir /source
WORKDIR /source
RUN git clone https://github.com/gflags/gflags.git
WORKDIR /source/gflags/
RUN git checkout tags/v2.2.2
RUN mkdir /source/gflags/build/
WORKDIR /source/gflags/build/
RUN cmake -DCMAKE_CXX_FLAGS="-fPIC" ..
RUN make -j8
RUN make install

WORKDIR /source
RUN git clone https://github.com/google/glog.git
WORKDIR /source/glog
RUN git checkout tags/v0.6.0
RUN mkdir /source/glog/build/
WORKDIR /source/glog/build/
RUN cmake ..
RUN make -j8
RUN make install

WORKDIR /source
RUN git clone https://gitlab.com/libeigen/eigen.git
WORKDIR /source/eigen/
RUN git checkout tags/3.4.0
RUN mkdir build
WORKDIR /source/eigen/build/
RUN cmake ..
RUN make install
#WORKDIR /source
#RUN git clone https://github.com/google/glog.git
#WORKDIR /source/glog
#RUN git checkout tags/v0.6.0
#RUN mkdir /source/glog/build/
#WORKDIR /source/glog/build/
#RUN cmake ..
#RUN make -j8
#RUN make install
#
#WORKDIR /source
#RUN git clone https://gitlab.com/libeigen/eigen.git
#WORKDIR /source/eigen/
#RUN git checkout tags/3.4.0
#RUN mkdir build
#WORKDIR /source/eigen/build/
#RUN cmake ..
#RUN make install

#RUN yum install -y lzip
#WORKDIR /source
Expand Down Expand Up @@ -145,23 +123,48 @@ RUN make install
#RUN make -j4
#RUN make install

RUN yum install -y suitesparse-devel
#WORKDIR /source
#RUN git clone https://github.com/ceres-solver/ceres-solver.git
#WORKDIR /source/ceres-solver
#RUN git checkout tags/2.0.0
#RUN mkdir build
#WORKDIR /source/ceres-solver/build/
#RUN cmake ..
#RUN make -j8
#RUN make install

WORKDIR /source
RUN git clone https://github.com/ceres-solver/ceres-solver.git
WORKDIR /source/ceres-solver
RUN git checkout tags/2.0.0
RUN mkdir build
WORKDIR /source/ceres-solver/build/
RUN cmake ..
RUN make -j8
RUN git clone https://github.com/NixOS/patchelf.git
WORKDIR /source/patchelf/
RUN git checkout tags/0.16.0
RUN ./bootstrap.sh
RUN ./configure
RUN make
RUN make install


RUN apt-get install -y liblzma-dev libssl-dev libopencv-dev
RUN apt-get install -y libncurses-dev libffi-dev libreadline6-dev libbz2-dev libsqlite3-dev

WORKDIR $SFM_DIR
RUN curl https://pyenv.run | bash
RUN /root/.pyenv/bin/pyenv install 3.9.9
RUN /root/.pyenv/bin/pyenv global 3.9.9
ENV PATH=$PATH:/root/.pyenv/versions/3.9.9/bin/
RUN python -m pip install --upgrade pip

ENV WHEEL_DIR=/source/wheelhouse
ENV SFM_DIR=/source/OpenSfM
COPY . $SFM_DIR

WORKDIR $SFM_DIR
RUN rm -rf cmake_build
RUN sh /source/OpenSfM/build_wheel.sh
# RUN sh /source/OpenSfM/test_and_upload_wheel.sh
RUN /root/.pyenv/versions/3.9.9/bin/pip install -r requirements.txt
RUN /root/.pyenv/versions/3.9.9/bin/pip wheel $SFM_DIR --no-deps -w $WHEEL_DIR
RUN ls /source/wheelhouse/*.whl | xargs -n 1 -I {} auditwheel repair {} --plat $PLAT -w $WHEEL_DIR
RUN cd ${WHEEL_DIR} && rm -rf *-linux*whl
RUN /root/.pyenv/versions/3.9.9/bin/pip install opensfm --no-index -f $WHEEL_DIR
RUN python -c "import opensfm"
RUN ls /source/wheelhouse/*.whl | xargs -n 1 -I {} python -m twine upload --repository-url "http://pypi.artichoke-labs.ai" {}
##RUN sh /source/OpenSfM/build_wheel.sh
##RUN sh /source/OpenSfM/test_and_upload_wheel.sh
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ OpenSfM is a Structure from Motion library written in Python. The library serves

Checkout this [blog post with more demos](http://blog.mapillary.com/update/2014/12/15/sfm-preview.html)

## MacOS Install
`brew install opencv`

## Getting Started

Expand Down
10 changes: 6 additions & 4 deletions build_wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ set -e -u -x

function repair_wheel {
wheel="$1"
/opt/_internal/cpython-3.9.19/bin/auditwheel repair "$wheel" --plat "$PLAT" -w $WHEEL_DIR
if ! /opt/_internal/cpython-3.9.19/bin/auditwheel show "$wheel"; then
echo "Skipping non-platform wheel $wheel"
else
/opt/_internal/cpython-3.9.19/bin/auditwheel repair "$wheel" --plat "$PLAT" -w $WHEEL_DIR
fi
}

# Compile wheels
for PYBIN in /opt/python/*/bin; do
if [[ "${PYBIN}" != *cp311* ]] && [[ "${PYBIN}" != *cp312* ]] && [[ "${PYBIN}" != *cp313* ]] && [[ "${PYBIN}" != *cp36* ]] && [[ "${PYBIN}" != *cp37* ]] && [[ "${PYBIN}" != *py37* ]] && [[ "${PYBIN}" != *cp38* ]] && [[ "${PYBIN}" != *py38* ]] && [[ "${PYBIN}" != *py39* ]] && [[ "${PYBIN}" != *py310* ]]; then
if [[ "${PYBIN}" != *cp311* ]] && [[ "${PYBIN}" != *cp312* ]] && [[ "${PYBIN}" != *cp313* ]] && [[ "${PYBIN}" != *cp36* ]] && [[ "${PYBIN}" != *cp37* ]] && [[ "${PYBIN}" != *py37* ]] && [[ "${PYBIN}" != *cp38* ]] && [[ "${PYBIN}" != *py38* ]] && [[ "${PYBIN}" != *py39* ]] && [[ "${PYBIN}" != *cp310* ]] && [[ "${PYBIN}" != *py310* ]]; then
"${PYBIN}/pip" install --upgrade pip
"${PYBIN}/pip" install -r ${SFM_DIR}/requirements.txt
"${PYBIN}/pip" install auditwheel==2.0.0
"${PYBIN}/pip" install auditwheel==1.4.0
"${PYBIN}/pip" wheel $SFM_DIR --no-deps -w $WHEEL_DIR
fi
done
Expand Down
1 change: 1 addition & 0 deletions opensfm/src/third_party/SuiteSparse
Submodule SuiteSparse added at 138067
2 changes: 1 addition & 1 deletion opensfm/src/third_party/ceres-solver
2 changes: 1 addition & 1 deletion opensfm/src/third_party/gflags
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ opencv-python==4.5.1.48 ; sys_platform == "win32"
opencv-python ; sys_platform == "linux"
twine
sphinx
auditwheel==1.4.0
auditwheel==6.0.0
Loading

0 comments on commit db68070

Please sign in to comment.