Short Description

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

Team: Bio Image Analysis
Institution: Institut Pasteur
Website: https://icy.bioimageanalysis.org

Documentation

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!

Resources needing this

Leave a Review

Leave a review
Cancel review
View full changelog
Close changelog

Changelog

  • Version 4.5.1.2 • Released on: 2021-06-14 13:00:00
    Download
    Description:

    Updated to OpenCV 4.5.1-2 last version)

  • Version 3.4.2.0 • Released on: 2020-07-31 16:00:00
    Download
    Description:

    - updated OpenCV to version 3.4.2
    - fixed native library loading for this specific version (require to use internal methods)
    - fixed VideoCapture example for this version

  • Version 3.1.0.1 • Released on: 2019-11-21 13:00:00
    Download
    Description:

    Better native library loading and added windows 32/64 bit support (Stephane)

  • Version 3.1.0.0 • Released on: 2016-10-28 12:01:55
    Download
    Description:

    First fully functional port of OpenCV 3.1.0 library, featuring an extra "OpenCVCapture" plugin to interact with connected cameras.

    Supported architectures:
    - Mac OS Intel (64 bits)
    - Unix ARM (64 bits)
    - Unix AMD (64 bits)

  • Version 0.0.1.0 • Released on: 2015-04-23 12:39:49
    Download