Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/openptv/openptv
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlib committed Mar 19, 2019
2 parents 75b0835 + 4115bc3 commit 7ab5fd8
Show file tree
Hide file tree
Showing 14 changed files with 248 additions and 79 deletions.
15 changes: 11 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
.pydevproject
.pydevproject.bak

py_bind/optv/*.c
.idea/
.vscode/
env/

*.pyc
py_bind/c_src
py_bind/optv/*.c
py_bind/dist
py_bind/build
py_bind/liboptv

liboptv/config.h.in~

liboptv/tests/check_fb.trs
liboptv/build
py_bind/build
*~

py_bind/optv/*.c
py_bind/build
*.pyc
21 changes: 10 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
language: c
compiler:
- clang
- gcc
language: python

before_install:
- sudo apt-get -qq update
- sudo apt-get install -y cmake
- sudo apt-get install -y check
- sudo apt-get install -y build-essential
- sudo apt-get install -y git
- sudo apt install python-pip
- pip install numpy
- pip install cython

install: true

script:
- cd liboptv
- mkdir _build && cd _build
- cmake ../
- make
- make verify
- cd py_bind
- python setup.py prepare
- python setup.py install
- cd test
- pip install nose
- nosetests
10 changes: 10 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# A Dockerfile for an Ubuntu machine that can compile liboptv and the Cython extensions

FROM ubuntu:18.04

RUN apt-get update
RUN apt-get --assume-yes install cmake
RUN apt-get --assume-yes install g++
RUN apt-get --assume-yes install python-pip
RUN pip install virtualenv
RUN virtualenv /env --python=`which python2`
10 changes: 10 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Set up the Ubuntu container so we can develop the Cython code on it
version: '3'
services:
optv-dev:
image: ptv-ubuntu:1
build: ./
volumes:
- ../:/src
command: tail -f /dev/null

5 changes: 5 additions & 0 deletions liboptv/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ tests/.libs/
tests/check_fb
tests/*.o

CMakeCache.txt
*.cmake
CMakeFiles/
install_manifest.txt
*.so
stamp-h1
4 changes: 2 additions & 2 deletions liboptv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cmake_minimum_required(VERSION 2.8)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
project(OpenPTV)
enable_testing()
# enable_testing()
add_subdirectory(src)
add_subdirectory(tests)
# add_subdirectory(tests)

INSTALL(DIRECTORY include/ DESTINATION include/optv/)

Expand Down
13 changes: 12 additions & 1 deletion liboptv/include/vec_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,18 @@ doubles.

#include <math.h>

#define EMPTY_CELL 0.0/0.0
#ifdef NAN
#define EMPTY_CELL NAN
#else
#if _MSC_VER <= 1500 // Visual C 2008 - for Python 2.7, or earlier
#define MSVC_NAN_REQUIRED
double return_nan(void);
#define EMPTY_CELL return_nan()
#else // More modern compilers or non Visual Studio
#define EMPTY_CELL 0.0/0.0
#endif
#endif

#define is_empty(x) isnan(x)
#define norm(x,y,z) sqrt((x)*(x) + (y)*(y) + (z)*(z))

Expand Down
9 changes: 6 additions & 3 deletions liboptv/src/orientation.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ double* orient (Calibration* cal_in, control_par *cpar, int nfix, vec3d fix[],
double *P, *y, *yh, *Xbeta, *resi;
vec3d glass_dir, tmp_vec, e1, e2;

double (*X)[NPAR];
double (*Xh)[NPAR];

Calibration *cal;

/* small perturbation for translation/rotation in meters and in radians */
Expand All @@ -278,8 +281,8 @@ double* orient (Calibration* cal_in, control_par *cpar, int nfix, vec3d fix[],
Xbeta = (double *) calloc(maxsize, sizeof(double));
resi = (double *) calloc(maxsize, sizeof(double));

double (*X)[NPAR] = malloc(sizeof (*X) * maxsize);
double (*Xh)[NPAR] = malloc(sizeof (*Xh) * maxsize);
X = malloc(sizeof (*X) * maxsize);
Xh = malloc(sizeof (*Xh) * maxsize);

for(i = 0; i < maxsize; i++) {
for(j = 0; j < NPAR; j++) {
Expand Down Expand Up @@ -759,13 +762,13 @@ int read_man_ori_fix(vec3d fix4[4], char* calblock_filename,
* Returns: pointer to a new orient_par structure.
*/
orient_par* read_orient_par(char *filename) {
orient_par *ret;
FILE * file = fopen(filename, "r");
if (file == NULL) {
printf("Could not open orientation parameters file %s.\n", filename);
return NULL;
}

orient_par *ret;
ret = malloc(sizeof(orient_par));

if ( !(fscanf(file, "%d", &ret->useflag)==1) /* use every point or every other pt */
Expand Down
3 changes: 2 additions & 1 deletion liboptv/src/parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,14 @@ int compare_mm_np(mm_np *mm_np1, mm_np *mm_np2)
* Returns: pointer to a new target_par structure.
*/
target_par* read_target_par(char *filename) {
target_par *ret;

FILE * file = fopen(filename, "r");
if (file == NULL) {
printf("Could not open target recognition parameters file %s.\n", filename);
return NULL;
}

target_par *ret;
ret = malloc(sizeof(target_par));

if ( !(fscanf(file, "%d", &ret->gvthres[0])==1) /* threshold for binarization 1.image */
Expand Down
3 changes: 3 additions & 0 deletions liboptv/src/track.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include <stdlib.h>
#include <stdio.h>

#define _USE_MATH_DEFINES
#include <math.h>

/* internal-use defines, not needed by the outside world. */
#define TR_UNUSED -1

Expand Down
11 changes: 11 additions & 0 deletions liboptv/src/vec_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ the logical structure, and allow optimizing for size as well.
#include "vec_utils.h"
#include <math.h>

#ifdef MSVC_NAN_REQUIRED

/* Returns a NAN, which is surprisingly non-trivial on Visual C for Python 2.7 */

static const unsigned long _explicit_dNAN[2] = {0x00000000, 0x7ff80000};
double return_nan(void) {
return *( double* )_explicit_dNAN;
}

#endif

/* vec_init() initializes all components of a 3D vector to NaN.
Arguments:
Expand Down
50 changes: 16 additions & 34 deletions py_bind/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,31 @@ The plan is to add more wrappers as other contributors of liboptv find them
necessary and choose to add them here.


Installation on Linux / OS X
----------------------------
This package assumes that liboptv is already installed. If it is not, see the
instructions for installing it in the liboptv source code.
Installation
------------
Run pip install openptv, which should install everything.

To build the wrapper, Cython must also be installed. Binary installers are
available at www.cython.org. Linux users may simply install from the package
manager, Windows users can get it through Python(x,y). If you have installed
openptv-python from source, then you already have Cython working.
Building the Package
--------------------
The package has to be built from the full repository. Make sure all the dependencies
in requirements.txt are installed, then run:

The test suite consists of Python code that may be run automatically using the
Nose test harness: https://nose.readthedocs.org/en/latest/#
python setup.py prepare # This copies the liboptv sources and converts pyx files to C
python setup.py build # This builds the package

With the dependencies installed, the optv package is installed by typing the
following command in a terminal:
You can then create source distributions and binary wheels:

sudo python setup.py install
python setup.py sdist bdist_wheel

Note that on many systems you will first need to obtain administrator
privileges. On Linux the 'sudo' command is recommended, as shown above.
You can upload them to your favorite repository, as they reside in the dist subdirectory.

Installation on Windows
-----------------------
Install liboptv as instructed in the Windows installation section of
liboptv/README.txt. This way you already have an MSYS environment,
which you continue to use here.
Note: You need to build wheels for each platform you want to support.

At this point, since we are building a Python module, you must have a
Python version installed. The Python(x,y) distribution, available from
https://code.google.com/p/pythonxy/ contains all you need. During the
installation you will be asked to choose packages. To the default
selection add the Cython package. For testing your installation later,
make sure the ``nose`` package is also installed.
On Windows, you must install the Visual C++ Compiler for Python 2.7. It can be found here:
https://www.microsoft.com/en-us/download/details.aspx?id=44266

The commands for installing the Python modules are a bit more elaborate
than the Linux instructions because Windows is evil. First one builds the
package:
You will need to build the package from a Visual C++ for Python Command Prompt.

python setup.py build_ext -I/usr/include -L/usr/lib/ --compiler=mingw32

Then installation is simply

python setup.py install

Testing the installation
------------------------
Expand Down
4 changes: 4 additions & 0 deletions py_bind/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Cython==0.29.5
nose==1.3.7
numpy==1.16.1
PyYAML>=4.2b1
Loading

0 comments on commit 7ab5fd8

Please sign in to comment.