Skip to content
A lein template to quickly create and manage an OpenCV project in Clojure
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A Leiningen template for creating OpenCV project and REPLing with them


The opencv-start lein template requires you have already installed into your local maven repository both the opencv/opencv "2.4.7" and opencv/opencv-native "2.4.7" artifacts.

To satisfy these requirements follow the Introduction to OpenCV Development with Clojure available on the official web site.

Quick start

The following is a very quick start guide to install OpenCV 2.4.7 or higher with Java bindings and assumes you have already installed the requirements to build OpenCV lib from the source.

Install OpenCV 2.4 with java bindings

I assume you're going to install opencv in the ~/dev directory.

cd ~/dev
git clone git://
cd opencv
git checkout 2.4
mkdir build
cd build
make -j8

Install Leiningen

The available Leiningen installation guide is very easy to be followed:

  1. Download the script
  2. Place it on your $PATH (cf. ~/bin is a good choice if it is on your path.)
  3. Set the script to be executable. (i.e. chmod 755 ~/bin/lein).

If you work on Windows, follow this instruction.

Install the lein-localrepo plugin

If it does not exist yet, create the .lein directory in your home directory.

mkdir -p ~/.lein

Create a new file named profiles.clj in the ~/.lein directory with the following content:

{:user {:plugins [[lein-localrepo "0.5.2"]]}}

Install opencv libs as local maven repository artifacts

Note that this step has to be done once only for each machine you want to run an OpenCV project in Clojure.


Start by creating a new directory of your choice (e.g. ~/dev/clj-opencv) and by copying in it the opencv-247.jar file generated when you previously built opencv with java bindings.

mkdir -p ~/dev/clj-opencv
cd ~/dev/clj-opencv
cp ~/dev/opencv/build/bin/opencv-247.jar .

To be able to add the shared native lib to the local maven repository, we first need to package it as a jar file.

The native lib has to be copied into a directories layout which mimics the names of your operating system and architecture. I’m using a Mac OS X with a X86 64 bit architecture. So my layout will be the following:

# for Mac OS X
mkdir -p native/macosx/x86_64
# for GNU/Linux
# mkdir -p native/linux/x86_64 

Copy into it the shared native lib for your OS (e.g. libopencv_java247.dylib for Mac OS X, for GNU/Linux)

# for Mac OS X
cp ~/dev/opencv/build/lib/libopencv_java247.dylib native/macosx/x86_64/
# for GNU/Linux
# cp ~/dev/opencv/build/lib/ native/linux/x86_64/

If you’re running OpenCV from a different OS/Architecture pair, here is a summary of the mapping you can choose from.


Mac OS X -> macosx
Windows  -> windows
Linux    -> linux
SunOS    -> solaris


amd64    -> x86_64
x86_64   -> x86_64
x86      -> x86
i386     -> x86
arm      -> arm
sparc    -> sparc

You now need to package the native lib in a jar file by using the jar command.

jar -cMf opencv-native-247.jar native
Install opencv artifacts into the local maven repository

First install the opencv-247.jar in the local maven repository.

lein localrepo install opencv-247.jar opencv/opencv 2.4.7

The above command installs in the local maven repository (e.g. ~/.m2/repository/) the opencv-247.jar jar file as the 2.4.7 release of the opencv artifactId in the opencv groupId.

Next install the shared native opencv lib too.

lein localrepo install opencv-native-247.jar opencv/opencv-native 2.4.7

The above command installs in the local maven repository the 2.4.7 release of the opencv-native artifactId in the opencv groupId.

You're now ready to use the opencv-start lein template to create new Clojure projects interoperating with the opencv lib.


Create a new project

To create a new OpenCV project issue the following lein command (task in leiningen parlance):

lein new opencv-start com.sinapsi/first-project

REPLing with the project

To start REPLing with your newly create project, just run the following lein task from the main directory of the project:

cd first-project
Giacomos-MacBook-Pro:opencv-repl mimmo$ lein repl
nREPL server started on port 50090 on host
REPL-y 0.3.0
Clojure 1.5.1
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e



Copyright © 2013 Giacomo (Mimmo) Cosenza aka Magomimmo

Distributed under the BSD 3-clause

You can’t perform that action at this time.