About Adam Warski

Adam is one of the co-founders of SoftwareMill, a company specialising in delivering customised software solutions. He is also involved in open-source projects, as a founder, lead developer or contributor to: Hibernate Envers, a Hibernate core module, which provides entity versioning/auditing capabilities; ElasticMQ, an SQS-compatible messaging server written in Scala; Veripacks, a tool to specify and verify inter-package dependencies, and others.

Using JavaCV with Scala and SBT

Recently I’ve been doing some simple face detection in a Scala-based project. The “industry standard” for such kind of tasks is OpenCV; face detection is one of its basic use-cases.
 
 
 
 
 
 
 
 

Everybody knows this picture, right?

Everybody knows this picture, right?

However OpenCV is written in C/C++, so obviously to use it from Scala a JVM interface is needed. One of such interfaces is JavaCV, which wraps several computer-vision related libraries, one of them being OpenCV. The process of actually doing face detection from Java using JavaCV is fairly well documented (see for example here), but what I had some trouble with, is getting SBT to get the JavaCV jars from the Maven central repository. There are two steps. First, you need to add the dependency to your build settings:

val javacv = 
  "com.googlecode.javacv" % 
  "javacv" % 
  "0.7" classifier "linux-x86_64" classifier "macosx-x86_64" classifier ""

libraryDependencies += javacv

The unusual thing here are the classifiers. To get the basic jars you need an empty classifier, but you also need some platform-dependent bindings to the native libraries. Here I’m including bindings for OSX (my dev platform) and Linux (my deployment platform). There are also bindings for Windows, e.g. windows-x86. But that won’t get you all the jars yet. The second SBT setting you must modify is:

classpathTypes += "maven-plugin"

That is because some of the dependent jars (javacpp) are packaged with the maven-plugin packaging. And as SBT isn’t Maven, they won’t be included by default. With the two settings above, you should be all set to start doing computer vision with JavaCV, SBT and Scala.
 

Reference: Using JavaCV with Scala and SBT from our JCG partner Adam Warski at the Blog of Adam Warski blog.
Related Whitepaper:

Java Essential Training

Author David Gassner explores Java SE (Standard Edition), the language used to build mobile apps for Android devices, enterprise server applications, and more!

The course demonstrates how to install both Java and the Eclipse IDE and dives into the particulars of programming. The course also explains the fundamentals of Java, from creating simple variables, assigning values, and declaring methods to working with strings, arrays, and subclasses; reading and writing to text files; and implementing object oriented programming concepts. Exercise files are included with the course.

Get it Now!  

Leave a Reply


five × 9 =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.

Sign up for our Newsletter

15,153 insiders are already enjoying weekly updates and complimentary whitepapers! Join them now to gain exclusive access to the latest news in the Java world, as well as insights about Android, Scala, Groovy and other related technologies.

As an extra bonus, by joining you will get our brand new e-books, published by Java Code Geeks and their JCG partners for your reading pleasure! Enter your info and stay on top of things,

  • Fresh trends
  • Cases and examples
  • Research and insights
  • Two complimentary e-books
Get tutored by the Geeks! JCG Academy is a fact... Join Now
Hello. Add your message here.