Skip to content

Commit

Permalink
Merge pull request #42 from akaszynski/master
Browse files Browse the repository at this point in the history
Build wheels
  • Loading branch information
danini authored Aug 30, 2023
2 parents 0506f8a + 4613e92 commit 9fa075d
Show file tree
Hide file tree
Showing 180 changed files with 1,143 additions and 29,235 deletions.
123 changes: 123 additions & 0 deletions .github/workflows/build-and-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Build and upload

on:
pull_request:
push:
tags:
- "*"
branches:
- "master"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]

steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Setup MSVC Developer Command Prompt
if: matrix.os == 'windows-latest'
uses: TheMrMilchmann/[email protected]
with:
arch: x64
toolset: 14.36.32532

- name: Cache OpenCV build
if: matrix.os == 'windows-latest'
id: cache-opencv
uses: actions/cache@v3
with:
path: D:/a/graph-cut-ransac/graph-cut-ransac/opencv
key: opencv3-4-5-${{ runner.os }}-${{ hashFiles('scripts/build-opencv.ps1') }}

- name: Build OpenCV on Windows
if: matrix.os == 'windows-latest' && steps.cache-opencv.outputs.cache-hit != 'true'
run: scripts/build-opencv.ps1
shell: pwsh

- name: Cache Eigen3 build
if: matrix.os == 'windows-latest'
id: cache-eigen3
uses: actions/cache@v3
with:
path: C:/eigen3
key: eigen3-${{ runner.os }}-${{ hashFiles('scripts/build-eigen3.ps1') }}

- name: Install Eigen3 on Windows
if: matrix.os == 'windows-latest' && steps.cache-eigen3.outputs.cache-hit != 'true'
run: scripts/build-eigen3.ps1
shell: pwsh

- name: Build wheels
uses: pypa/[email protected]
env:
CIBW_ENVIRONMENT_WINDOWS: 'OpenCV_DIR="D:/a/graph-cut-ransac/graph-cut-ransac/opencv/build" Eigen3_DIR="C:/eigen3"'
CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel} --add-path D:/a/graph-cut-ransac/graph-cut-ransac/opencv/build/bin"

- uses: actions/upload-artifact@v3
with:
name: pygcransac-wheels-${{ runner.os }}
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
submodules: 'recursive'

- name: Build
run: pipx run build --sdist

- name: Validate
run: |
pip install twine
twine check dist/*
- uses: actions/upload-artifact@v3
with:
name: pygcransac-sdist
path: dist/*.tar.gz

upload_pypi:
name: Release and upload to PyPI
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
# upload to PyPI on every tag
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
steps:

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'

# Download all artifacts
- uses: actions/download-artifact@v3

- name: Upload to Public PyPi
run: |
pip install twine
twine upload --skip-existing ./**/*.whl
twine upload --skip-existing ./**/*.tar.gz
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}

- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: |
./**/*.whl
45 changes: 45 additions & 0 deletions .github/workflows/build-docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish Docker image

on:
workflow_dispatch:
inputs:
docker_tag:
description: 'Docker tag'
required: true


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build_and_push:
name: Build and possibly Push Docker image to GitHub Packages
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Set Docker tag
run: |
echo "::set-output name=tag::${{ github.event.inputs.docker_tag }}"
id: docker_tag

- name: Log in to GitHub Container Registry
uses: docker/[email protected]
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v4
with:
context: ./docker
push: ${{ startsWith(github.ref, 'refs/tags/') }}
tags: ghcr.io/${{ github.repository }}/manylinux2014_x86_64_opencv3:${{ steps.docker_tag.outputs.tag }}
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -345,4 +345,13 @@ healthchecksdb
MigrationBackup/

