Skip to content

Commit

Permalink
Merge pull request #60 from sz3/ci-package
Browse files Browse the repository at this point in the history
Add scripts to build asm/wasm and portable linux + add github action to draft release on tag
  • Loading branch information
sz3 authored Feb 25, 2022
2 parents 729eb7e + 9d52131 commit 5fbface
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
os: ubuntu-18.04
env: CXX="g++-7" CC="gcc-7"

- name: "linux gcc9"
os: ubuntu-latest

- name: "linux clang"
os: ubuntu-18.04
env: CXX="clang++" CC="clang"
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: release

on:
push:
tags:
- '*'

jobs:
package-cimbar:
runs-on: ubuntu-latest
steps:
- name: Get the code
uses: actions/checkout@v2
with:
submodules: 'recursive'

- name: Get openCV
run: |
wget https://github.com/opencv/opencv/archive/refs/tags/4.5.5.zip
unzip 4.5.5.zip
mv opencv-4.5.5 opencv4
- name: Run the build process with Docker
uses: addnab/docker-run-action@v3
with:
image: emscripten/emsdk:latest
options: -v ${{ github.workspace }}:/usr/src/app
shell: bash
run: |
bash /usr/src/app/package-wasm.sh
- name: Show results
run: ls -l web/

- name: Create release
uses: softprops/action-gh-release@v1
with:
draft: true
files: |
web/cimbar.asmjs.zip
web/cimbar.wasm.tar.gz
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ else() # if not wasm, go find opencv. 3 or 4 should both work
include_directories(${OpenCV_INCLUDE_DIRS})
endif()

if(DEFINED BUILD_PORTABLE_LINUX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(OPENCV4 REQUIRED opencv4)
link_directories(${OPENCV4_STATIC_LIBRARY_DIRS})

# statically link c++/gcc (not libc!!)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -static-libstdc++ -static-libgcc")
endif()

if(NOT DEFINED OPENCV_LIBS)
set(OPENCV_LIBS "opencv_calib3d" "opencv_imgcodecs" "opencv_imgproc" "opencv_photo" "opencv_core")
set(OPENCV_LIBS "opencv_calib3d" "opencv_imgcodecs" "opencv_imgproc" "opencv_photo" "opencv_core" ${OPENCV4_STATIC_LIBRARIES})
endif()

if(NOT DEFINED CPPFILESYSTEM)
Expand Down
31 changes: 31 additions & 0 deletions package-portable-linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/sh
## targeting old glibc
# docker run --mount type=bind,source="$(pwd)",target="/usr/src/app" -it ubuntu:16.04

cd /usr/src/app

# https://gist.github.com/jlblancoc/99521194aba975286c80f93e47966dc5
apt update
apt install -y software-properties-common
add-apt-repository -y ppa:ubuntu-toolchain-r/test

apt update
apt install -y pkgconf g++-7 python-pip
apt install -y libgles2-mesa-dev libglfw3-dev

# cmake (via pip)
python -m pip install cmake

# use gcc7
update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-7 100
update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-7 100

cd opencv4/
mkdir build-portable/ && cd build-portable/
/usr/local/bin/cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DBUILD_SHARED_LIBS=OFF -DOPENCV_GENERATE_PKGCONFIG=YES -DOPENCV_FORCE_3RDPARTY_BUILD=YES
make -j5 install

cd /usr/src/app
mkdir build-portable/ && cd build-portable/
/usr/local/bin/cmake .. -DBUILD_PORTABLE_LINUX=1
make -j5 install
23 changes: 23 additions & 0 deletions package-wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
#docker run --mount type=bind,source="$(pwd)",target="/usr/src/app" -it emscripten/emsdk:latest

cd /usr/src/app

apt update
apt install python -y

cd opencv4/
mkdir opencv-build-wasm && cd opencv-build-wasm
python ../platforms/js/build_js.py build_wasm --build_wasm --emscripten_dir=/emsdk/upstream/emscripten

cd /usr/src/app
mkdir build-wasm && cd build-wasm
emcmake cmake .. -DUSE_WASM=1 -DOPENCV_DIR=/usr/src/app/opencv4
make -j5 install
(cd ../web/ && tar -czvf cimbar.wasm.tar.gz cimbar_js.* index.html main.js)

cd /usr/src/app
mkdir build-asmjs && cd build-asmjs
emcmake cmake .. -DUSE_WASM=2 -DOPENCV_DIR=/usr/src/app/opencv4
make -j5 install
(cd ../web/ && zip cimbar.asmjs.zip cimbar_js.js index.html main.js)
2 changes: 1 addition & 1 deletion src/lib/cimb_translator/test/CimbDecoderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ TEST_CASE( "CimbDecoderTest/testPrethresholdDecode", "[unit]" )
for (unsigned i = 0; i < 16; ++i)
{
cv::Mat tile = cimbar::getTile(4, i, true);
cv::Mat tenxten(10, 10, tile.type());
cv::Mat tenxten(10, 10, tile.type(), cv::Scalar(0, 0, 0));
tile.copyTo(tenxten(cv::Rect(cv::Point(1, 1), tile.size())));

// grayscale and threshold, since that's what average_hash needs
Expand Down
4 changes: 4 additions & 0 deletions src/lib/image_hash/average_hash.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace image_hash
uint64_t mval = (*hax) & 0x101010101ULL;
const uint8_t* cv = reinterpret_cast<const uint8_t*>(&mval);
uint8_t val = cv[0] << 4 | cv[1] << 3 | cv[2] << 2 | cv[3] << 1 | cv[4];
// TODO:
/*if (bigEndian)
val = cv[7] << 4 | cv[6] << 3 | cv[5] << 2 | cv[4] << 1 | cv[3];*/ // ?

res |= intx::uint128(val) << bitpos;
}
}
Expand Down

0 comments on commit 5fbface

Please sign in to comment.