Skip to content

Commit

Permalink
Merge pull request #338 from asterics/deinhofer/javacv-upgrade-and-op…
Browse files Browse the repository at this point in the history
…timizations-1.5

downgraded javacv to 1.5, this uses opencv 4.0.1 without openblas dep…
  • Loading branch information
deinhofer authored May 6, 2020
2 parents e81b01f + 7d4fffa commit c88a5e1
Show file tree
Hide file tree
Showing 17 changed files with 185 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public class XFacetrackerLKInstance extends AbstractRuntimeComponentInstance imp
private Integer propFrameRate = 0;
private boolean propDisplayGUI = true;
private boolean propEnableOverlaySettings = true;
private Integer propResizeHeight = 120;

private String instanceId = "XFacetrackerLK";

Expand Down Expand Up @@ -201,6 +202,8 @@ public Object getRuntimePropertyValue(String propertyName) {
return propFrameRate;
} else if ("enableOverlaySettings".equalsIgnoreCase(propertyName)) {
return propEnableOverlaySettings;
} else if ("resizeHeight".equalsIgnoreCase(propertyName)) {
return propResizeHeight;
}

return "";
Expand Down Expand Up @@ -279,6 +282,13 @@ public Object setRuntimePropertyValue(String propertyName, Object newValue) {
propEnableOverlaySettings = false;
}
return oldValue;
} else if ("resizeHeight".equalsIgnoreCase(propertyName)) {
oldValue = propResizeHeight;
propResizeHeight = 120;
try {
propResizeHeight = Integer.parseInt((String) newValue);
} catch (NumberFormatException e) {
}
}