# Specific to this report
results/*
results/*

# build and pip
_skbuild
build/SampleProject
dist
.mypy_cache
*.egg-info
*.so
wheelhouse/
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "lib/pybind11"]
path = lib/pybind11
url = https://github.com/pybind/pybind11.git
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(CREATE_SAMPLE_PROJECT)
add_definitions(-DCREATE_SAMPLE_PROJECT)
endif()

find_package(OpenCV)
if (OPENCV_FOUND)
Expand Down Expand Up @@ -59,7 +62,7 @@ add_subdirectory(lib/pybind11)

pybind11_add_module(pygcransac ${SOURCE_DIR}/src/bindings.cpp ${SOURCE_DIR}/src/gcransac_python.cpp ${HDRS_GCRANSAC} ${SRCS_GCRANSAC} )
target_link_libraries(pygcransac PRIVATE ${OpenCV_LIBS} Eigen3::Eigen)

install(TARGETS pygcransac DESTINATION .)

add_library(${PROJECT_NAME} STATIC ${HDRS_GCRANSAC} ${SRCS_GCRANSAC})

Expand Down Expand Up @@ -93,6 +96,3 @@ if (CREATE_SAMPLE_PROJECT)

add_dependencies(SampleProject ${PROJECT_NAME})
endif (CREATE_SAMPLE_PROJECT)



7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ The method is explained in the [Latest developments in RANSAC presentation](http

Experiments on homography, fundamental matrix, essential matrix, and 6D pose estimation are shown in the corresponding [presentation](https://www.youtube.com/watch?v=igRydL72160&feature=youtu.be) from the tutorial RANSAC in 2020.

# Install from PyPI with pip
There are pre-compiled wheels for Windows and Linux for Python 3.8 - 3.11 that you can install with:

```
pip install pygcransac
```

# Installation C++

To build and install C++ only `GraphCutRANSAC`, clone or download this repository and then build the project by CMAKE.
Expand Down
8 changes: 8 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Start with the base image
FROM quay.io/pypa/manylinux2014_x86_64:2023-07-14-55e4124

# Copy the shell script from your host to the container
COPY install-opencv-3.4.5-in-centos-7.sh /root/install-opencv-3.4.5-in-centos-7.sh

# Execute the script
RUN /root/install-opencv-3.4.5-in-centos-7.sh
34 changes: 34 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Manylinux Wheels for Graph-Cut-RANSAC with OpenCV and Eigen

This directory is used to create a docker image to support the building manylinux wheels for the project [Graph-Cut-RANSAC](https://github.com/danini/graph-cut-ransac), requiring OpenCV 3.4.5 and Eigen. The build is optimized for OpenCV with the absolute minimum number of modules. This optimization is important because `auditwheel` will attempt to include all modules when they're all built, which could significantly increase the build time and result in an unnecessarily large wheel file.

By minimizing the number of modules in OpenCV, we're able to reduce the build time and create a more efficient wheel file.

## Getting Started

To build this image, navigate to the `docker` directory and use the following command:

```bash
cd docker
docker build -t manylinux2014_x86_64_opencv3:latest .
```

## Details

This repository provides the Dockerfile needed to create a `manylinux2014` docker image that includes the following:

- OpenCV v3.4.5
- Eigen
- gflag

This image is tagged as `manylinux2014_x86_64_opencv3:latest`.


## License

This repository uses the MIT license. Please refer to the original projects for
licensing information:

- [Graph-Cut-RANSAC](https://github.com/danini/graph-cut-ransac)
- [OpenCV](https://github.com/opencv/opencv)
- [Eigen](https://github.com/libigl/eigen)
113 changes: 113 additions & 0 deletions docker/install-opencv-3.4.5-in-centos-7.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#!/bin/bash

# Build and install OpenCV from source on CentOS 7 for graph-cut-ransac and MAGSAC++

# install dependencies for opencv and magsac
yum update -y
yum install -y cmake3 eigen3-devel gflags-devel
yum clean all && rm -rf /var/cache/yum # clean cache

# Download opencv
git clone --depth 1 --branch 3.4.5 https://github.com/opencv/opencv.git
cd opencv
mkdir build && cd build

# Compile and install OpenCV with contrib modules
cmake3 -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_C_EXAMPLES=OFF \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D PYTHON3_EXECUTABLE=/usr/bin/python3.6 \
-D PYTHON_DEFAULT_EXECUTABLE=/usr/bin/python3.6 \
-D PYTHON3_VERSION_STRING="3.6.8" \
-D BUILD_opencv_cudacodec=OFF \
-D WITH_1394:BOOL=OFF \
-D WITH_ARAVIS:BOOL=OFF \
-D WITH_CLP:BOOL=OFF \
-D WITH_CUDA:BOOL=OFF \
-D WITH_EIGEN:BOOL=ON \
-D WITH_FFMPEG:BOOL=OFF \
-D WITH_GDAL:BOOL=OFF \
-D WITH_GDCM:BOOL=OFF \
-D WITH_GIGEAPI:BOOL=OFF \
-D WITH_GPHOTO2:BOOL=OFF \
-D WITH_GSTREAMER:BOOL=OFF \
-D WITH_GSTREAMER_0_10:BOOL=OFF \
-D WITH_GTK:BOOL=OFF \
-D WITH_GTK_2_X:BOOL=OFF \
-D WITH_HALIDE:BOOL=OFF \
-D WITH_IMGCODEC_HDR:BOOL=OFF \
-D WITH_IMGCODEC_PXM:BOOL=OFF \
-D WITH_IMGCODEC_SUNRASTER:BOOL=OFF \
-D WITH_INF_ENGINE:BOOL=OFF \
-D WITH_IPP:BOOL=OFF \
-D WITH_ITT:BOOL=OFF \
-D WITH_JASPER:BOOL=OFF \
-D WITH_JPEG:BOOL=OFF \
-D WITH_LAPACK:BOOL=ON \
-D WITH_LIBV4L:BOOL=OFF \
-D WITH_MFX:BOOL=OFF \
-D WITH_OPENCL:BOOL=OFF \
-D WITH_OPENCLAMDBLAS:BOOL=OFF \
-D WITH_OPENCLAMDFFT:BOOL=OFF \
-D WITH_OPENCL_SVM:BOOL=OFF \
-D WITH_OPENEXR:BOOL=OFF \
-D WITH_OPENGL:BOOL=OFF \
-D WITH_OPENMP:BOOL=OFF \
-D WITH_OPENNI:BOOL=OFF \
-D WITH_OPENNI2:BOOL=OFF \
-D WITH_OPENVX:BOOL=OFF \
-D WITH_PNG:BOOL=OFF \
-D WITH_PROTOBUF:BOOL=OFF \
-D WITH_PTHREADS_PF:BOOL=ON \
-D WITH_PVAPI:BOOL=OFF \
-D WITH_QT:BOOL=OFF \
-D WITH_QUIRC:BOOL=OFF \
-D WITH_TBB:BOOL=OFF \
-D WITH_TIFF:BOOL=OFF \
-D WITH_UNICAP:BOOL=OFF \
-D WITH_V4L:BOOL=OFF \
-D WITH_VA:BOOL=OFF \
-D WITH_VA_INTEL:BOOL=OFF \
-D WITH_VTK:BOOL=OFF \
-D WITH_WEBP:BOOL=OFF \
-D WITH_XIMEA:BOOL=OFF \
-D WITH_XINE:BOOL=OFF \
-D BUILD_EXAMPLES=OFF \
-D BUILD_TESTS:BOOL=OFF \
-D BUILD_TIFF:BOOL=OFF \
-D BUILD_USE_SYMLINKS:BOOL=OFF \
-D BUILD_WEBP:BOOL=OFF \
-D BUILD_WITH_DEBUG_INFO:BOOL=OFF \
-D BUILD_WITH_DYNAMIC_IPP:BOOL=OFF \
-D BUILD_ZLIB:BOOL=OFF \
-D BUILD_opencv_apps:BOOL=OFF \
-D BUILD_opencv_dnn:BOOL=OFF \
-D BUILD_opencv_highgui:BOOL=OFF \
-D BUILD_opencv_imgcodecs:BOOL=OFF \
-D BUILD_opencv_java_bindings_generator:BOOL=OFF \
-D BUILD_opencv_js:BOOL=OFF \
-D BUILD_opencv_ml:BOOL=OFF \
-D BUILD_opencv_objdetect:BOOL=OFF \
-D BUILD_opencv_photo:BOOL=OFF \
-D BUILD_opencv_python_bindings_generator:BOOL=OFF \
-D BUILD_opencv_shape:BOOL=OFF \
-D BUILD_opencv_stitching:BOOL=OFF \
-D BUILD_opencv_superres:BOOL=OFF \
-D BUILD_opencv_ts:BOOL=OFF \
-D BUILD_opencv_video:BOOL=OFF \
-D BUILD_opencv_videoio:BOOL=OFF \
-D BUILD_opencv_videostab:BOOL=OFF \
-D BUILD_opencv_world:BOOL=OFF \
-D BUILD_opencv_calib3d:BOOL=ON \
-D BUILD_opencv_features2d:BOOL=ON \
-D BUILD_opencv_imgproc:BOOL=ON \
-D BUILD_opencv_core:BOOL=ON \
-D BUILD_opencv_flann:BOOL=ON ..

# compile and install OpenCV
make -j && make install

# Remove OpenCV source
cd ../..
rm -rf opencv
1 change: 1 addition & 0 deletions lib/pybind11
Submodule pybind11 added at 8a099e
Loading

0 comments on commit 9fa075d

Please sign in to comment.