My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
OpenCV  
Build instructions for OpenCV4Java
NativeLib
Updated Aug 12, 2011 by olivier.chafik@gmail.com

Introduction

Quote from the OpenCV Wiki : "OpenCV (Open Source Computer Vision) is a library of programming functions mainly aimed at real time computer vision."

License

BSD-style : OpenCV License

Downloads

Sources available from OpenCV's SourceForge Project.

Java wrappers with self-extracting binaries for MacOSX and Windows 32bits : OpenCV.jar

Building

  • Download OpenCV sources and unzip / untar them
  • Put the following files in the top OpenCV directory :
  • Open a command-line shell and go to the top OpenCV directory
  • On MacOSX : sh makeMacOSXFatBinaries.sh to create fat binaries of OpenCV
  • java -jar jnaerator.jar

Quickstart

Have a look at JNA's frontpage

import cv.*; 
import cxcore.*; 
import highgui.*; 
import ml.*; 
import static cv.CvLibrary.*; 
import static  cxcore.CxcoreLibrary.*; 
import static  highgui.HighguiLibrary.*; 
import static  ml.MlLibrary*; 
import static opencv.OpenCV.*;

public class Test {
	public static void main(String[] args) {
		try {
			IplImage img = highgui.cvLoadImage(args[0], CV_LOAD_IMAGE_UNCHANGED);
			highgui.cvNamedWindow("Example1", CV_WINDOW_AUTOSIZE);
			highgui.cvShowImage("Example1", new CvArr(img));
			System.in.read();
			//HighguiLibrary.INSTANCE.cvWaitKey(0);
			cxcore.cvReleaseImage(new PointerByReference(img.getPointer(0)));
			highgui.cvDestroyWindow("Example1");
		} catch (Throwable th) {
			th.printStackTrace();
		}
	}
}
Comment by miaozh...@gmail.com, Jul 28, 2009

sorry to ask,any doc for this or any more examples beside this one? btw,this is so exciting projects. thank you!

Comment by project member olivier.chafik@gmail.com, Aug 22, 2009

Sorry, that's the only example available so far. For more advanced OpenCV/Java stuff, you might want to have a look at Samuel Audet's work, which doesn't use JNAerated wrappers but hand-coded ones. Cheers

Comment by koppesne...@gmail.com, Sep 16, 2009

I might not fully understand the example but is it true that the OpenCV.jar doesn't contain the HighguiLibrary? class?

I tried to build the required classes according to the howto listed above (on Windows Vista 64bit) but run into the following error at the last command (java -jar jnaerator.jar ):

16-sep-2009 17:55:13 com.ochafik.admin.visualstudio.VisualStudioUtils? getProp INFO: environment? VISUAL_STUDIO_HOME=C:\Program Files (x86)\Microsoft Visual Studio 9.0 16-sep-2009 17:55:13 com.ochafik.admin.visualstudio.VisualStudioUtils? getProp INFO: environment? WINDOWS_SDK_HOME=C:\Program Files\Microsoft SDKs\Windows\v6.0A 16-sep-2009 17:55:13 com.ochafik.admin.visualstudio.VisualStudioUtils? getProp INFO: environment? VISUAL_STUDIO_INCLUDES=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include;C:\Program Files (x86)\Microsoft SDKs\Windows\v6.0A\Includ java.io.FileNotFoundException?: c:\Program Files (x86)\OpenCV1.2\src\cxcore\include\.h

at com.ochafik.lang.jnaerator.JNAeratorCommandLineArgs$ArgsParser?.convertArg(Unknown Source) at com.ochafik.lang.jnaerator.JNAeratorCommandLineArgs$ArgsParser?.parse(Unknown Source) at com.ochafik.lang.jnaerator.JNAerator.main(Unknown Source)

The Paths to Visual Studio & WINDOWS_SDK_HOME are ok. It would be great if you can put me in the right direction. I'm really interested binding OpenCV to my Java projects but I might want to use jnaerator also for other projects. It seems great and much easier as JNI.

Thanks in advance,

Jan Snelders

Comment by project member olivier.chafik@gmail.com, Sep 22, 2009

Hi Jan,

Sorry for replying a bit late, I forgot to register to the comment notifications :-S Can you try with the following command instead :

java -jar jnaerator.jar config.jnaerator

Thanks

Comment by fastun.a...@gmail.com, Oct 4, 2009

Hi Oliver,

I tried to build according to the howto listed above (on Windows XP) but run into the following error at the last command: C:\DevTools?\OpenCV>java -jar jnaerator-0.9.1.jar config.jnaerator 04.10.2009 15:29:06 com.ochafik.admin.visualstudio.VisualStudioUtils? getProp INFO: environment? VISUAL_STUDIO_HOME=C:\Program Files\Microsoft Visual Studio 9.0 04.10.2009 15:29:06 com.ochafik.admin.visualstudio.VisualStudioUtils? getProp INFO: environment? WINDOWS_SDK_HOME=C:\Program Files\Microsoft SDKs\Windows\v6.0A 04.10.2009 15:29:06 com.ochafik.admin.visualstudio.VisualStudioUtils? getProp INFO: environment? VISUAL_STUDIO_INCLUDES=C:\Program Files\Microsoft Visual Studio 9.0\VC\include;C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include java.io.FileNotFoundException?: -entry

at com.ochafik.lang.jnaerator.JNAeratorCommandLineArgs$ArgsParser?.conver
tArg(JNAeratorCommandLineArgs.java:48)
at com.ochafik.lang.jnaerator.JNAeratorCommandLineArgs$ArgsParser?.parse(
JNAeratorCommandLineArgs.java:123)
at com.ochafik.lang.jnaerator.JNAerator.main(JNAerator.java:237)

And, sorry for dummy question, I want to use OpenCV.jar with Eclipse. How can I do it?

Comment by project member olivier.chafik@gmail.com, Oct 4, 2009

Hi, the syntax of .jnaerator files changed and I forgot to update config.jnaerator, sorry about that... I've checked in an update... As for Eclipse look at methods 2 or 3 in section "Adding External JARs" of this howto

And feel free to join the NativeLibs4Java google group for further support :-) Cheers

Comment by Ria.Elli...@mailbox.tu-dresden.de, Jul 31, 2010

I try to use the jnaerator for OpenCV 2.0 right now but don't manage to solve it without any errors as they totaly rearranged the whole package structure. Is there maybe a config-file for OpenCV 2.0 available as well?

Comment by omi1990p...@gmail.com, Sep 26, 2011

Which version this support ,,,cause i have latest one Open CV2.3.1 but don,t know if it supports this or not

Comment by project member olivier.chafik@gmail.com, Oct 18, 2011

NativeLibs4Java?'s OpenCV bindings were just an experiment that is not supported nor maintained. I would advise you to try JavaCV, which is actively maintained : http://code.google.com/p/javacv/. Cheers


Sign in to add a comment
Powered by Google Project Hosting