Skip to content

Commit

Permalink
Merge pull request #5 from nasa/staging/v4.2
Browse files Browse the repository at this point in the history
Release v4.2
  • Loading branch information
marclecerf authored Jul 21, 2023
2 parents 23d662c + 9f754af commit 77ab9ba
Show file tree
Hide file tree
Showing 70 changed files with 1,267,215 additions and 967 deletions.
27 changes: 25 additions & 2 deletions .github/workflows/build-wheels.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build
name: Build 🐍 📦 + Publish to PyPI

on:
push:
Expand Down Expand Up @@ -92,9 +92,11 @@ jobs:
-DUPSP_BUILD_TESTING=OFF -DUPSP_BUILD_APPLICATIONS=OFF -DUPSP_BUILD_PYBIND11=ON'
CIBW_BEFORE_ALL_LINUX: "yum install -y perl-IPC-Cmd zip ninja-build"
CIBW_BEFORE_BUILD_WINDOWS: "pip install cmake"
CIBW_BUILD: "cp39-win_amd64 cp39-macosx_x86_64 cp39-manylinux_x86_64"
CIBW_BUILD: "cp*-win_amd64 cp*-macosx_x86_64 cp*-manylinux_x86_64"
CIBW_SKIP: "*-win32 *-manylinux_i686"
CIBW_BUILD_VERBOSITY: 1
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: "pytest {project}/test/python"
with:
package-dir: .
output-dir: wheelhouse
Expand All @@ -118,3 +120,24 @@ jobs:
- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

pypi_publish:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
# Upload for any push of tag starting with 'v'
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@release/v1
# For testing
# with:
# repository_url: https://test.pypi.org/legacy/
45 changes: 17 additions & 28 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Run the uPSP project build system and unit tests.
# Artifacts are installed into the runner's system Python 3 environment.
# Run the uPSP C++ build system and unit tests.
#
# Notes:
#
Expand All @@ -26,10 +25,9 @@
# - On NAS HECC systems, we build the C/C++ code with dynamic linkage due
# to the available system dependencies. This is *not* a default
# target supported by vcpkg, but it has a lot of community interest and
# "unofficial" testing support. Ref: https://github.com/microsoft/vcpkg/issues/15006
# We patch up some of the RPATH quirks using 'patchelf'.
# "unofficial" testing support.
#
name: unit-tests
name: C/C++ unit tests
on:
push:
workflow_dispatch:
Expand All @@ -51,6 +49,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: lukka/get-cmake@latest
- name: Install dependencies (Linux)
run: |
Expand Down Expand Up @@ -82,33 +82,22 @@ jobs:
runVcpkgInstall: true
# Release 2023.04.15
vcpkgGitCommitId: '501db0f17ef6df184fcdbfbe0f87cde2313b6ab1'
- name: Patch vcpkg library headers with patchelf
run: |
cd vcpkg
${{ github.workspace }}/.github/workflows/vcpkg-fix-rpaths
cd ..
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Upgrade pip to v23+
run: |
pip install --upgrade pip
pip --version
python --version
- name: Run build+install with pip
- name: Run CMake build
run: |
SKBUILD_CONFIGURE_OPTIONS=\
" -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"\
" -DVCPKG_TARGET_TRIPLET=x64-linux-dynamic" pip install -v .
mkdir build
cd build
cmake \
-DCMAKE_TOOLCHAIN_FILE="${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" \
-DVCPKG_TARGET_TRIPLET="x64-linux-dynamic" \
-DUPSP_BUILD_TESTING=ON \
-DUPSP_BUILD_APPLICATIONS=ON \
-DUPSP_BUILD_PYBIND11=ON \
..
make -j
# - name: Setup upterm session
# uses: lhotari/action-upterm@v1
- name: Run C/C++ unit tests
# TODO this should be made cross-platform. Currently works only for ubuntu-latest
# TODO fix RUNPATH of built executables to avoid use of LD_LIBRARY_PATH
run: |
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${{ env.VCPKG_INSTALLED_DIR }}/${{ env.VCPKG_DEFAULT_TRIPLET }}/lib"
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
cd cpp/test
../../_skbuild/linux-x86_64-3.9/cmake-build/run_tests
../../build/cpp/test/run_tests
54 changes: 0 additions & 54 deletions .github/workflows/vcpkg-fix-rpaths

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/vcpkg-triplets/x64-linux-dynamic.cmake

