Need help or advice ? Come to the Icy club ! - Every Wenesday morning from 9h30 to 12h30 - Francois Jacob Building - Main hall - Pasteur
Register

User reviews

This plugin is not rated yet


Please log-in to post a review

OpenCV

by Alexandre Dufour

OpenCV (Open Computer Vision) library for Icy. see more at http://opencv.org

Publication Id
ICY-I2C2C8
See technical details
View complete changelog

Documentation

Note: the current plug-in is a placeholder, as we finalise our tests. The final version (v.3.0.0b) will be online very soon. 

OpenCV for Icy currently supports Mac (64 bit only) and Windows (32 & 64 bit architectures).

 

About

OpenCV is a popular open-source C++ library for computer vision and comprises numerous algorithms for 2D image and video capture and processing. OpenCV is released under a BSD license and hence is free for both academic and commercial use.

Additionally, this plug-in provides a general-purpose class (smartly) called OpenCV, which contains several utilities to test OpenCV and convert between Icy's and OpenCV's image structures. 

 

Documentation

Most of the documentation and help regarding OpenCV is available here: http://docs.opencv.org. Additionally, the OpenCV team has done a terrific job in properly documenting the Java wrapper, therefore any modern IDE will give you access to the documentation and how to use its many functionalities. However, in this quick start guide you should have a few pointers to get busy in no time:

Testing OpenCV

1) Live webcam

This is perhaps the simplest / most fun example to begin with (you do need a compatible webcam, though). All you need to do is pop-up the Script Editor (don't forget to import the OpenCV module using the auto-completion) and call:

OpenCV.liveWebcam()

Voila! This should open an Icy viewer with the live feed from the camera. And if you feel like it, a screenshot is the best way to immortalise the moment!

NB: despite our heavy testing it may still happen that Icy crashes "badly" on this example, i.e. shuts down completely with no bug report. In this case please report this to the forum, indicating your operating system and webcam model (if you know it).

2) The good'ol' Sobel filter

Another simple test (convenient if you actually don't have a webcam to play with) is to call OepnCV to perform some filtering on the active image. In this example, the sript will take the active image, perform a Sobel filter along X, then along Y, and will produce a new image formed of a blend of the 2 filters. Just type this in a Script Editor (don't forget to import the OpenCV module using the auto-completion):

OpenCV.testSobel()

And presto, the currently opened image is returned to you in a "Sobelised" fashion!

Exploiting OpenCV in your own code

The tests above don't do much besides testing that OpenCV is live. Now for heavy buisness!

1) Load OpenCV

By default, OpenCV does not load its native libraries automatically when Icy starts (for performance reasons), so this is the first thing you should do somewhere in your code, by calling:

OpenCV.initialize();

NB#1: this call is not necessary when calling the methods of the OpenCV class (as in the examples above), but mandatory before using any of the official OpenCV classes.
NB#2: it doens't matter how many times you call this, only the first call actually does the loading

2) Use OpenCV

The entire OpenCV code base is located in the org.opencv package (and its subpackages). The starting point is most certainly the Mat class (org.opencv.core.Mat), which is a general matrix representation of the image data handled in OpenCV (as of v.3.0). In order to use OpenCV's functionalities, your first step is thus to convert Icy's images into Mat objects. This is done as follows:

IcyBufferedImage img = Icy.getMainInterface().getActiveImage(); // or anything else...
Mat mat = OpenCV.convertToMat(img);

Once you are here, you next step is probably to have a look at the many image processing functionalities available, which are in the Imgproc class (org.opencv.imgproc.Imgproc). To recall the Sobel example above, you could then do this:

Mat x = new Mat();
Mat y = new Mat();
// filter along X
Imgproc.Sobel(mat, x, -1, 1, 0);
// filter along Y
Imgproc.Sobel(mat, y, -1, 0, 1);
// Blend the result of both filters
org.opencv.core.Core.addWeighted(x, 0.5, y, 0.5, 1.0, mat);

Note here the use of the org.opencv.core.Core class, which provides other basic math and matrix operations.

Finally, once your job is done, time to go back to Icy for visualisation. The operation is as easy as before:

img = OpenCV.convertToIcy(mat);
Icy.getMainInterface().addSequence(new Sequence("My Sobelised image", img));

 

I hope this tutorial is clear enough, and I can't wait to hear your feedback in the forum!