Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Support for the latest OpenCV version #54

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ find_package(PkgConfig REQUIRED)

find_package(OpenCV REQUIRED)

if(NOT (${OpenCV_VERSION} VERSION_LESS 3))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what do you think about that?

Suggested change
if(NOT (${OpenCV_VERSION} VERSION_LESS 3))
if${OpenCV_VERSION} VERSION_GREATER_EQUAL 3)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV_LEGACY_MODE")
endif()

include_directories(${OpenCV_INCLUDE_DIRS})
link_directories(${OpenCV_LIBRARY_DIRS})

Expand Down
46 changes: 40 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ See the new features in our latest release.

## Installation

First grab Aeon's dependencies:
First grab aeon's dependencies:

### Ubuntu (release 16.04 LTS and later):
### Ubuntu (release 16.04 LTS and later)

apt-get install git clang libopencv-dev

##### For Python 3.n

apt-get install python3-dev python3-pip python3-numpy

### CentOS (release 7.2 and later):
### CentOS (release 7.2 and later)

yum install epel-release
yum install git clang gcc-c++ make cmake opencv-devel
Expand All @@ -37,7 +37,7 @@ First grab Aeon's dependencies:

yum install python-pip python34-pip python34-devel python34-opencv python34-numpy

### OSX:
### OSX

brew tap homebrew/science
brew install opencv
Expand All @@ -57,9 +57,9 @@ First grab Aeon's dependencies:
# If you want to generate report when unit test fails: make -i coverage
make coverage

### To install Aeon:
### To install aeon

git clone https://github.com/NervanaSystems/aeon.git
git clone -b develop https://github.com/NervanaSystems/aeon.git

##### For Python 2.7

Expand All @@ -73,6 +73,40 @@ First grab Aeon's dependencies:
pip3 install -r requirements.txt
mkdir -p build && cd $_ && cmake .. && pip3 install .

### To install aeon with the latest OpenCV version

##### Clone aeon repository

git clone -b develop https://github.com/NervanaSystems/aeon.git

##### Build OpenCV

mkdir -p aeon/build/3rdparty && cd $_
git clone https://github.com/opencv/opencv.git
cd opencv && mkdir build && cd $_

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=$(pwd)/installation/OpenCV -DINSTALL_C_EXAMPLES=OFF -DINSTALL_PYTHON_EXAMPLES=OFF -DWITH_TBB=OFF -DWITH_V4L=OFF -DWITH_QT=OFF -DWITH_OPENGL=OFF -DBUILD_EXAMPLES=OFF -DWITH_CUDA=OFF -DOPENCV_FORCE_3RDPARTY_BUILD=OFF -DWITH_IPP=OFF -DWITH_ITT=OFF -DBUILD_ZLIB=OFF -DBUILD_TIFF=OFF -DBUILD_JASPER=OFF -DBUILD_JPEG=OFF -DBUILD_PNG=OFF -DBUILD_OPENEXR=OFF -DBUILD_WEBP=OFF -DBUILD_opencv_gpu=OFF -DOPENCV_GENERATE_PKGCONFIG=ON -DOPENCV_PC_FILE_NAME=opencv.pc ..

make -j8 # for example it runs 8 jobs in parallel
make install

##### Install aeon

cd ../../../
cmake -DCMAKE_PREFIX_PATH=$(pwd)/3rdparty/opencv/build/installation/OpenCV ..

##### For Python 2.7

pip install -r ../requirements.txt
pip install .

##### For Python 3.n

pip3 install -r ../requirements.txt
pip3 install .

You can also build wheel package with command `python setup.py bdist_wheel`

Note: if installing system wide (as opposed to within a virtual environment) you may need to run `sudo`

