Skip to content

Commit

Permalink
Merge pull request #22 from adambenhamo/RPiBinary
Browse files Browse the repository at this point in the history
#20 Adding binaries for linux/arm
  • Loading branch information
vonnieda committed Jul 18, 2017
2 parents 6ea1c62 + 0aae032 commit a25eb08
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ target
.settings/org.eclipse.jdt.core.prefs
.settings/org.eclipse.m2e.core.prefs
opencv/**
.metadata/
37 changes: 37 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@

### 3.2.0

#### Linux/Arm for Raspberry Pi

* Install packages:
```
sudo apt-get update && sudo apt-get install oracle-java8-jdk cmake ant
sudo apt-get install build-essential cmake pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4 libtiffxx0c2 libtiff-tools libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs libavcodec-dev libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-dev
```
* Change .bashrc to set JAVA_HOME, ANT_HOME and paths:

```
export ANT_HOME=/usr/share/ant/
export PATH=${PATH}:${ANT_HOME}/bin
export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/
export PATH=$PATH:$JAVA_HOME/bin
```

* Download opencv:

```
wget https://github.com/opencv/opencv/archive/3.2.0.zip
mv 3.2.0 opencv.zip
unzip opencv.zip
cd opencv-3.2.0/
```

* Finally build using cmake:
```
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_OPENCL=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_SHARED_LIBS=OFF -D JAVA_INCLUDE_PATH=$JAVA_HOME/include -D JAVA_AWT_LIBRARY=$JAVA_HOME/jre/lib/amd64/libawt.so -D JAVA_JVM_LIBRARY=$JAVA_HOME/jre/lib/arm/server/libjvm.so -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
make install
```

* libopencv_java320.so can now be found in build/libs


#### Linux
* Built on Ubuntu 16.04.1
* Was having problems with HGFS, solved with: http://askubuntu.com/questions/591664/files-missing-in-mnt-hgfs-on-ubuntu-vm
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/nu/pattern/OpenCV.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public class OpenCV {

private final static Logger logger = Logger.getLogger(OpenCV.class.getName());



static enum OS {
OSX("^[Mm]ac OS X$"),
LINUX("^[Ll]inux$"),
Expand Down Expand Up @@ -64,7 +66,8 @@ public static OS getCurrent() {

static enum Arch {
X86_32("i386", "i686", "x86"),
X86_64("amd64", "x86_64");
X86_64("amd64", "x86_64"),
ARMv8("arm");

private final Set<String> patterns;

Expand Down Expand Up @@ -111,7 +114,7 @@ public TemporaryDirectory() {
public Path getPath() {
return path;
}

public TemporaryDirectory deleteOldInstancesOnStart() {
Path tempDirectory = path.getParent();

Expand Down Expand Up @@ -330,6 +333,9 @@ private static Path extractNativeBinary(final OS os, final Arch arch) {
case X86_64:
location = "/nu/pattern/opencv/linux/x86_64/libopencv_java320.so";
break;
case ARMv8:
location = "/nu/pattern/opencv/linux/ARMv8/libopencv_java320.so";
break;
default:
throw new UnsupportedPlatformException(os, arch);
}
Expand Down Expand Up @@ -363,7 +369,7 @@ private static Path extractNativeBinary(final OS os, final Arch arch) {

final InputStream binary = OpenCV.class.getResourceAsStream(location);
final Path destination;

// Do not try to delete the temporary directory on the close if Windows
// because there will be a write lock on the file which will cause an
// AccessDeniedException. Instead, try to delete existing instances of
Expand All @@ -373,7 +379,7 @@ private static Path extractNativeBinary(final OS os, final Arch arch) {
} else {
destination = new TemporaryDirectory().markDeleteOnExit().getPath().resolve("./" + location).normalize();
}

try {
logger.log(Level.FINEST, "Copying native binary to \"{0}\".", destination);
Files.createDirectories(destination.getParent());
Expand All @@ -387,4 +393,3 @@ private static Path extractNativeBinary(final OS os, final Arch arch) {
return destination;
}
}

Binary file not shown.

0 comments on commit a25eb08

Please sign in to comment.