This file was deleted.

5 changes: 1 addition & 4 deletions .github/workflows/vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@
"ilmbase",
"gtest",
"pybind11"
],
"vcpkg-configuration": {
"overlay-triplets": ["./vcpkg-triplets"]
}
]
}
6 changes: 3 additions & 3 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
include_directories(include)

option(UPSP_BUILD_APPLICATIONS "Build applications" ON)
option(UPSP_BUILD_PYBIND11 "Build Python bindings" ON)
option(UPSP_BUILD_TESTING "Build unit tests" ON)
option(UPSP_BUILD_APPLICATIONS "Build applications" OFF)
option(UPSP_BUILD_PYBIND11 "Build Python bindings" OFF)
option(UPSP_BUILD_TESTING "Build unit tests" OFF)

if (UPSP_BUILD_APPLICATIONS)
add_subdirectory(exec)
Expand Down
1 change: 0 additions & 1 deletion cpp/exec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ target_link_libraries(upsp-extract-frames opencv_videoio)
target_include_directories(upsp-extract-frames SYSTEM PRIVATE ${Boost_INCLUDE_DIR})

add_executable(add_field add_field.cpp)
target_link_libraries(add_field upsp_video)
target_link_libraries(add_field upsp_utils)
target_link_libraries(add_field hdf5::hdf5_cpp-shared hdf5::hdf5_hl_cpp-shared)

