Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV 4.5.1 with CUDA support #976

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@
String name();

/**
* A brief summary of the operation. In-depth descriptions, usage guides, and examples
* should be on the wiki, not here.
* A brief summary of the operation. In-depth descriptions, usage guides, and examples should be
* on the wiki, not here.
*
* @return a summary of the operation
*/
String summary();

/**
* The category the operation belongs to. Defaults to
* {@link OperationCategory#MISCELLANEOUS MISCELLANEOUS}.
* The category the operation belongs to. Defaults to {@link OperationCategory#MISCELLANEOUS
* MISCELLANEOUS}.
*
* @return the category to which the operation belongs
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
* Processes elements with the GRIP annotations and generates class list files for them.
*/
@SupportedAnnotationTypes({
"edu.wpi.grip.annotation.*",
"com.thoughtworks.xstream.annotations.XStreamAlias"
"edu.wpi.grip.annotation.*",
"com.thoughtworks.xstream.annotations.XStreamAlias"
})
@SupportedSourceVersion(SourceVersion.RELEASE_8)
@AutoService(Processor.class)
Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ javaSubprojects {
}

tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = "8"
sourceCompatibility = "11"
}

}
Expand Down
8 changes: 4 additions & 4 deletions core/core.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ dependencies {
api(project(":annotation"))
annotationProcessor(project(":annotation"))
api(group = "com.google.code.findbugs", name = "jsr305", version = "3.0.1")
api(group = "org.bytedeco", name = "javacv", version = "1.3")
api(group = "org.bytedeco.javacpp-presets", name = "opencv", version = "3.4.3-1.4.3")
api(group = "org.bytedeco.javacpp-presets", name = "opencv", version = "3.4.3-1.4.3", classifier = if (withCuda) "$os-gpu" else os)
api(group = "org.bytedeco", name = "javacv", version = "1.5.5")
api(group = "org.bytedeco", name = "opencv-platform", version = "4.5.1-1.5.5")
api(group = "org.bytedeco", name = "opencv-platform-gpu", version = "4.5.1-1.5.5")
api(group = "org.bytedeco.javacpp-presets", name = "videoinput", version = "0.200-1.1", classifier = os)
api(group = "org.bytedeco.javacpp-presets", name = "ffmpeg", version = "0.200-1.3", classifier = os)
api(group = "org.bytedeco.javacpp-presets", name = "ffmpeg", version = "4.1-1.4.4", classifier = os)
api(group = "org.python", name = "jython", version = "2.7.0")
api(group = "com.thoughtworks.xstream", name = "xstream", version = "1.4.10")
api(group = "org.apache.commons", name = "commons-lang3", version = "3.5")
Expand Down
Binary file removed core/libs/opencv-3.0.0-1.1-linux-frc.jar
Binary file not shown.
24 changes: 12 additions & 12 deletions core/src/main/java/edu/wpi/grip/core/Cleaner.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
import static java.util.concurrent.TimeUnit.MILLISECONDS;

/**
* Cleans up unused objects by periodically calling {@link System#gc()} to nudge the
* garbage collector to clean up dead native (JavaCV) objects. This is required because JavaCV
* objects only free their native memory when they're garbage collected, so if they accumulate in
* the heap, the app will use about 40x the memory as used heap (i.e. 230MB of used heap results in
* about 9.8GB of used memory for the process). This is because {@code Mats} and anything
* else extending {@link org.bytedeco.javacpp.Pointer} use native memory that greatly exceeds the
* Java objects size on the heap.
* Cleans up unused objects by periodically calling {@link System#gc()} to nudge the garbage
* collector to clean up dead native (JavaCV) objects. This is required because JavaCV objects only
* free their native memory when they're garbage collected, so if they accumulate in the heap, the
* app will use about 40x the memory as used heap (i.e. 230MB of used heap results in about 9.8GB of
* used memory for the process). This is because {@code Mats} and anything else extending {@link
* org.bytedeco.javacpp.Pointer} use native memory that greatly exceeds the Java objects size on the
* heap.
*
* <p>JavaCV has a system property {@code org.bytedeco.javacpp.maxphysicalbytes} that it uses to
* determine when to start deallocating native memory. However, this only results in calls to
* {@code System.gc()} and imposes a hard upper limit on native memory use, limiting large images
* or long pipelines. It's also not very portable: running from source needs it to be passed
* as a JVM argument with gradle, and it can't be adjusted based on the amount of memory on the
* system it's installed on. For us, manually running System.gc() periodically is a better solution.
* determine when to start deallocating native memory. However, this only results in calls to {@code
* System.gc()} and imposes a hard upper limit on native memory use, limiting large images or long
* pipelines. It's also not very portable: running from source needs it to be passed as a JVM
* argument with gradle, and it can't be adjusted based on the amount of memory on the system it's
* installed on. For us, manually running System.gc() periodically is a better solution.
* </p>
*/
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ protected CoreCommandLineHelper(Option... additionalOptions) {
* returning from this method. This will also occur if the help option is specified.
*
* @param args the command line arguments to parse
*
* @return a CommandLine object that can be queried for command line options and their values
*/
@SuppressWarnings({"checkstyle:regexp", "PMD.SystemPrintln"})
Expand Down Expand Up @@ -152,7 +151,6 @@ void exit() {
*
* @param args the parsed command line arguments
* @param project the project to load the file into
*
* @throws IOException if the file couldn't be loaded
*/
public void loadFile(CommandLine args, Project project) throws IOException {
Expand Down
10 changes: 5 additions & 5 deletions core/src/main/java/edu/wpi/grip/core/FileManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
public interface FileManager {

/**
* Saves an array of bytes to a file.
*
* @param image The image to save
* @param fileName The file name to save
*/
* Saves an array of bytes to a file.
*
* @param image The image to save
* @param fileName The file name to save
*/
void saveImage(byte[] image, String fileName);
}
4 changes: 2 additions & 2 deletions core/src/main/java/edu/wpi/grip/core/Loggers.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ private Loggers() {
}

/**
* Sets up loggers to print to stdout and to ~/GRIP/GRIP.log. This should only be called once
* in the application lifecycle, at startup.
* Sets up loggers to print to stdout and to ~/GRIP/GRIP.log. This should only be called once in
* the application lifecycle, at startup.
*/
public static void setupLoggers() {
// Set up the global level logger. This handles IO for all loggers.
Expand Down
70 changes: 35 additions & 35 deletions core/src/main/java/edu/wpi/grip/core/MatWrapper.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
package edu.wpi.grip.core;

import org.bytedeco.javacpp.opencv_core;
import org.bytedeco.javacpp.opencv_core.GpuMat;
import org.bytedeco.javacpp.opencv_core.Mat;
import org.bytedeco.javacpp.opencv_core.Size;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_core.Mat;
import org.bytedeco.opencv.opencv_core.Scalar;
import org.bytedeco.opencv.opencv_core.Size;

import java.util.Objects;
import java.util.function.Function;

import static org.bytedeco.javacpp.opencv_core.CV_16S;
import static org.bytedeco.javacpp.opencv_core.CV_16U;
import static org.bytedeco.javacpp.opencv_core.CV_32F;
import static org.bytedeco.javacpp.opencv_core.CV_32S;
import static org.bytedeco.javacpp.opencv_core.CV_64F;
import static org.bytedeco.javacpp.opencv_core.CV_8S;
import static org.bytedeco.javacpp.opencv_core.CV_8U;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_16S;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_16U;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_1U;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_32F;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_32S;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_64F;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_8S;
import static org.bytedeco.javacpp.opencv_core.IPL_DEPTH_8U;
import static org.bytedeco.opencv.global.opencv_core.CV_16S;
import static org.bytedeco.opencv.global.opencv_core.CV_16U;
import static org.bytedeco.opencv.global.opencv_core.CV_32F;
import static org.bytedeco.opencv.global.opencv_core.CV_32S;
import static org.bytedeco.opencv.global.opencv_core.CV_64F;
import static org.bytedeco.opencv.global.opencv_core.CV_8S;
import static org.bytedeco.opencv.global.opencv_core.CV_8U;
import static org.bytedeco.opencv.global.opencv_core.IPL_DEPTH_16S;
import static org.bytedeco.opencv.global.opencv_core.IPL_DEPTH_16U;
import static org.bytedeco.opencv.global.opencv_core.IPL_DEPTH_1U;
import static org.bytedeco.opencv.global.opencv_core.IPL_DEPTH_32F;
import static org.bytedeco.opencv.global.opencv_core.IPL_DEPTH_32S;
import static org.bytedeco.opencv.global.opencv_core.IPL_DEPTH_64F;
import static org.bytedeco.opencv.global.opencv_core.IPL_DEPTH_8S;
import static org.bytedeco.opencv.global.opencv_core.IPL_DEPTH_8U;

/**
* Wraps a GPU mat and a CPU mat and allows device memory and host memory
* to be used semi-transparently. A wrapper may change between wrapping an image in host memory or
* an image in GPU memory. A wrapper is used to minimize copies between host and device memory,
* which may take longer than the time savings of using a CUDA-accelerated operation.
* Wraps a GPU mat and a CPU mat and allows device memory and host memory to be used
* semi-transparently. A wrapper may change between wrapping an image in host memory or an image in
* GPU memory. A wrapper is used to minimize copies between host and device memory, which may take
* longer than the time savings of using a CUDA-accelerated operation.
*
* <p>Data is lazily copied between host and device memory when needed. Wrappers that
* are only accessed from CPU operations will never have their data stored in device memory.
Expand All @@ -50,8 +50,8 @@ public final class MatWrapper {
private boolean isCpu = true;

/**
* Flags whether or not the wrapped value has been modified since the most recent read. This
* is used so that the value is only copied between host and device when it's needed.
* Flags whether or not the wrapped value has been modified since the most recent read. This is
* used so that the value is only copied between host and device when it's needed.
*/
private boolean changed = false;

Expand Down Expand Up @@ -107,8 +107,8 @@ public boolean isGpu() {

/**
* Gets the raw CPU mat. This should only be used when this mat is used as a {@code dst} parameter
* to an OpenCV function. If you want to get the current value as a mat in host memory, use
* {@link #getCpu()}.
* to an OpenCV function. If you want to get the current value as a mat in host memory, use {@link
* #getCpu()}.
*/
public Mat rawCpu() {
// Assume the mat is about to be modified as a `dst` parameter to an OpenCV function
Expand All @@ -120,8 +120,8 @@ public Mat rawCpu() {

/**
* Gets the raw GPU mat. This should only be used when this mat is used as a {@code dst} parameter
* to an OpenCV function. If you want to get the current value as a mat in GPU memory, use
* {@link #getGpu()}.
* to an OpenCV function. If you want to get the current value as a mat in GPU memory, use {@link
* #getGpu()}.
*/
public GpuMat rawGpu() {
// Assume the mat is about to be modified as a `dst` parameter to an OpenCV function
Expand All @@ -147,9 +147,9 @@ public Mat getCpu() {

/**
* Gets this mat as a mat in GPU memory. If this is {@link #isCpu() backed by host memory}, the
* host memory will be copied into the GPU mat before being returned. This copy only happens
* after {@link #set(Mat) set(Mat)} is called, and only once between successive calls;
* invocations of this method after the first copy will not perform another.
* host memory will be copied into the GPU mat before being returned. This copy only happens after
* {@link #set(Mat) set(Mat)} is called, and only once between successive calls; invocations of
* this method after the first copy will not perform another.
*/
public GpuMat getGpu() {
if (changed && isCpu) {
Expand Down Expand Up @@ -182,8 +182,8 @@ public void set(GpuMat mat) {
}

/**
* Sets this as being backed by the given wrapper. This wrapper will be functionally equivalent
* to the one given.
* Sets this as being backed by the given wrapper. This wrapper will be functionally equivalent to
* the one given.
*/
public void set(MatWrapper wrapper) {
if (wrapper.isCpu()) {
Expand Down Expand Up @@ -370,7 +370,7 @@ public void create(int rows, int cols, int type) {
*
* @param value Assigned scalar converted to the actual array type.
*/
public MatWrapper put(opencv_core.Scalar value) {
public MatWrapper put(Scalar value) {
if (isCpu()) {
cpuMat.put(value);
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/edu/wpi/grip/core/Operation.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ public interface Operation {
* by {@link Step#setRemoved()} to ensure correct synchronization.
*/
default void cleanUp() {
/* no-op */
/* no-op */
}
}
15 changes: 7 additions & 8 deletions core/src/main/java/edu/wpi/grip/core/OperationDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class OperationDescription {
private final ImmutableSet<String> aliases;

/**
* Creates an operation description from a {@link Description @Description} annotation on
* an operation subclass.
* Creates an operation description from a {@link Description @Description} annotation on an
* operation subclass.
*/
public static OperationDescription from(Description description) {
checkNotNull(description, "The description annotation cannot be null");
Expand All @@ -46,8 +46,8 @@ public static OperationDescription from(Description description) {
}

/**
* Creates an operation description from a {@link Description @Description} annotation on
* an operation subclass. The class is assumed to have the annotation; be careful when using this
* Creates an operation description from a {@link Description @Description} annotation on an
* operation subclass. The class is assumed to have the annotation; be careful when using this
* method.
*
* @param clazz the class to generate a description for
Expand All @@ -73,10 +73,9 @@ private OperationDescription(String name,

/**
* Creates a new {@link Builder} instance to create a new {@code OperationDescription} object. The
* created descriptor has a default category of
* {@link OperationCategory#MISCELLANEOUS MISCELLANEOUS} and no icon; use the
* {@link Builder#category(OperationCategory) .category()} and {@link Builder#icon(Icon) .icon()}
* methods to override the default values.
* created descriptor has a default category of {@link OperationCategory#MISCELLANEOUS
* MISCELLANEOUS} and no icon; use the {@link Builder#category(OperationCategory) .category()} and
* {@link Builder#icon(Icon) .icon()} methods to override the default values.
*/
public static Builder builder() {
return new Builder()
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/edu/wpi/grip/core/StepIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface StepIndexer extends Comparator<Step> {
int indexOf(Step step);

/**
* Compares two steps based on their indexes. <i>This is not consistent with {@code equals()}</i>.
* Compares two steps based on their indexes. <i>This is not consistent with {@code
* equals()}</i>.
*
* @param o1 the first step to compare
* @param o2 the second step to compare
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/edu/wpi/grip/core/cuda/CudaVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public CudaVerifier(AccelerationMode accelerationMode,
}

/**
* Verifies the presence of a CUDA runtime, if required by the GRIP runtime, and exits the
* app if no compatible CUDA runtime is available.
* Verifies the presence of a CUDA runtime, if required by the GRIP runtime, and exits the app if
* no compatible CUDA runtime is available.
*/
public void verifyCuda() {
if (!verify()) {
Expand All @@ -51,7 +51,7 @@ public void verifyCuda() {
* GRIP is not using CUDA acceleration, this will always return {@code true}.
*
* @return false if GRIP is using CUDA acceleration but no compatible CUDA runtime is available,
* true otherwise
* true otherwise
*/
public boolean verify() {
if (accelerationMode.isUsingCuda()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package edu.wpi.grip.core.cuda;

import org.bytedeco.javacpp.Loader;
import org.bytedeco.javacpp.opencv_cudaarithm;
import org.bytedeco.opencv.global.opencv_cudaarithm;

/**
* Checks if CUDA is available by attempting to load one of the OpenCV CUDA class' JNI. If the JNI
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
/**
* An event that can potentially dirty the save file.
*
* <p>These events ensure that anything that changes causes the save file to be flagged as dirty and
* <p>These events ensure that anything that changes causes the save file to be flagged as dirty
* and
* in need of being saved for the project to be deemed "clean" again.
*/
public interface DirtiesSaveEvent {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public boolean isRegarding(Socket socket) {
}

/**
* This event will only dirty the save if the InputSocket does not have connections.
* Thus the value can only have been changed by a UI component.
* If the socket has connections then the value change is triggered by another socket's change.
* This event will only dirty the save if the InputSocket does not have connections. Thus the
* value can only have been changed by a UI component. If the socket has connections then the
* value change is triggered by another socket's change.
*
* @return True if this should dirty the save.
*/
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/edu/wpi/grip/core/events/WarningEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class WarningEvent implements LoggableEvent {
/**
* Creates a new warning event.
*
* @param header the header or title of the warning (e.g. "Cannot generate code").
* This should be short and descriptive.
* @param body the body of the warning.
* This should go into detail about what the user did wrong.
* @param header the header or title of the warning (e.g. "Cannot generate code"). This should be
* short and descriptive.
* @param body the body of the warning. This should go into detail about what the user did
* wrong.
*/
public WarningEvent(String header, String body) {
checkNotNull(header, "Header text cannot be null");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

package edu.wpi.grip.core.exception;

/**
* An exception thrown when something goes wrong with an internal GRIP
* operation. This class is {@code abstract} to encourage making subclasses
* for specific cases.
* An exception thrown when something goes wrong with an internal GRIP operation. This class is
* {@code abstract} to encourage making subclasses for specific cases.
*/
public abstract class GripException extends RuntimeException {

Expand Down
Loading