Skip to content

Commit b9a982d

Browse files
authored
Create javacv-installer.md
Moved to correct place
1 parent 4143a11 commit b9a982d

File tree

1 file changed

+138
-0
lines changed

1 file changed

+138
-0
lines changed

_pages/plugins/javacv-installer.md

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
---
2+
title: JavaCV Installer
3+
categories: [Development, Utilities]
4+
source-url: https://github.com/anotherche/imagej-javacv-installer
5+
initial-release-date: "July 2020"
6+
dev-status: "active"
7+
team-founders: "@anotherche"
8+
team-maintainers: "@anotherche"
9+
---
10+
11+
## What is JavaCV
12+
13+
In short, JavaCV is a collection of Java interfaces to various native computer vision libraries originally written in C/C++.
14+
15+
The collection currently includes interfaces to libraries such as OpenCV, FFmpeg, libdc1394, FlyCapture, libfreenect, librealsense, videoInput, ARToolKitPlus, Leptonica, and Tesseract.
16+
17+
The interfaces are based on the original JavaCPP technology developed by Samuel Audet, which allows automatic generation of JNI code for Java wrappers of native libraries using C/C++ header files.
18+
19+
More information is available at [Bytedeco site](https://bytedeco.org/) and [Github](https://github.com/bytedeco).
20+
21+
## How can JavaCV help with ImageJ
22+
23+
JavaCV itself does not contain any plugins for direct use in ImageJ.
24+
However, the interfaces it provides contain many classes and methods for image analysis and manipulation that can be used to develop plugins.
25+
Thus, JavaCV may be needed primarily by plugin developers.
26+
27+
For example, JavaCV was used to develop the [FFmpeg_Video](https://forum.image.sc/t/plugins-for-reading-and-writing-compressed-video/8777) plugin, which uses FFmpeg API to implement import/export of video files of almost any format in ImageJ.
28+
In [PhotoBend](https://imagej.net/plugins/photobend) plugins, the OpenCV interface is used for specific object recognition and tracking, while FFmpeg allows to use video files as sources of sequences of analyzed images.
29+
30+
## What is the JavaCV installer plugin and who might need it
31+
32+
When using third party libraries, developers are always faced with the need to ensure that all dependencies are in place without causing conflicts with other parts of the software.
33+
Since JavaCV contains a large number of interfaces and native libraries for different types of platforms,
34+
simultaneous use of JavaCV components by different ImageJ plugins can lead to problems with over-provisioning dependencies of all the different plugins,
35+
as well as incompatibility between different versions of the components.
36+
37+
To solve this problem, one needs to be able to centrally manage the installation of JavaCV components, and this is exactly what the JavaCV Installer plugin does.
38+
39+
## How it works
40+
41+
***internal operation***
42+
43+
Using the Apache Maven Artifact Resolver library, the installer queries the central Maven repository to determine the available versions of JavaCV and the interfaces provided by its various releases.
44+
A user or programmatic interface allows the user to select JavaCV components of the desired versions and install them in ImageJ.
45+
46+
During installation, the installer checks for and resolves any version conflicts that may occur.
47+
For the final installation of dependencies (jar files), the installer uses a built-in ImageJ update mechanism that requires a restart of ImageJ after the installation is complete.
48+
Additionally, the installer creates a local cache of the repository, allowing quick switching between JavaCV versions
49+
("local-maven-repo" forlder inside ImageJ installation that can be freely deleted at any moment - the installer will recreate it if necessary).
50+
51+
***user front-end***
52+
53+
Manual JavaCV installation can be done using the plugin's user interface:
54+
55+
![](/media/plugins/javacv-installer-ui.png)
56+
57+
Using macro or public methods of the plugin, developers can automatically check for required interfaces and install missing JavaCV dependencies in ImageJ.
58+
59+
For example, to silently install ffmpeg and opencv from JavaCV 1.5.10, one can run the following macro:
60+
```
61+
IJ.run("Install JavaCV libraries", "version=1.5.10 select_installation_option=[Install missing] treat_selected_version_as_minimal_required ffmpeg opencv");
62+
```
63+
64+
To implement interactive installation of missing dependencies, one can use the following code
65+
(note that the first part of this method checks if the installer itself is installed, and installs it in ImageJ if it is missing.):
66+
67+
```
68+
boolean checkJavaCV(String version, boolean treatAsMinVer, String components) {
69+
70+
String javaCVInstallCommand = "Install JavaCV libraries";
71+
Hashtable table = Menus.getCommands();
72+
String javaCVInstallClassName = (String) table.get(javaCVInstallCommand);
73+
if (javaCVInstallClassName == null) {
74+
int result = JOptionPane.showConfirmDialog(null,
75+
"<html><h2>JavaCV Installer not found.</h2>"
76+
+ "<br>Please install it from from JavaCVInstaller update site:"
77+
+ "<br>https://sites.imagej.net/JavaCVInstaller/"
78+
+ "<br>Do you whant it to be installed now for you?"
79+
+ "<br><i>you need to restart ImageJ after the install</i></html>",
80+
"JavaCV check", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
81+
if (result == JOptionPane.YES_OPTION) {
82+
net.imagej.updater.CommandLine updCmd = new net.imagej.updater.CommandLine(
83+
AppUtils.getBaseDirectory("ij.dir", CommandLine.class, "updater"), 80);
84+
updCmd.addOrEditUploadSite("JavaCVInstaller", "https://sites.imagej.net/JavaCVInstaller/", null, null,
85+
false);
86+
net.imagej.updater.CommandLine updCmd2 = new net.imagej.updater.CommandLine(
87+
AppUtils.getBaseDirectory("ij.dir", CommandLine.class, "updater"), 80);
88+
updCmd2.update(Arrays.asList("plugins/JavaCV_Installer/JavaCV_Installer.jar"));
89+
IJ.run("Refresh Menus");
90+
table = Menus.getCommands();
91+
javaCVInstallClassName = (String) table.get(javaCVInstallCommand);
92+
if (javaCVInstallClassName == null) {
93+
IJ.showMessage("JavaCV check",
94+
"Failed to install JavaCV Installer plugin.\nPlease install it manually.");
95+
}
96+
}
97+
return false;
98+
}
99+
100+
String installerCommand = "version=" + version + " select_installation_option=[Install missing] "
101+
+ (treatAsMinVer ? "treat_selected_version_as_minimal_required " : "") + components;
102+
103+
boolean saveRecorder = Recorder.record; // save state of the macro Recorder
104+
Recorder.record = false; // disable the macro Recorder to avoid the JavaCV installer plugin being
105+
// recorded instead of this plugin
106+
String saveMacroOptions = Macro.getOptions();
107+
IJ.run("Install JavaCV libraries", installerCommand);
108+
if (saveMacroOptions != null)
109+
Macro.setOptions(saveMacroOptions);
110+
Recorder.record = saveRecorder; // restore the state of the macro Recorder
111+
112+
String result = Prefs.get("javacv.install_result", "");
113+
String launcherResult = Prefs.get("javacv.install_result_launcher", "");
114+
if (!(result.equalsIgnoreCase("success") && launcherResult.equalsIgnoreCase("success"))) {
115+
if (result.indexOf("restart") > -1 || launcherResult.indexOf("restart") > -1) {
116+
IJ.log("Please restart ImageJ to proceed with installation of necessary JavaCV libraries.");
117+
return false;
118+
} else {
119+
IJ.log("JavaCV installation failed. Trying to use JavaCV as is...");
120+
return true;
121+
}
122+
}
123+
return true;
124+
}
125+
```
126+
## Installation in Fiji
127+
128+
To install the plugin manually:
129+
<ol>
130+
<li>add JavaCV Installer update site https://sites.imagej.net/JavaCVInstaller using the update sites manager </li>
131+
<li>install the plugin normally using the updater</li>
132+
</ol>
133+
134+
For the automated installation see the above code example of the `checkJavaCV` method.
135+
136+
## Additional information and support
137+
138+
The plugin is discussed at [imagej forum](https://forum.image.sc/t/new-javacv-installer-plugin/55392)

0 commit comments

Comments
 (0)