Skip to content

Commit

Permalink
Removed dependency to EOCV-Sim common and added jitpack.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
serivesmejia committed Jan 2, 2022
1 parent f53394a commit ee571e4
Show file tree
Hide file tree
Showing 19 changed files with 824 additions and 25 deletions.
13 changes: 1 addition & 12 deletions backend-openimaj/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,7 @@ apply from: '../publish.gradle'
dependencies {
compileOnly project(':core')

try {
implementation('com.github.deltacv.EOCV-Sim:Common:3.4.0') {
exclude group: 'org.openpnp', module: 'io.github.deltacv.steve.opencv'
}
} catch(Exception ignored) {
implementation('com.github.deltacv:Common:3.4.0') { // fallback for mavenLocal artifact
exclude group: 'org.openpnp', module: 'io.github.deltacv.steve.opencv'
}
}

implementation 'org.slf4j:slf4j-api:1.7.32'
implementation 'org.slf4j:slf4j-log4j12:1.7.32'
// implementation 'org.slf4j:slf4j-log4j12:1.7.32'
implementation('org.openimaj:core-video-capture:1.3.10') {
//exclude group: 'org.openimaj', module: 'core'
exclude group: 'org.openimaj', module: 'core-audio'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ package io.github.deltacv.steve.openimaj

import io.github.deltacv.steve.WebcamBase
import io.github.deltacv.steve.WebcamRotation
import com.github.serivesmejia.eocvsim.util.Log
import com.github.serivesmejia.eocvsim.util.fps.FpsLimiter
import io.github.deltacv.steve.util.FpsLimiter
import io.github.deltacv.steve.commonResolutions
import org.firstinspires.ftc.robotcore.internal.collections.EvictingBlockingQueue
import io.github.deltacv.steve.util.EvictingBlockingQueue
import org.opencv.core.CvType
import org.opencv.core.Mat
import org.opencv.core.Size
import org.openftc.easyopencv.MatRecycler
import io.github.deltacv.steve.util.MatRecycler
import org.openimaj.video.capture.Device
import org.openimaj.video.capture.VideoCapture
import org.slf4j.LoggerFactory
import java.util.concurrent.ArrayBlockingQueue

class OpenIMAJWebcam @JvmOverloads constructor(
Expand All @@ -45,10 +45,6 @@ class OpenIMAJWebcam @JvmOverloads constructor(
override val index: Int = -1
) : WebcamBase(rotation) {

companion object {
const val TAG = "OpenIMAJWebcam"
}

override val isOpen get() = videoCapture != null && videoCapture!!.hasNextFrame()

override var resolution = resolution
Expand All @@ -58,7 +54,7 @@ class OpenIMAJWebcam @JvmOverloads constructor(
}

override val supportedResolutions get() = commonResolutions

override val name: String get() = device.nameStr

override var fps = fps
Expand All @@ -67,6 +63,8 @@ class OpenIMAJWebcam @JvmOverloads constructor(
field = value
}

val logger = LoggerFactory.getLogger(this::class.java)

var videoCapture: VideoCapture? = null
private set
private var grabber: ReflectOpenIMAJGrabber? = null
Expand Down Expand Up @@ -111,7 +109,7 @@ class OpenIMAJWebcam @JvmOverloads constructor(

streamThread!!.start()
} catch(e: Exception) {
Log.error(TAG, "Error while opening camera", e)
logger.error("Error while opening camera", e)

videoCapture = null
streamThread?.interrupt()
Expand All @@ -120,7 +118,7 @@ class OpenIMAJWebcam @JvmOverloads constructor(

override fun internalRead(mat: Mat) {
if(!streamThread!!.isAlive) {
Log.warn(TAG, "The WebcamStream thread mysteriously disappeared, probably due to an exception. Closing webcam \"$name\".")
logger.warn("The WebcamStream thread mysteriously disappeared, probably due to an exception. Closing webcam \"$name\".")
close()
return
}
Expand Down Expand Up @@ -166,6 +164,8 @@ class OpenIMAJWebcam @JvmOverloads constructor(
private val recycler = MatRecycler(matQueueSize + 2, height, width, CvType.CV_8UC3)
private val pixels = ByteArray(width * height * 3)

val logger = LoggerFactory.getLogger(this::class.java)

override fun run() {
queue.setEvictAction {
it.returnMat()
Expand Down Expand Up @@ -196,7 +196,7 @@ class OpenIMAJWebcam @JvmOverloads constructor(
// copied from the original source code of VideoCapture.
// no idea what the < -1 error codes stand for.
if (err == -1) {
Log.warn(TAG, "Timed out waiting for next frame of \"${webcam.name}\"")
logger.warn("Timed out waiting for next frame of \"${webcam.name}\"")
return@synchronized
} else if (err < -1) {
throw RuntimeException("Error occurred getting next frame (code: $err)")
Expand All @@ -215,7 +215,7 @@ class OpenIMAJWebcam @JvmOverloads constructor(
// It *shouldn't* happen since we don't allow the resolution to be changed in the middle of
// a running camera stream, but we implement this check regardless to see if it fixes the issue
if(resolution.width.toInt() != width || resolution.height.toInt() != height) {
Log.warn(TAG, "Grabber currently has a resolution different than the initial one ($resolution vs initial Size($width, $height))")
logger.warn("Grabber currently has a resolution different than the initial one ($resolution vs initial Size($width, $height))")
return@synchronized // continue;
}

Expand Down
1 change: 1 addition & 0 deletions build.common.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repositories {
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib"
compileOnly "org.openpnp:opencv:$opencv_version"
implementation 'org.slf4j:slf4j-api:1.7.32'
}


Expand Down
1 change: 1 addition & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'org.jetbrains.kotlin.jvm'
id 'java'
id 'maven-publish'
}

Expand Down
118 changes: 118 additions & 0 deletions core/src/main/java/io/github/deltacv/steve/util/Assert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
Copyright (c) 2016 Robert Atkinson
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted (subject to the limitations in the disclaimer below) provided that
the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
Neither the name of Robert Atkinson nor the names of his contributors may be used to
endorse or promote products derived from this software without specific prior
written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package io.github.deltacv.steve.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* {@link Assert} is a utility class for assertions that generates an exception which
* gets written to the log, but then continues on with the application. The write to the
* log gives us notices that something is amiss that needs addressing, but continuing with
* the app might, for example, allow a robot to continue on in a match rather than aborting
* in the middle, depending on the nature of the failure.
*/
public class Assert {

static Logger logger = LoggerFactory.getLogger(Assert.class);

public static void assertTrue(boolean value) {
if (!value) {
assertFailed();
}
}

public static void assertFalse(boolean value) {
if (value) {
assertFailed();
}
}

public static void assertNull(Object value) {
if (value != null) {
assertFailed();
}
}

public static void assertNotNull(Object value) {
if (value == null) {
assertFailed();
}
}

public static void assertEquals(int expected, int actual) {
if (expected != actual) {
assertFailed();
}
}

//----------------------------------------------------------------------------------------------

public static void assertTrue(boolean value, String format, Object... args) {
if (!value) {
assertFailed(format, args);
}
}

public static void assertFalse(boolean value, String format, Object... args) {
if (value) {
assertFailed(format, args);
}
}

public static void assertNull(Object value, String format, Object... args) {
if (value != null) {
assertFailed(format, args);
}
}

public static void assertNotNull(Object value, String format, Object... args) {
if (value == null) {
assertFailed(format, args);
}
}

//----------------------------------------------------------------------------------------------

public static void assertFailed() {
try {
throw new RuntimeException("assertion failed");
} catch (Exception e) {
logger.error("assertion failed", e);
}
}

public static void assertFailed(String format, Object[] args) {
String message = String.format(format, args);
String banner = "assertion failed: " + message;
try {
throw new RuntimeException(banner);
} catch (Exception e) {
logger.error(banner, e);
}
}
}
Loading

0 comments on commit ee571e4

Please sign in to comment.