Skip to content

Commit

Permalink
Merge 5155526 into a82d73e
Browse files Browse the repository at this point in the history
  • Loading branch information
tatsy committed Jun 9, 2017
2 parents a82d73e + 5155526 commit d2a72f8
Show file tree
Hide file tree
Showing 14 changed files with 156 additions and 32 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.

# User defined files
version.h
VERSION

# image files
*.png
*.jpg
Expand Down
20 changes: 14 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@ install:
- docker pull tatsy/ubuntu-cxx:opencv

# Dynamically generate Dockerfile
- sed -i -e "s/@C_COMPILER@/$CC/;s/@CXX_COMPILER@/$CXX/;s/@BRANCH_NAME@/$TRAVIS_BRANCH/;s/@PULL_REQUEST@/$TRAVIS_PULL_REQUEST/" Dockerfile
- sed -i -e "s/@C_COMPILER@/$CC/" Dockerfile
- sed -i -e "s/@CXX_COMPILER@/$CXX/" Dockerfile
- sed -i -e "s/@BRANCH_NAME@/$TRAVIS_BRANCH/" Dockerfile
- sed -i -e "s/@PULL_REQUEST@/$TRAVIS_PULL_REQUEST/" Dockerfile
- sed -i -e "s/@PYTHON_VERSION@/$PYTHON_VERSION/" Dockerfile

# Build Dockerfile
- docker build --tag=lime-env .

# Run container
- docker run --name lime-env --env="CI=true" --env="TRAVIS_JOB_ID=$TRAVIS_JOB_ID" --env="CTEST_OUTPUT_ON_FAILURE=TRUE" -itd lime-env

# Check Python module installation
- docker exec lime-env python -c "import lime; lime.print_version()"

script:
# Run test on Docker container
- docker exec lime-env make check
Expand All @@ -42,9 +49,9 @@ before_deploy:
- pip install sphinx breathe sphinx_rtd_theme
- "cd docs; sh deploy_docs.sh; cd -"
- mkdir packages
- tar czvf packages/releases-$GIT_TAG.tar.gz $(ls -I packages)
- zip -q packages/releases-$GIT_TAG.zip -r $(ls -I packages)
- git tag $GIT_TAG -a -m "Commit from Travis CI for build $TRAVIS_BUILD_NUMBER"
- tar czvf packages/releases-v${LIME_VERSION}.tar.gz $(ls -I packages)
- zip -q packages/releases-v${LIME_VERSION}.zip -r $(ls -I packages)
- git tag v{$LIME_VERSION} -a -m "Commit from Travis CI for build $TRAVIS_BUILD_NUMBER"
- git push --tags --quiet https://$GH_TOKEN@github.com/tatsy/lime.git 2> /dev/null

deploy:
Expand All @@ -66,8 +73,9 @@ branches:
- development

env:
global:
- GIT_TAG=v0.2.0
matrix:
- PYTHON_VERSION=2.7
- PYTHON_VERSION=3.5

notifications:
email:
Expand Down
31 changes: 28 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
cmake_minimum_required(VERSION 3.0.0)
project(lime)

if (UNIX AND NOT APPLE)
set(LINUX TRUE)
else()
set(LINUX FALSE)
endif()

# ------------------------------------------------------------------------------
# Set version string
# ------------------------------------------------------------------------------
set(LIME_VERSION_STRING "0.3.0")
message(STATUS "LIME v${LIME_VERSION_STRING}")
file(WRITE "VERSION" "${LIME_VERSION_STRING}")

# ------------------------------------------------------------------------------
# Build options
# ------------------------------------------------------------------------------
Expand All @@ -14,15 +27,27 @@ option(LIME_BUILD_PYTHON_MODULE "Build python modules." OFF)
# ------------------------------------------------------------------------------
find_package( OpenCV 3.0 REQUIRED )
if (${LIME_BUILD_PYTHON_MODULE})
find_package( PythonLibs 3 REQUIRED )
find_package( Boost REQUIRED python numpy )
find_package( PythonLibs REQUIRED )
if (NOT DEFINED PYTHON_INCLUDE_DIR OR NOT DEFINED PYTHON_LIBRARY)
message(FATAL_ERROR "Python libraries not found. Please set PYTHON_INCLUDE_DIR and PYTHON_LIBRARY manually to CMake.")
endif()

message(STATUS "Python ${PYTHONLIBS_VERSION_STRING}")
message(STATUS " Include: ${PYTHON_INCLUDE_DIR}")
message(STATUS " Library: ${PYTHON_LIBRARY}")

if (LINUX AND ${PYTHONLIBS_VERSION_STRING} VERSION_GREATER "3.0")
find_package( Boost REQUIRED python3 numpy3 )
else()
find_package( Boost REQUIRED python numpy )
endif()
endif()