Now continue on to the [user guide](http://aeon.nervanasys.com/index.html/user_guide.html) to get started using aeon. Or to the
Expand Down
6 changes: 5 additions & 1 deletion src/cap_mjpeg_decoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#include "opencv2/imgproc/imgproc_c.h"
#include <opencv2/imgproc/imgproc_c.h>
#include <opencv2/highgui/highgui_c.h>
#ifdef OPENCV_LEGACY_MODE
#include <opencv2/imgcodecs/legacy/constants_c.h>
#include <opencv2/videoio/legacy/constants_c.h>
#endif

#include "util.hpp"
#include "avi.hpp"
Expand Down
8 changes: 8 additions & 0 deletions src/etl_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ image::extractor::extractor(const image::config& cfg)
{
_pixel_type = CV_MAKETYPE(CV_8U, cfg.channels);
_color_mode = cfg.channels == 1 ? CV_LOAD_IMAGE_GRAYSCALE : CV_LOAD_IMAGE_COLOR;
#ifdef OPENCV_LEGACY_MODE
// Do not run ApplyExifOrientation as this causes Segmentation faults
_color_mode = _color_mode | CV_LOAD_IMAGE_IGNORE_ORIENTATION;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So with OpenCV>=3 we have to add CV_LOAD_IMAGE_IGNORE_ORIENTATION to prevent the unexpected orientation change?

#endif
}
}

Expand All @@ -86,7 +90,11 @@ shared_ptr<image::decoded> image::extractor::extract(const void* inbuf, size_t i

// It is bad to cast away const, but opencv does not support a const Mat
// The Mat is only used for imdecode on the next line so it is OK here
#ifdef OPENCV_LEGACY_MODE
cv::Mat input_img(insize * CV_MAT_CN(_pixel_type), 1, CV_8UC1, (char*)inbuf);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this constructor do?

#else
cv::Mat input_img(1, insize, _pixel_type, (char*)inbuf);
#endif
cv::imdecode(input_img, _color_mode, &output_img);

if (output_img.empty()) {
Expand Down
4 changes: 4 additions & 0 deletions src/etl_image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
#ifdef OPENCV_LEGACY_MODE
#include <opencv2/imgcodecs/legacy/constants_c.h>
#include <opencv2/videoio/legacy/constants_c.h>
#endif
#include <chrono>
#include "interface.hpp"
#include "image.hpp"
Expand Down
3 changes: 3 additions & 0 deletions src/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#ifdef OPENCV_LEGACY_MODE
#include <opencv2/imgproc/types_c.h>
#endif

namespace nervana
{
Expand Down
20 changes: 11 additions & 9 deletions src/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ def parallelCCompile(self, sources, output_dir=None, macros=None, include_dirs=N
import distutils.ccompiler
distutils.ccompiler.CCompiler.compile=parallelCCompile

lib_dirs = ""
lib_dirs += " -L${CMAKE_PREFIX_PATH}/lib "
libs = ""
include_dirs = ""
include_dirs += " -I${CMAKE_PREFIX_PATH}/include "
lib_dirs = "${CMAKE_PREFIX_PATH}/lib"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happened here to this file?

include_dirs = "${OpenCV_INCLUDE_DIRS}".replace(';', ' ')

status, tmp = getstatusoutput("pkg-config --cflags opencv")
if "${CMAKE_PREFIX_PATH}":
export_cv_pkg_config_path = "export PKG_CONFIG_PATH=${CMAKE_PREFIX_PATH}/lib/pkgconfig;"
else:
export_cv_pkg_config_path = ""

status, tmp = getstatusoutput(export_cv_pkg_config_path + "pkg-config --cflags opencv")
if status != 0:
print("required package 'opencv' not found")
exit()
include_dirs += tmp
lib_dirs += getoutput("pkg-config --libs-only-L opencv")
libs += getoutput("pkg-config --libs-only-l opencv")
include_dirs += " " + tmp
lib_dirs += " " + getoutput(export_cv_pkg_config_path + "pkg-config --libs-only-L opencv")
libs = getoutput(export_cv_pkg_config_path + "pkg-config --libs-only-l opencv")

libs += ' -lstdc++fs'

Expand Down