if (wasRunning) {
Expand Down Expand Up @@ -827,7 +837,7 @@ public void drawPoints(IplImage img, CvPoint2D32f corners) {
public CvPoint2D32f findFeatures(IplImage imgA) {

try {
faceRect = faceDetection.detectFace(imgA);
faceRect = faceDetection.detectFace(imgA,propResizeHeight);
if (faceRect != null) {
System.out.println("\nFound face at: " + faceRect);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@
<property name="enableOverlaySettings"
type="boolean"
value="true"
description="if selected, the video frame shows the current frame rate and device name as overlayed text."/>
description="if selected, the video frame shows the current frame rate and device name as overlayed text."/>
<!-- <property name="resizeHeight"
type="integer"
value="120"
description="The frame height for to be used for face detection. On slow platforms, decrease value, otherwise leave it."/> -->
<!--
<property name="cameraDisplayUpdate"
type="integer"
Expand Down
51 changes: 43 additions & 8 deletions ARE/middleware/src/main/java/eu/asterics/mw/are/BundleManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.*;
import java.util.logging.Logger;

import org.apache.commons.codec.binary.Hex;
Expand Down Expand Up @@ -731,6 +724,9 @@ public void installServices() {
return;
}

OSUtils.getArchBaseString();
OSUtils.getBitness();

String path;
Bundle bundle = null;

Expand All @@ -751,6 +747,11 @@ public void installServices() {
if (path.startsWith("#") || path.isEmpty() || !path.endsWith(".jar")) {
continue;
}

//Trying to load architecture specific service file.
path=getPlatformSpecificJarName(path);
logger.fine("Using platform-specific pathname: "+path);

try {
URI jarURI = ResourceRegistry.getInstance().getResource(path, RES_TYPE.JAR);
// bundle=installSingle(jarURI);
Expand All @@ -773,6 +774,40 @@ public void installServices() {
notifyAREEventListeners(AREEvent.POST_BUNDLES_EVENT);
}

/**
* Returns a platform-specific pathname, if the tested jar exists.
* The tests are done in the following order:
* <basename>-<arch>_<bitness>.jar
* <basename>-<arch>.jar
* <basename>.jar
*
* @param path
* @return
*/
private String getPlatformSpecificJarName(String path) {
String[] pathElems=path.split(".jar");
// logger.fine("path: "+path+", pathElems: "+Arrays.toString(pathElems));
if(pathElems.length == 1) {
try{
String testJarName=pathElems[0]+"-"+OSUtils.getArchBaseString()+"_"+OSUtils.getBitness()+".jar";
// logger.fine("Checking for existence of <"+testJarName+">");
if(ResourceRegistry.getInstance().resourceExists(ResourceRegistry.getInstance().getResource(testJarName,RES_TYPE.JAR))) {
return testJarName;
}

testJarName=pathElems[0]+"-"+OSUtils.getArchBaseString()+".jar";
// logger.fine("Checking for existence of <"+testJarName+">");
if(ResourceRegistry.getInstance().resourceExists(ResourceRegistry.getInstance().getResource(testJarName,RES_TYPE.JAR))) {
return testJarName;
}
} catch(Exception e) {
logger.fine("Could not check pathname of resource: "+e.getMessage());
}
}
//otherwise return the given path name.
return path;
}

/**
* Actually generates the loader_componentlist.ini file, which is actually a cache and maps Asterics components to the associated component jar. This is
* necessary because, unlike in OSGi normally, there is no 1:1 mapping between a component and the jar name. In Asterics a several components may be bundled
Expand Down
42 changes: 42 additions & 0 deletions ARE/middleware/src/main/java/eu/asterics/mw/utils/OSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public class OSUtils {
AREProperties.instance.setDefaultPropertyValue(ARE_OPEN_URL_CMD_KEY_PREFIX + LINUX, "xdg-open", "Default Linux command to start a browser.");
AREProperties.instance.setDefaultPropertyValue(ARE_OPEN_URL_CMD_KEY_PREFIX + WINDOWS, "explorer", "Default Windows command to start a browser.");
AREProperties.instance.setDefaultPropertyValue(ARE_OPEN_URL_CMD_KEY_PREFIX + MACOSX, "open", "Default Mac OSX command to start a browser.");

logger.fine("sun.arch.data.model: "+System.getProperty("sun.arch.data.model"));
logger.fine("os.arch: "+System.getProperty("os.arch"));
logger.fine("Architecture String: "+OSUtils.getArchString());
logger.fine("Architecture Base String: "+OSUtils.getArchBaseString());
}

public static enum OS_NAMES {
Expand Down Expand Up @@ -114,6 +119,43 @@ public static String getOsName() {
return "unknown";
}

/**
* Returns the CPU architecture string. AMD64 will be mapped to x86_64.
*
* @return
*/
public static String getArchString() {
String archString=System.getProperty("os.arch");

if(archString.equalsIgnoreCase("amd64")) {
archString="x86_64";
}
return archString;
}

/**
* Returns the CPU architecture base string. Should be arm or x86 or ppc?.
*
* @return
*/
public static String getArchBaseString() {
String archBaseString=getArchString();
if(archBaseString.startsWith("x86")) {
archBaseString="x86";
}

return archBaseString;
}

/**
* Returns the CPU bitness: 32 or 64.
*
* @return
*/
public static String getBitness() {
return System.getProperty("sun.arch.data.model");
}

/**
* Starts the given application using its applicationPath, arguments and workingDirectory but only if the current platform equals to executeOnPlatform or if
* executeOnPlatform equals to {@link OS_NAMES#ALL}.
Expand Down
12 changes: 11 additions & 1 deletion ARE/services/ComputerVision/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<property name="services" location="../../services"/>
<property name="resources" location="src/main/resources"/>
<property name="javacv.dest" location="javacv/"/>
<property name="javacv.version" value="1.5.2"/>
<property name="javacv.version" value="1.5"/>
<!-- don't forget to also update the MANIFEST file!! -->

<property name="jar.os.name.windows" value="windows"/>
Expand Down Expand Up @@ -143,6 +143,11 @@
<arg value="-f"/>
<arg value="javacv-windows.bnd"/>
</java>
<java jar="${biz.aQute:bnd:jar}" fork="true">
<arg value="bnd"/>
<arg value="-f"/>
<arg value="javacv-windows-x86_64.bnd"/>
</java>
</target>
<!-- a linux-only version with opencv, libfreenect -->
<target name="do-merge-jars-linux" description="Generate a merged javacv OSGI-bundle with linux-only jars" unless="javacv.linux.exists">
Expand All @@ -151,6 +156,11 @@
<arg value="-f"/>
<arg value="javacv-linux.bnd"/>
</java>
<java jar="${biz.aQute:bnd:jar}" fork="true">
<arg value="bnd"/>
<arg value="-f"/>
<arg value="javacv-linux-arm.bnd"/>
</java>
</target>
<!-- a macosx-only version with opencv, libfreenect -->
<target name="do-merge-jars-macosx" description="Generate a merged javacv OSGI-bundle with macosx-only jars" unless="javacv.macosx.exists">
Expand Down
18 changes: 18 additions & 0 deletions ARE/services/ComputerVision/javacv-linux-arm.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version=1.5
opencv-ver=4.0.1
src=./javacv
pkg=org/bytedeco
-includeresource: ${src}/${pkg}/javacv/${version}/javacv-${version}.jar, ${src}/${pkg}/javacv-platform/${version}/javacv-platform-${version}.jar, ${src}/${pkg}/javacpp/${version}/javacpp-${version}.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}-linux-arm64.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}-linux-armhf.jar, ${src}/${pkg}/opencv-platform/${opencv-ver}-${version}/opencv-platform-${opencv-ver}-${version}.jar, ${src}/${pkg}/openblas-platform/0.3.7-${version}/openblas-platform-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-linux-armhf.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-linux-arm64.jar
-exportcontents: org.bytedeco
-output: ../javacv-${version}-basic-linux-arm.jar
Bundle-ClassPath: ., javacv-${version}.jar, javacv-platform-${version}.jar, javacpp-${version}.jar, opencv-${opencv-ver}-${version}.jar, opencv-${opencv-ver}-${version}-linux-x86_64.jar, opencv-${opencv-ver}-${version}-linux-x86.jar, opencv-${opencv-ver}-${version}-linux-arm64.jar, opencv-${opencv-ver}-${version}-linux-armhf.jar, opencv-platform-${opencv-ver}-${version}.jar, openblas-platform-0.3.7-${version}.jar, openblas-0.3.7-${version}.jar, openblas-0.3.7-${version}-linux-x86.jar, openblas-0.3.7-${version}-linux-x86_64.jar, openblas-0.3.7-${version}-linux-armhf.jar, openblas-0.3.7-${version}-linux-arm64.jar
Manifest-Version: 1.0
Created-By: bnd
Built-By: deinhofer
Bundle-ManifestVersion: 2
Bundle-Name: asterics-services.javacv
Bundle-SymbolicName: org.bytedeco.javacv
Bundle-Version: ${version}
Export-Package: org.bytedeco.java*, org.bytedeco.opencv.opencv_*, org.bytedeco.*.global.*
Import-Package: *;resolution:=optional
DynamicImport-Package:
7 changes: 4 additions & 3 deletions ARE/services/ComputerVision/javacv-linux.bnd
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version=1.5.2
version=1.5
opencv-ver=4.0.1
src=./javacv
pkg=org/bytedeco
-includeresource: ${src}/${pkg}/javacv/${version}/javacv-${version}.jar, ${src}/${pkg}/javacv-platform/${version}/javacv-platform-${version}.jar, ${src}/${pkg}/javacpp/${version}/javacpp-${version}.jar, ${src}/${pkg}/opencv/4.1.2-${version}/opencv-4.1.2-${version}.jar, ${src}/${pkg}/opencv/4.1.2-${version}/opencv-4.1.2-${version}-linux-x86_64.jar, ${src}/${pkg}/opencv/4.1.2-${version}/opencv-4.1.2-${version}-linux-x86.jar, ${src}/${pkg}/opencv/4.1.2-${version}/opencv-4.1.2-${version}-linux-arm64.jar, ${src}/${pkg}/opencv/4.1.2-${version}/opencv-4.1.2-${version}-linux-armhf.jar, ${src}/${pkg}/opencv-platform/4.1.2-${version}/opencv-platform-4.1.2-${version}.jar, ${src}/${pkg}/openblas-platform/0.3.7-${version}/openblas-platform-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-linux-x86.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-linux-x86_64.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-linux-armhf.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-linux-arm64.jar
-includeresource: ${src}/${pkg}/javacv/${version}/javacv-${version}.jar, ${src}/${pkg}/javacv-platform/${version}/javacv-platform-${version}.jar, ${src}/${pkg}/javacpp/${version}/javacpp-${version}.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}-linux-x86_64.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}-linux-x86.jar, ${src}/${pkg}/opencv-platform/${opencv-ver}-${version}/opencv-platform-${opencv-ver}-${version}.jar, ${src}/${pkg}/openblas-platform/0.3.7-${version}/openblas-platform-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-linux-x86.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-linux-x86_64.jar
-exportcontents: org.bytedeco
-output: ../javacv-${version}-basic-linux.jar
Bundle-ClassPath: ., javacv-${version}.jar, javacv-platform-${version}.jar, javacpp-${version}.jar, opencv-4.1.2-${version}.jar, opencv-4.1.2-${version}-linux-x86_64.jar, opencv-4.1.2-${version}-linux-x86.jar, opencv-4.1.2-${version}-linux-arm64.jar, opencv-4.1.2-${version}-linux-armhf.jar, opencv-platform-4.1.2-${version}.jar, openblas-platform-0.3.7-${version}.jar, openblas-0.3.7-${version}.jar, openblas-0.3.7-${version}-linux-x86.jar, openblas-0.3.7-${version}-linux-x86_64.jar, openblas-0.3.7-${version}-linux-armhf.jar, openblas-0.3.7-${version}-linux-arm64.jar
Bundle-ClassPath: ., javacv-${version}.jar, javacv-platform-${version}.jar, javacpp-${version}.jar, opencv-${opencv-ver}-${version}.jar, opencv-${opencv-ver}-${version}-linux-x86_64.jar, opencv-${opencv-ver}-${version}-linux-x86.jar, opencv-${opencv-ver}-${version}-linux-arm64.jar, opencv-${opencv-ver}-${version}-linux-armhf.jar, opencv-platform-${opencv-ver}-${version}.jar, openblas-platform-0.3.7-${version}.jar, openblas-0.3.7-${version}.jar, openblas-0.3.7-${version}-linux-x86.jar, openblas-0.3.7-${version}-linux-x86_64.jar, openblas-0.3.7-${version}-linux-armhf.jar, openblas-0.3.7-${version}-linux-arm64.jar
Manifest-Version: 1.0
Created-By: bnd
Built-By: deinhofer
Expand Down
7 changes: 4 additions & 3 deletions ARE/services/ComputerVision/javacv-macosx.bnd
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
version=1.5.2
version=1.5
opencv-ver=4.0.1
src=./javacv
pkg=org/bytedeco
-includeresource: ${src}/${pkg}/javacv/${version}/javacv-${version}.jar, ${src}/${pkg}/javacv-platform/${version}/javacv-platform-${version}.jar, ${src}/${pkg}/javacpp/${version}/javacpp-${version}.jar, ${src}/${pkg}/opencv/4.1.2-${version}/opencv-4.1.2-${version}.jar, ${src}/${pkg}/opencv/4.1.2-${version}/opencv-4.1.2-${version}-macosx-x86_64.jar, ${src}/${pkg}/opencv/4.1.2-${version}/opencv-4.1.2-${version}-macosx-x86.jar, ${src}/${pkg}/opencv-platform/4.1.2-${version}/opencv-platform-4.1.2-${version}.jar, ${src}/${pkg}/openblas-platform/0.3.7-${version}/openblas-platform-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-macosx-x86.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-macosx-x86_64.jar
-includeresource: ${src}/${pkg}/javacv/${version}/javacv-${version}.jar, ${src}/${pkg}/javacv-platform/${version}/javacv-platform-${version}.jar, ${src}/${pkg}/javacpp/${version}/javacpp-${version}.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}-macosx-x86_64.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}-macosx-x86.jar, ${src}/${pkg}/opencv-platform/${opencv-ver}-${version}/opencv-platform-${opencv-ver}-${version}.jar, ${src}/${pkg}/openblas-platform/0.3.7-${version}/openblas-platform-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-macosx-x86.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-macosx-x86_64.jar
-exportcontents: org.bytedeco
-output: ../javacv-${version}-basic-macosx.jar
Bundle-ClassPath: ., javacv-${version}.jar, javacv-platform-${version}.jar, javacpp-${version}.jar, opencv-4.1.2-${version}.jar, opencv-4.1.2-${version}-macosx-x86_64.jar, opencv-4.1.2-${version}-macosx-x86.jar, opencv-platform-4.1.2-${version}.jar, openblas-platform-0.3.7-${version}.jar, openblas-0.3.7-${version}.jar, openblas-0.3.7-${version}-macosx-x86.jar, openblas-0.3.7-${version}-macosx-x86_64.jar
Bundle-ClassPath: ., javacv-${version}.jar, javacv-platform-${version}.jar, javacpp-${version}.jar, opencv-${opencv-ver}-${version}.jar, opencv-${opencv-ver}-${version}-macosx-x86_64.jar, opencv-${opencv-ver}-${version}-macosx-x86.jar, opencv-platform-${opencv-ver}-${version}.jar, openblas-platform-0.3.7-${version}.jar, openblas-0.3.7-${version}.jar, openblas-0.3.7-${version}-macosx-x86.jar, openblas-0.3.7-${version}-macosx-x86_64.jar
Manifest-Version: 1.0
Created-By: bnd
Built-By: deinhofer
Expand Down
18 changes: 18 additions & 0 deletions ARE/services/ComputerVision/javacv-windows-x86_64.bnd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version=1.5
opencv-ver=4.0.1
src=./javacv
pkg=org/bytedeco
-includeresource: ${src}/${pkg}/javacv/${version}/javacv-${version}.jar, ${src}/${pkg}/javacv-platform/${version}/javacv-platform-${version}.jar, ${src}/${pkg}/javacpp/${version}/javacpp-${version}.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}.jar, ${src}/${pkg}/opencv/${opencv-ver}-${version}/opencv-${opencv-ver}-${version}-windows-x86_64.jar, ${src}/${pkg}/opencv-platform/${opencv-ver}-${version}/opencv-platform-${opencv-ver}-${version}.jar, ${src}/${pkg}/openblas-platform/0.3.7-${version}/openblas-platform-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}.jar, ${src}/${pkg}/openblas/0.3.7-${version}/openblas-0.3.7-${version}-windows-x86_64.jar, ${src}/${pkg}/videoinput/0.200-${version}/videoinput-0.200-${version}.jar, ${src}/${pkg}/videoinput-platform/0.200-${version}/videoinput-platform-0.200-${version}.jar, ${src}/${pkg}/videoinput/0.200-${version}/videoinput-0.200-${version}-windows-x86_64.jar
-exportcontents: org.bytedeco
-output: ../javacv-${version}-basic-windows-x86_64.jar
Bundle-ClassPath: ., javacv-${version}.jar, javacv-platform-${version}.jar, javacpp-${version}.jar, opencv-${opencv-ver}-${version}.jar, opencv-${opencv-ver}-${version}-windows-x86_64.jar, opencv-${opencv-ver}-${version}-windows-x86.jar, opencv-platform-${opencv-ver}-${version}.jar, openblas-platform-0.3.7-${version}.jar, openblas-0.3.7-${version}.jar, openblas-0.3.7-${version}-windows-x86.jar, openblas-0.3.7-${version}-windows-x86_64.jar, videoinput-0.200-${version}.jar, videoinput-platform-0.200-${version}.jar, videoinput-0.200-${version}-windows-x86_64.jar, videoinput-0.200-${version}-windows-x86.jar
Manifest-Version: 1.0
Created-By: bnd
Built-By: deinhofer
Bundle-ManifestVersion: 2
Bundle-Name: asterics-services.javacv
Bundle-SymbolicName: org.bytedeco.javacv
Bundle-Version: ${version}
Export-Package: org.bytedeco.java*, org.bytedeco.opencv.opencv_*, org.bytedeco.*.global.*
Import-Package: *;resolution:=optional
DynamicImport-Package:
Loading

0 comments on commit c88a5e1

Please # to comment.