# Build settings
if (NOT WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O2")
if (${LIME_BUILD_TESTS})
message(STATUS "[lime] Generating coverage data.")
message(STATUS "[ LIME ] Generating coverage data.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fprofile-arcs -ftest-coverage")
endif()
endif()
Expand Down
40 changes: 38 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ENV BRANCH_NAME @BRANCH_NAME@
ENV PULL_REQUEST @PULL_REQUEST@
ENV CC @C_COMPILER@
ENV CXX @CXX_COMPILER@
ENV PYTHON_VERSION @PYTHON_VERSION@

#
## update/upgrade
Expand All @@ -29,6 +30,27 @@ RUN pip install gcovr
#
RUN apt-get -qq install cppcheck cccc doxygen

#
## Install Python through Anaconda
#
RUN wget -q https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O miniconda.sh
RUN bash miniconda.sh -b -p $HOME/anaconda
ENV PATH "$HOME/anaconda/bin:$PATH"
RUN conda update --yes conda
RUN conda install --yes python=$PYTHON_VERSION setuptools numpy scipy pillow six libgcc

#
## Install Boost
#
RUN wget -q https://dl.bintray.com/boostorg/release/1.64.0/source/boost_1_64_0.tar.gz
RUN tar -zxf boost_1_64_0.tar.gz
RUN \
cd boost_1_64_0 && \
./bootstrap.sh && \
./b2 address-model=64 \
include=`python -c "from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_inc())"` \
-d0 --with-python -j2 install .

#
## Install Google test
#
Expand All @@ -42,7 +64,7 @@ RUN \
#
## Build lime
#
RUN git clone --depth 10 -b $BRANCH_NAME https://github.com/tatsy/lime.git
RUN git clone --depth 12 -b $BRANCH_NAME https://github.com/tatsy/lime.git #redo
RUN \
if [ $PULL_REQUEST != "false" ]; then \
cd lime && \
Expand All @@ -53,11 +75,25 @@ RUN \
RUN \
cd lime && \
git submodule update --init --recursive

RUN \
cd lime && \
cmake -D CMAKE_BUILD_TYPE=Release -D LIME_BUILD_TESTS=ON -D GTEST_ROOT=/usr/local . && \
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D LIME_BUILD_TESTS=ON \
-D GTEST_ROOT=/usr/local \
-D PYTHON_INCLUDE_DIR=`python -c "from __future__ import print_function; from distutils import sysconfig; print(sysconfig.get_python_inc())"` \
-D PYTHON_LIBRARY=`find $HOME/anaconda/lib -name python${PYTHON_VERSION}` \
-D LIME_BUILD_PYTHON_MODULE=ON . && \
cmake --build .

#
## Install pylime
#
RUN \
cd lime && \
python setup.py install

#
## # of threads used by OpenMP
#
Expand Down
16 changes: 12 additions & 4 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
import sys
sys.path.insert(0, os.path.abspath('../sources'))

def get_version():
root_folder = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir))
v = ''
with open(os.path.join(root_folder, 'VERSION'), 'r') as lines:
v = list(lines)[0]
return v

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
Expand Down Expand Up @@ -58,18 +65,19 @@
master_doc = 'index'

# General information about the project.
project = 'Lime'
copyright = 'MIT License 2016, Tatsuya Yatagawa (tatsy)'
project = 'LIME'
copyright = 'MIT License 2016-2017, Tatsuya Yatagawa (tatsy)'
author = 'tatsy'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.2.0'
version = get_version()
# The full version, including alpha/beta/rc tags.
release = '0.2.0'
release = get_version()
print(get_version())

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Welcome to Lime's documentation!
================================

Lime (Library for IMage Editing) is an image editing library extending OpenCV
Lime (Library for IMage Editing) is an image editing library extending OpenCV 3.x
which is developed for C/C++ and Python.

.. toctree::
Expand Down
14 changes: 11 additions & 3 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ your program source codes.
Python
--------

For Python users, you can build the library with CMake. After building it,
you can install it normally with ``setup.py``. Following is the simple
installation steps.
For Python users, you can build the library with CMake. While `lime` depends
on `OpenCV` and `boost python/numpy`, you need to install these libraries beforehands.
Please make sure, the versions of these libraries meet the following requirements.

* OpenCV 3.0 or higher
* Boost 1.63 or higher and build boost-python and boost-numpy

After install these libraries, you can build and install the python library with following shell script.

.. code-block:: shell
Expand All @@ -44,3 +49,6 @@ installation steps.
While building the source codes with CMake, you may ought to specify your
python include and library directories.

