10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ProcessingでOpenCVを使う

Last updated at Posted at 2015-06-07

OpenCVの公式JavaラッパーをProcessingで使う
OpenCV for ProcessingOPENCV Processing and Java Libraryもあるけど
機能に限りがあるので公式のものを使うことをおすすめします
2015/11/9訂正:
OpenCV for ProcessingはJavaのOpenCVを使用しているようでした.
最新版のOpenCVを使いたい方はこの方法を試すか,OpenCV for Processingの中を書き換えてみてください.

まずはOpenCVのJavaラッパーを持ってくる
Macの場合はhomebrewで管理できる(Windowsの方はすみません)

pip install numpy
brew tap home-brew/science
brew install opencv --with-java

少し時間がかかるが終わったら
/usr/local/Cellar/opencv/2.4.11_1/share/OpenCV/java/
opencv-2411.jar
libopencv_java2411.dylib
があるはず
注 ) 数字はバージョンによって異なります
次にProcessing/librariesopencv/libraryディレクトリを作り
先ほどのopencv-2411.jarlibopencv_java2411.dylibをコピーする
最終的には
Processing/libraries/opencv/library/opencv-2411.jar
Processing/libraries/opencv/library/libopencv_java2411.dylib

になる
これでProcessingライブラリ化は完了なのでサンプルを動かしてみる

HelloOpenCV.pde
import org.opencv.core.*;

Mat img;

void setup() {
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  Mat m  = Mat.eye(3, 3, CvType.CV_8UC1);
  System.out.println("m = " + m.dump());
}
void draw() {
}

無事に

m = [1, 0, 0;
  0, 1, 0;
  0, 0, 1]

と表示されたら終了
PImageとMatの変換については次の投稿

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?