Expand Down
32 changes: 30 additions & 2 deletions cpp/exec/psp_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,21 @@ int phase1(Phase1Settings& sett, P1Elems& elems) {
// register the image to the first frame
if (ifile.registration == upsp::RegistrationType::Pixel) {
cv::Mat warp_matrix;
img = upsp::register_pixel(first_frames_32f[c], img, warp_matrix);
const int max_iters = 50;
const double epsilon = 0.001;
int interpolation_flags = 0;
switch(ifile.pixel_interpolation) {
case upsp::PixelInterpolationType::Linear:
interpolation_flags = cv::INTER_LINEAR;
break;
case upsp::PixelInterpolationType::Nearest:
interpolation_flags = cv::INTER_NEAREST;
break;
}
img = upsp::register_pixel(
first_frames_32f[c], img, warp_matrix,
max_iters, epsilon, interpolation_flags
);
}

// patch frame
Expand Down Expand Up @@ -1762,7 +1776,21 @@ int phase1(Phase1Settings& sett, P1Elems& elems) {
// register the image to the first frame
if ((f > 0) && (ifile.registration == upsp::RegistrationType::Pixel)) {
cv::Mat warp_matrix;
img = upsp::register_pixel(elems.first_frames[c], img, warp_matrix);
const int max_iters = 50;
const double epsilon = 0.001;
int interpolation_flags = 0;
switch(ifile.pixel_interpolation) {
case upsp::PixelInterpolationType::Linear:
interpolation_flags = cv::INTER_LINEAR;
break;
case upsp::PixelInterpolationType::Nearest:
interpolation_flags = cv::INTER_NEAREST;
break;
}
img = upsp::register_pixel(
elems.first_frames[c], img, warp_matrix,
max_iters, epsilon, interpolation_flags
);
}

// patch frame
Expand Down
5 changes: 4 additions & 1 deletion cpp/include/registration.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ struct RegisterImage : std::unary_function<cv::Mat, cv::Mat> {
* @param[in] max_iters maximum number of iterations for ECC algorithm
* @param[in] epsilon threshold of the increment in correlation coefficient between
* two iterations, criteria for ECC algorithm to stop
* @param[in] interpolation_flags pixel interpolation method for image warping
* two iterations, criteria for ECC algorithm to stop
* @return @a inp_img warped to align with @a ref_img
*
* @pre @a ref_img and @a inp_img are grayscale images
* @pre @a ref_img is CV_32F
*/
cv::Mat register_pixel(const cv::Mat& ref_img, const cv::Mat& inp_img,
cv::Mat& warp_matrix, int max_iters=50, double epsilon=0.001);
cv::Mat& warp_matrix, int max_iters=50, double epsilon=0.001,
int interpolation_flags=cv::INTER_LINEAR);

/** Remove match pairs where the distance between the points is significantly large
*
Expand Down
5 changes: 5 additions & 0 deletions cpp/include/upsp_inputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum class TargetPatchType { None, Polynomial };

/** Registration method */
enum class RegistrationType { None, Point, Pixel };
enum class PixelInterpolationType { Linear, Nearest };

/** Type of spatial filter */
enum class FilterType { None, Gaussian, Box };
Expand Down Expand Up @@ -78,6 +79,7 @@ class FileInputs {
GridType grid_type;
TargetPatchType target_patcher;
RegistrationType registration;
PixelInterpolationType pixel_interpolation;
FilterType filter;
OverlapType overlap;
unsigned int filter_size;
Expand Down Expand Up @@ -174,6 +176,9 @@ std::ostream& operator<<(std::ostream& os, const upsp::TargetPatchType& tpt);
/** Add registration type string to stream */
std::ostream& operator<<(std::ostream& os, const upsp::RegistrationType& rt);

/** Add pixel interpolation type string to stream */
std::ostream& operator<<(std::ostream& os, const upsp::PixelInterpolationType& pt);

/** Add filter type string to stream */
std::ostream& operator<<(std::ostream& os, const upsp::FilterType& ft);

Expand Down
1 change: 1 addition & 0 deletions cpp/lib/P3DModel.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#include "logging.h"
#include "plot3d.h"
#include "utils/pspError.h"

namespace upsp {

Expand Down
15 changes: 10 additions & 5 deletions cpp/lib/registration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ cv::Mat RegisterImage::operator()(cv::Mat inp) {

/*****************************************************************************/
cv::Mat register_pixel(const cv::Mat& ref_img, const cv::Mat& inp_img,
cv::Mat& warp_matrix, int max_iters/*=50*/, double epsilon/*=0.001*/) {
cv::Mat& warp_matrix, int max_iters/*=50*/, double epsilon/*=0.001*/,
int interpolation_flags/*=cv::INTER_LINEAR*/) {

// grayscale and ref CV_32F
assert(ref_img.channels() == 1);
Expand Down Expand Up @@ -65,11 +66,15 @@ cv::Mat register_pixel(const cv::Mat& ref_img, const cv::Mat& inp_img,
// get the warped image
cv::Mat warp_img;
if (warp_mode != cv::MOTION_HOMOGRAPHY) {
cv::warpAffine(inp_img, warp_img, warp_matrix, ref_img.size(), cv::INTER_LINEAR +
cv::WARP_INVERSE_MAP);
cv::warpAffine(
inp_img, warp_img, warp_matrix, ref_img.size(),
interpolation_flags | cv::WARP_INVERSE_MAP
);
} else {
cv::warpPerspective(inp_img, warp_img, warp_matrix, ref_img.size(), cv::INTER_LINEAR +
cv::WARP_INVERSE_MAP);
cv::warpPerspective(
inp_img, warp_img, warp_matrix, ref_img.size(),
interpolation_flags | cv::WARP_INVERSE_MAP
);
}

return warp_img;
Expand Down
Loading

0 comments on commit 77ab9ba

Please sign in to comment.