If the installation is failed, you should check whether `lime` binary file appears in 'build/lib' directory
(the name of the binary would be `lime.pyd` (Windows), 'liblime.dylib' (MacOS) or 'lime.so' (Linux)).
16 changes: 12 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import print_function

import os
import re
import sys
import site
import shutil
Expand All @@ -11,6 +12,12 @@

lime_shared_lib = ''

def get_version():
v = ''
with open('VERSION', 'r') as lines:
v = list(lines)[0]
return v

def prebuild():
global lime_shared_lib

Expand Down Expand Up @@ -59,16 +66,17 @@ def run(self):
setup(
cmdclass={ 'install' : install },
name='lime',
version='0.2.0',
version=get_version(),
author='tatsy',
author_email='tatsy.mail@gmail.com',
url='https://github.com/tatsy/lime.git',
description='Library for IMage Editing.',
license='MIT',
classifiers={
'Development Status :: 3 - Alpha',
'Programming Language :: Python 3',
'Programming Language :: C++'
'Development Status :: 4 - Beta',
'Programming Language :: C++',
'Programming Language :: Python 2',
'Programming Language :: Python 3'
},
data_files=[ (get_python_lib(), [ lime_shared_lib ]) ]
)
3 changes: 3 additions & 0 deletions sources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
configure_file("${CMAKE_CURRENT_LIST_DIR}/core/version.h.in"
"${CMAKE_CURRENT_LIST_DIR}/core/version.h" @ONLY)

if (${LIME_BUILD_STATIC_LIB})
message(STATUS "[ LIME ] Build static library.")

Expand Down
2 changes: 2 additions & 0 deletions sources/core/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <iostream>
#include <sstream>

#include "version.h"

// -----------------------------------------------------------------------------
// API export macro
// -----------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions sources/core/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#ifndef _LIME_CORE_HPP_
#define _LIME_CORE_HPP_

#include "common.h"
#include "point.h"
#include "array2d.h"
#include "random.h"
Expand Down
16 changes: 16 additions & 0 deletions sources/core/version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifdef _MSC_VER
#pragma once
#endif

#ifndef _LIME_VERSION_H_
#define _LIME_VERSION_H_

namespace lime {

static inline void print_version() {
printf("LIME v@LIME_VERSION_STRING@\n");
}

} // namespace lime

#endif // _LIME_VERSION_H_
19 changes: 12 additions & 7 deletions sources/python/lime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ inline npy::ndarray mat2np(const cv::Mat &mat) {
return arr;
}

inline void py_print_verson() {
lime::print_version();
}

// -----------------------------------------------------------------------------
// NPR module
// -----------------------------------------------------------------------------
Expand Down Expand Up @@ -190,17 +194,17 @@ py::list py_poissonDisk(const npy::ndarray &gray, const py::list &points,
double minRadius = 2.0, double maxRadius = 5.0) {
cv::Mat input;
np2mat(gray, input);

std::vector<cv::Point2f> samples;
int nPoints = py::len(points);
for (int i = 0; i < nPoints; i++) {
double a = py::extract<double>(points[i][0]);
double b = py::extract<double>(points[i][1]);
samples.push_back(cv::Point2f((float)a, (float)b));
}

lime::poissonDisk(input, &samples, (lime::PDSMethod)pdsMethod, minRadius, maxRadius);

py::list output;
for (int i = 0; i < samples.size(); i++) {
py::tuple t = py::make_tuple((double)samples[i].x, (double)samples[i].y);
Expand Down Expand Up @@ -236,6 +240,9 @@ BOOST_PYTHON_MODULE(lime) {
// Exception translator.
py::register_exception_translator<PyLimeException>(&translate);

// Version
py::def("print_version", py_print_verson);

// NPR methods.
py::def("randomNoise", py_randomNoise);
py::def("perlinNoise", py_perlinNoise);
Expand Down Expand Up @@ -282,10 +289,10 @@ BOOST_PYTHON_MODULE(lime) {

py::def("LIC", py_LIC, ol_py_LIC(
py::args("img", "tangent", "L", "ftype")));

py::scope().attr("PDS_RAND_QUEUE") = (int)lime::PDS_RAND_QUEUE;
py::scope().attr("PDS_FAST_PARALLEL") = (int)lime::PDS_FAST_PARALLEL;

py::def("poissonDisk", py_poissonDisk, ol_py_poissonDisk(
py::args("gray", "samples", "method", "min_radius", "max_radius")));

Expand All @@ -295,6 +302,4 @@ BOOST_PYTHON_MODULE(lime) {
py::scope().attr("CONSTANCY_FAUGERAS") = (int)lime::CONSTANCY_FAUGERAS;

py::def("colorConstancy", py_colorConstancy);


}
Loading

0 comments on commit d2a72f8

Please sign in to comment.