Установка OpenCV 2.4.9 и работа с JavaCV на Mac OS X 10.8.5


Установка OpenCV

Installing OpenCV 2.4.9 on Mac OSX with Python Support | jjyap

tap [tap]
Tap a new formula repository from GitHub, or list existing taps.
tap is of the form user/repo, e.g. brew tap homebrew/dupes.

brew tap homebrew/science
brew info opencv

opencv: stable 2.4.9, HEAD
http://opencv.org/
Not installed
From: https://github.com/homebrew/homebrew-science/blob/master/opencv.rb
==> Dependencies
Build: cmake ✘, pkg-config ✔
Required: jpeg ✔, libpng ✔, libtiff ✔
Recommended: openexr ✘
Optional: eigen ✘, gstreamer ✘, jasper ✘, libdc1394 ✘, openni ✘, qt ✘, tbb ✘, ffmpeg ✘
==> Options
--32-bit
    Build 32-bit only
--c++11
    Build using C++11 mode
--with-cuda
    Build with CUDA support
--with-eigen
    Build with eigen support
--with-ffmpeg
    Build with ffmpeg support
--with-gstreamer
    Build with gstreamer support
--with-jasper
    Build with jasper support
--with-java
    Build with Java support
--with-libdc1394
    Build with libdc1394 support
--with-openni
    Build with openni support
--with-qt
    Build the Qt4 backend to HighGUI
--with-quicktime
    Use QuickTime for Video I/O insted of QTKit
--with-tbb
    Enable parallel code in OpenCV using Intel TBB
--with-tests
    Build with accuracy & performance tests
--without-opencl
    Disable GPU code in OpenCV using OpenCL
--without-openexr
    Build without openexr support
--HEAD
    install HEAD version


OpenCV поддерживает работу со следующими технологиями:

brew install opencv

$ brew install opencv
==> Installing dependencies for opencv: cmake, ilmbase, openexr
==> Installing opencv dependency: cmake
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/cmake-3.0.1.mountain_lion.bottle.tar.gz
######################################################################## 100,0%
==> Pouring cmake-3.0.1.mountain_lion.bottle.tar.gz
🍺  /usr/local/Cellar/cmake/3.0.1: 1623 files, 27M
==> Installing opencv dependency: ilmbase
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/ilmbase-2.1.0.mountain_lion.bottle.tar.gz
######################################################################## 100,0%
==> Pouring ilmbase-2.1.0.mountain_lion.bottle.tar.gz
🍺  /usr/local/Cellar/ilmbase/2.1.0: 75 files, 1,6M
==> Installing opencv dependency: openexr
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openexr-2.1.0.mountain_lion.bottle.tar.gz
######################################################################## 100,0%
==> Pouring openexr-2.1.0.mountain_lion.bottle.tar.gz
🍺  /usr/local/Cellar/openexr/2.1.0: 127 files, 7,0M
==> Installing opencv
==> Downloading https://github.com/Itseez/opencv/archive/2.4.9.tar.gz
######################################################################## 100,0%
==> cmake .. -DCMAKE_INSTALL_PREFIX=/usr/local/Cellar/opencv/2.4.9 -DCMAKE_BUILD_TYPE=None -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_VERBOSE_MAKEFILE=ON -Wno-dev -DCMAKE_OSX_DEPLOYMENT_TARGET= -DBUILD_ZLIB=OFF -DBUILD_TIFF=OFF -DBUILD_PNG=O
==> make
==> make install
🍺  /usr/local/Cellar/opencv/2.4.9: 217 files, 38M, built in 7.9 minutes

Я тут произвел установку без флага --with-java, но вам бы порекомендовал чтобы потом не переустанавливать.

Классическое введение: Introduction to programming with OpenCV

Установка JavaCV

1) Для работы с JavaCV устанавливать OpenCV не обязательно. Я например сразу удалил: brew uninstall opencv

2) Со страницы проекта bytedeco/javacv нужно скопировать зависимость для Apache Maven.

При самостоятельной сборке надо убедиться что JAVA_HOME установлена правильно. Это можно сделать так: java - Where is JAVA_HOME on OSX Lion (10.7) , Mountain Lion (10.8) or Mavericks (10.9)? - Stack Overflow

3) Импорт пакетов:
import org.bytedeco.javacv.*;
import org.bytedeco.javacpp.*;
import static org.bytedeco.javacpp.opencv_core.*;
import static org.bytedeco.javacpp.opencv_imgproc.*;
import static org.bytedeco.javacpp.opencv_calib3d.*;
import static org.bytedeco.javacpp.opencv_objdetect.*;
import static org.bytedeco.javacpp.opencv_highgui.*;

4) Код:
IplImage colorImage = IplImage.create(640, 480, IPL_DEPTH_8U, 3);
cvZero(colorImage);
if (colorImage != null)
{
 cvSaveImage("black.png", colorImage);
}
cvReleaseImage(colorImage);

5) Самая распространенная ошибка:
java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path

Практически 100% это что-то с версиями. В моем случае проблема решилась понижением версии с 0.9 до 0.8 в Maven зависимости.

--