Skip to content

Commit

Permalink
AprilTags 2.0.0 ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Aug 6, 2023
1 parent f760163 commit 20b21ce
Show file tree
Hide file tree
Showing 18 changed files with 107 additions and 75 deletions.
18 changes: 10 additions & 8 deletions RobotCore/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'maven-publish'
}

group 'org.firstinspires.ftc'
Expand All @@ -10,20 +11,21 @@ java {
targetCompatibility = JavaVersion.VERSION_1_8
}

sourceSets {
main {
resources {
// include native libs in the compiled jar
srcDirs "lib/"
}
}
}

task sourcesJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier = "sources"
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
artifact sourcesJar
}
}
}

repositories {
mavenCentral()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.firstinspires.ftc.robotcore.external.navigation;

public class DistanceUnit {
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'com.github.deltacv'
version '1.1.1'
version '2.0.0-A'

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public static void main(String[] args) {

VideoCapture camera = new VideoCapture();

System.out.print("Enter a camera index: ");
int index = 0;//new Scanner(System.in).nextInt();
System.out.print("Enter camera index: ");
int index = new Scanner(System.in).nextInt();

camera.open(index);
if(!camera.isOpened()) {
System.out.println("Could not open camera " + index);
return;
System.err.println("\nCould not open camera " + index);
System.exit(1);
}

Mat image = new Mat();
camera.read(image);
if(image.empty()) {
System.out.println("Could not open camera " + index + " (image was empty)");
return;
System.err.println("\nCould not open camera " + index + " (image was empty)");
System.exit(1);
}

System.out.println("Opened camera " + index);
System.out.println("\nOpened camera " + index);

while(camera.isOpened()) {
camera.read(image);
Expand Down
2 changes: 0 additions & 2 deletions lib/README.md

This file was deleted.

Binary file added lib/apriltag_amd64.dll
Binary file not shown.
Binary file removed lib/libapriltag.dll
Binary file not shown.
Binary file removed lib/libapriltag.dylib
Binary file not shown.
Binary file removed lib/libapriltag.so
Binary file not shown.
Binary file added lib/libapriltag_amd64.dylib
Binary file not shown.
Binary file added lib/libapriltag_amd64.so
Binary file not shown.
Binary file removed lib/libapriltag_arm.dylib
Binary file not shown.
Binary file added lib/libapriltag_arm64.dylib
Binary file not shown.
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
rootProject.name = 'AprilTagDesktop'
include 'RobotCore'

include 'example'
Original file line number Diff line number Diff line change
Expand Up @@ -24,88 +24,67 @@
package io.github.deltacv.apriltag;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

public class NativeLibLoader {
public class AprilTagLibLoader {

private NativeLibLoader() { }

public enum OperatingSystem {
WINDOWS,
LINUX,
MACOS_X86,
MACOS_SILICON,
UNKNOWN
private AprilTagLibLoader() {
}

public static OperatingSystem getOS() {
String osName = System.getProperty("os.name").toLowerCase();
String arch = System.getProperty("os.arch");

if (osName.contains("win")) {
return OperatingSystem.WINDOWS;
} else if (osName.contains("nux")) {
return OperatingSystem.LINUX;
} else if (osName.contains("mac") || osName.contains("darwin")) {
if(arch.equals("aarch64") || arch.contains("arch") || arch.contains("arm")) {
return OperatingSystem.MACOS_SILICON;
} else {
return OperatingSystem.MACOS_X86;
}
}

return OperatingSystem.UNKNOWN;
}

private static boolean hasBeenLoaded = false;
private static boolean hasBeenLoaded = false;

public static void load() {
if(hasBeenLoaded) {
return;
}
OperatingSystem OS = getOS();
if (hasBeenLoaded) {
return;
}

SystemUtil.OperatingSystem OS = SystemUtil.getOS();
String osName = System.getProperty("os.name").toLowerCase();

String prefix = "lib";
String extension = "";

switch(OS) {
String arch = "";

if(SystemUtil.getArch() != SystemUtil.Architecture.UNKNOWN) {
arch = "_" + SystemUtil.getArch().suffix;
}

switch (OS) {
case WINDOWS:
extension = ".dll";
extension = arch + ".dll";
prefix = "";
break;
case LINUX:
extension = ".so";
break;
case MACOS_X86:
extension = ".dylib";
extension = arch + ".so";
break;
case MACOS_SILICON:
extension = "_arm.dylib";
case MACOS:
extension = arch + ".dylib";
break;
case UNKNOWN:
throw new UnsupportedOperationException("The " + osName + " platform couldn't be recognized, therefore the april tag desktop plugin is not supported");
}

String name = "libapriltag" + extension;
String name = prefix + "apriltag" + extension;

String tmpDir = System.getProperty("java.io.tmpdir");
File tempFile = new File(tmpDir + File.separator + name);

try {
Files.copy(NativeLibLoader.class.getResourceAsStream("/" + name), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch(NullPointerException e) {
throw new UnsupportedOperationException("A native lib could not be found for the " + osName + " platform, this probably means that the AprilTag plugin is not supported", e);
} catch(Exception e) {
throw new RuntimeException("Error while extracting native library", e);
Files.copy(AprilTagLibLoader.class.getResourceAsStream("/" + name), tempFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (NullPointerException e) {
throw new UnsupportedOperationException("Library could not be found for the " + osName + " platform, AprilTag plugin is not supported. Tried " + name, e);
} catch (Exception e) {
throw new RuntimeException("Error while extracting library", e);
}

try {
System.load(tempFile.getAbsolutePath());
} catch(Throwable e) {
throw new UnsupportedOperationException("The native library failed to link, which probably means that the AprilTag plugin is not supported in the " + osName + " platform", e);
} catch (Throwable e) {
throw new UnsupportedOperationException("Library failed to link, AprilTag plugin is not supported in the " + osName + " platform", e);
}

hasBeenLoaded = true;
}

Expand Down
49 changes: 49 additions & 0 deletions src/main/java/io/github/deltacv/apriltag/SystemUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package io.github.deltacv.apriltag;

class SystemUtil {

public enum OperatingSystem {
WINDOWS, LINUX, MACOS, UNKNOWN
}

public enum Architecture {
AMD64("amd64"), ARM64("arm64"), UNKNOWN("");

public final String suffix;

Architecture(String suffix) {
this.suffix = suffix;
}
}

private SystemUtil() { }



public static OperatingSystem getOS() {
String osName = System.getProperty("os.name").toLowerCase();

if (osName.contains("win")) {
return OperatingSystem.WINDOWS;
} else if (osName.contains("nux")) {
return OperatingSystem.LINUX;
} else if (osName.contains("mac") || osName.contains("darwin")) {
return OperatingSystem.MACOS;
}

return OperatingSystem.UNKNOWN;
}

public static Architecture getArch() {
String arch = System.getProperty("os.arch").toLowerCase();

if(arch.equals("aarch64") || arch.contains("arch") || arch.contains("arm")) {
return Architecture.ARM64;
} else if(arch.equals("amd64") || arch.contains("64") || arch.contains("x86_64")) {
return Architecture.AMD64;
} else {
return Architecture.UNKNOWN;
}
}

}
4 changes: 2 additions & 2 deletions src/main/java/org/openftc/apriltag/AprilTagDetectorJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package org.openftc.apriltag;

import org.opencv.core.Mat;
import io.github.deltacv.apriltag.NativeLibLoader;
import io.github.deltacv.apriltag.AprilTagLibLoader;

import java.util.ArrayList;

Expand Down Expand Up @@ -102,6 +102,6 @@ public static ArrayList<AprilTagDetection> runAprilTagDetectorSimple(long ptrDet

static
{
NativeLibLoader.load();
AprilTagLibLoader.load();
}
}
4 changes: 2 additions & 2 deletions src/main/java/org/openftc/apriltag/ApriltagDetectionJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
package org.openftc.apriltag;

import org.firstinspires.ftc.robotcore.external.matrices.GeneralMatrixF;
import io.github.deltacv.apriltag.NativeLibLoader;
import io.github.deltacv.apriltag.AprilTagLibLoader;
import org.opencv.core.Point;

import java.util.ArrayList;
Expand Down Expand Up @@ -145,6 +145,6 @@ public static ArrayList<AprilTagDetection> getDetections(long ptrDetections, dou

static
{
NativeLibLoader.load();
AprilTagLibLoader.load();
}
}

0 comments on commit 20b21ce

Please sign in to comment.