commit a82d01dac34e58bd5439c7b2d1ffef5ea50a87c1 Author: rdkartono Date: Thu Apr 24 11:28:01 2025 +0700 First commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..92195a7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..c1dd12f Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..40ca015 --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar \ No newline at end of file diff --git a/Libs/archive.dll b/Libs/archive.dll new file mode 100644 index 0000000..ebb9ff4 Binary files /dev/null and b/Libs/archive.dll differ diff --git a/Libs/avif.dll b/Libs/avif.dll new file mode 100644 index 0000000..a9ed759 Binary files /dev/null and b/Libs/avif.dll differ diff --git a/Libs/bz2.dll b/Libs/bz2.dll new file mode 100644 index 0000000..3abd58d Binary files /dev/null and b/Libs/bz2.dll differ diff --git a/Libs/cublas64_12.dll b/Libs/cublas64_12.dll new file mode 100644 index 0000000..81a05a6 Binary files /dev/null and b/Libs/cublas64_12.dll differ diff --git a/Libs/cublasLt64_12.dll b/Libs/cublasLt64_12.dll new file mode 100644 index 0000000..7f81535 Binary files /dev/null and b/Libs/cublasLt64_12.dll differ diff --git a/Libs/cudnn64_9.dll b/Libs/cudnn64_9.dll new file mode 100644 index 0000000..7fe172c Binary files /dev/null and b/Libs/cudnn64_9.dll differ diff --git a/Libs/cudnn_adv64_9.dll b/Libs/cudnn_adv64_9.dll new file mode 100644 index 0000000..3284de6 Binary files /dev/null and b/Libs/cudnn_adv64_9.dll differ diff --git a/Libs/cudnn_cnn64_9.dll b/Libs/cudnn_cnn64_9.dll new file mode 100644 index 0000000..d85ef17 Binary files /dev/null and b/Libs/cudnn_cnn64_9.dll differ diff --git a/Libs/cudnn_engines_precompiled64_9.dll b/Libs/cudnn_engines_precompiled64_9.dll new file mode 100644 index 0000000..9b531ee Binary files /dev/null and b/Libs/cudnn_engines_precompiled64_9.dll differ diff --git a/Libs/cudnn_engines_runtime_compiled64_9.dll b/Libs/cudnn_engines_runtime_compiled64_9.dll new file mode 100644 index 0000000..3f99f5f Binary files /dev/null and b/Libs/cudnn_engines_runtime_compiled64_9.dll differ diff --git a/Libs/cudnn_graph64_9.dll b/Libs/cudnn_graph64_9.dll new file mode 100644 index 0000000..42b0b3b Binary files /dev/null and b/Libs/cudnn_graph64_9.dll differ diff --git a/Libs/cudnn_heuristic64_9.dll b/Libs/cudnn_heuristic64_9.dll new file mode 100644 index 0000000..abbcadf Binary files /dev/null and b/Libs/cudnn_heuristic64_9.dll differ diff --git a/Libs/cudnn_ops64_9.dll b/Libs/cudnn_ops64_9.dll new file mode 100644 index 0000000..b7d7159 Binary files /dev/null and b/Libs/cudnn_ops64_9.dll differ diff --git a/Libs/ffi-7.dll b/Libs/ffi-7.dll new file mode 100644 index 0000000..3610655 Binary files /dev/null and b/Libs/ffi-7.dll differ diff --git a/Libs/gif.dll b/Libs/gif.dll new file mode 100644 index 0000000..708d968 Binary files /dev/null and b/Libs/gif.dll differ diff --git a/Libs/glib-2.0-0.dll b/Libs/glib-2.0-0.dll new file mode 100644 index 0000000..b1024f9 Binary files /dev/null and b/Libs/glib-2.0-0.dll differ diff --git a/Libs/gmodule-2.0-0.dll b/Libs/gmodule-2.0-0.dll new file mode 100644 index 0000000..6c26599 Binary files /dev/null and b/Libs/gmodule-2.0-0.dll differ diff --git a/Libs/gobject-2.0-0.dll b/Libs/gobject-2.0-0.dll new file mode 100644 index 0000000..d8f309c Binary files /dev/null and b/Libs/gobject-2.0-0.dll differ diff --git a/Libs/gstapp-1.0-0.dll b/Libs/gstapp-1.0-0.dll new file mode 100644 index 0000000..0c3b330 Binary files /dev/null and b/Libs/gstapp-1.0-0.dll differ diff --git a/Libs/gstaudio-1.0-0.dll b/Libs/gstaudio-1.0-0.dll new file mode 100644 index 0000000..f57c8d3 Binary files /dev/null and b/Libs/gstaudio-1.0-0.dll differ diff --git a/Libs/gstbase-1.0-0.dll b/Libs/gstbase-1.0-0.dll new file mode 100644 index 0000000..604cdc8 Binary files /dev/null and b/Libs/gstbase-1.0-0.dll differ diff --git a/Libs/gstpbutils-1.0-0.dll b/Libs/gstpbutils-1.0-0.dll new file mode 100644 index 0000000..bd6f540 Binary files /dev/null and b/Libs/gstpbutils-1.0-0.dll differ diff --git a/Libs/gstreamer-1.0-0.dll b/Libs/gstreamer-1.0-0.dll new file mode 100644 index 0000000..c56b99c Binary files /dev/null and b/Libs/gstreamer-1.0-0.dll differ diff --git a/Libs/gstriff-1.0-0.dll b/Libs/gstriff-1.0-0.dll new file mode 100644 index 0000000..45bacb5 Binary files /dev/null and b/Libs/gstriff-1.0-0.dll differ diff --git a/Libs/gsttag-1.0-0.dll b/Libs/gsttag-1.0-0.dll new file mode 100644 index 0000000..7bd2e67 Binary files /dev/null and b/Libs/gsttag-1.0-0.dll differ diff --git a/Libs/gstvideo-1.0-0.dll b/Libs/gstvideo-1.0-0.dll new file mode 100644 index 0000000..fafbb27 Binary files /dev/null and b/Libs/gstvideo-1.0-0.dll differ diff --git a/Libs/intl-8.dll b/Libs/intl-8.dll new file mode 100644 index 0000000..bb07349 Binary files /dev/null and b/Libs/intl-8.dll differ diff --git a/Libs/jpeg62.dll b/Libs/jpeg62.dll new file mode 100644 index 0000000..ebafecb Binary files /dev/null and b/Libs/jpeg62.dll differ diff --git a/Libs/leptonica-1.85.0.dll b/Libs/leptonica-1.85.0.dll new file mode 100644 index 0000000..73fdbf1 Binary files /dev/null and b/Libs/leptonica-1.85.0.dll differ diff --git a/Libs/libcrypto-3-x64.dll b/Libs/libcrypto-3-x64.dll new file mode 100644 index 0000000..2f783b8 Binary files /dev/null and b/Libs/libcrypto-3-x64.dll differ diff --git a/Libs/libcurl.dll b/Libs/libcurl.dll new file mode 100644 index 0000000..aec577a Binary files /dev/null and b/Libs/libcurl.dll differ diff --git a/Libs/liblzma.dll b/Libs/liblzma.dll new file mode 100644 index 0000000..51cf80a Binary files /dev/null and b/Libs/liblzma.dll differ diff --git a/Libs/libopenblas.dll b/Libs/libopenblas.dll new file mode 100644 index 0000000..38112e1 Binary files /dev/null and b/Libs/libopenblas.dll differ diff --git a/Libs/libpng16.dll b/Libs/libpng16.dll new file mode 100644 index 0000000..e90f622 Binary files /dev/null and b/Libs/libpng16.dll differ diff --git a/Libs/libsharpyuv.dll b/Libs/libsharpyuv.dll new file mode 100644 index 0000000..47ec4fb Binary files /dev/null and b/Libs/libsharpyuv.dll differ diff --git a/Libs/libwebp.dll b/Libs/libwebp.dll new file mode 100644 index 0000000..20ec6c8 Binary files /dev/null and b/Libs/libwebp.dll differ diff --git a/Libs/libwebpmux.dll b/Libs/libwebpmux.dll new file mode 100644 index 0000000..c2928c7 Binary files /dev/null and b/Libs/libwebpmux.dll differ diff --git a/Libs/libyuv.dll b/Libs/libyuv.dll new file mode 100644 index 0000000..fe9cde0 Binary files /dev/null and b/Libs/libyuv.dll differ diff --git a/Libs/lz4.dll b/Libs/lz4.dll new file mode 100644 index 0000000..90d9a35 Binary files /dev/null and b/Libs/lz4.dll differ diff --git a/Libs/nppc64_12.dll b/Libs/nppc64_12.dll new file mode 100644 index 0000000..cfd3e00 Binary files /dev/null and b/Libs/nppc64_12.dll differ diff --git a/Libs/nppial64_12.dll b/Libs/nppial64_12.dll new file mode 100644 index 0000000..99bba5e Binary files /dev/null and b/Libs/nppial64_12.dll differ diff --git a/Libs/nppist64_12.dll b/Libs/nppist64_12.dll new file mode 100644 index 0000000..44615ae Binary files /dev/null and b/Libs/nppist64_12.dll differ diff --git a/Libs/opencv_java4100.dll b/Libs/opencv_java4100.dll new file mode 100644 index 0000000..ffc2a0c Binary files /dev/null and b/Libs/opencv_java4100.dll differ diff --git a/Libs/opencv_videoio_ffmpeg4100_64.dll b/Libs/opencv_videoio_ffmpeg4100_64.dll new file mode 100644 index 0000000..b880c1c Binary files /dev/null and b/Libs/opencv_videoio_ffmpeg4100_64.dll differ diff --git a/Libs/openjp2.dll b/Libs/openjp2.dll new file mode 100644 index 0000000..13763dd Binary files /dev/null and b/Libs/openjp2.dll differ diff --git a/Libs/openvino.dll b/Libs/openvino.dll new file mode 100644 index 0000000..4a6b761 Binary files /dev/null and b/Libs/openvino.dll differ diff --git a/Libs/orc-0.4-0.dll b/Libs/orc-0.4-0.dll new file mode 100644 index 0000000..bcca30e Binary files /dev/null and b/Libs/orc-0.4-0.dll differ diff --git a/Libs/pcre2-8-0.dll b/Libs/pcre2-8-0.dll new file mode 100644 index 0000000..d539463 Binary files /dev/null and b/Libs/pcre2-8-0.dll differ diff --git a/Libs/tbb12.dll b/Libs/tbb12.dll new file mode 100644 index 0000000..a20a1d1 Binary files /dev/null and b/Libs/tbb12.dll differ diff --git a/Libs/tesseract55.dll b/Libs/tesseract55.dll new file mode 100644 index 0000000..ff4516a Binary files /dev/null and b/Libs/tesseract55.dll differ diff --git a/Libs/tiff.dll b/Libs/tiff.dll new file mode 100644 index 0000000..db71c35 Binary files /dev/null and b/Libs/tiff.dll differ diff --git a/Libs/z-1.dll b/Libs/z-1.dll new file mode 100644 index 0000000..7e257a1 Binary files /dev/null and b/Libs/z-1.dll differ diff --git a/Libs/zlib1.dll b/Libs/zlib1.dll new file mode 100644 index 0000000..fc2c81e Binary files /dev/null and b/Libs/zlib1.dll differ diff --git a/Libs/zstd.dll b/Libs/zstd.dll new file mode 100644 index 0000000..dc83d81 Binary files /dev/null and b/Libs/zstd.dll differ diff --git a/Yolo/yolov8s-face-lindevs.onnx b/Yolo/yolov8s-face-lindevs.onnx new file mode 100644 index 0000000..039cabd Binary files /dev/null and b/Yolo/yolov8s-face-lindevs.onnx differ diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..8a8fb22 --- /dev/null +++ b/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..1d8ab01 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..5818f27 --- /dev/null +++ b/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + + id.co.gtc + CudaTester + 1.0-SNAPSHOT + CudaTester + + + UTF-8 + 5.10.2 + + + + + org.openjfx + javafx-controls + 21 + + + org.openjfx + javafx-fxml + 21 + + + + org.junit.jupiter + junit-jupiter-api + ${junit.version} + test + + + org.junit.jupiter + junit-jupiter-engine + ${junit.version} + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.13.0 + + 21 + 21 + + + + org.openjfx + javafx-maven-plugin + 0.0.8 + + + + default-cli + + id.co.gtc.cudatester/id.co.gtc.cudatester.HelloApplication + app + app + app + true + true + true + + + + + + + \ No newline at end of file diff --git a/src/main/java/id/co/gtc/cudatester/Camera.java b/src/main/java/id/co/gtc/cudatester/Camera.java new file mode 100644 index 0000000..8b4d1ec --- /dev/null +++ b/src/main/java/id/co/gtc/cudatester/Camera.java @@ -0,0 +1,167 @@ +package id.co.gtc.cudatester; + +import org.bytedeco.opencv.opencv_core.Mat; +import org.bytedeco.opencv.opencv_videoio.VideoCapture; +import org.opencv.core.Core; +import org.opencv.videoio.Videoio; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; +import static org.bytedeco.opencv.global.opencv_core.*; + +public class Camera { + + public static boolean LibraryLoaded = false; + public static int cameraWidth = -1; + public static int cameraHeight = -1; + public static int cameraFps = -1; + private static final int maxWidth = 3840; + private static final int maxHeight = 2160; +// private static final int maxWidth = 1920; +// private static final int maxHeight = 1080; + private final AtomicInteger frameCount = new AtomicInteger(0); + Thread capturethread = null; + Thread fpsthread = null; + + static{ + System.out.println("Current directory: "+Libraries.getCurrentDirectory()); + Libraries.ExtractAll(Libraries.getCurrentDirectory(),(new_extract)-> System.out.println("Extracting library "+new_extract), (already_exists)-> System.out.println("Library already exists: "+already_exists), (failed)-> System.out.println("Failed to extract library: "+failed)); + try{ + System.loadLibrary(Core.NATIVE_LIBRARY_NAME); + if ("4.10.0".equals(Core.VERSION)){ + LibraryLoaded = true; + } + } catch (Exception e){ + System.out.println("Failed to load library: "+e.getMessage()); + } + } + + VideoCapture _vcap; + AtomicBoolean Capturing = new AtomicBoolean(false); + public Camera(){ + //System.out.println("Build information : "+Core.getBuildInformation()); + int ii = getCudaEnabledDeviceCount(); + if (ii>0){ + System.out.println("CUDA enabled device count: "+ii); + // printCudaDeviceInfo(ii); + } else { + System.out.println("No CUDA enabled device found"); + } + } + + @SuppressWarnings({"BusyWait"}) + public void StartCamera(int cameraIndex, Consumer Opened, Consumer Status, Consumer NewFrame){ + Capturing.set(false); + cameraWidth = -1; + cameraHeight = -1; + if (LibraryLoaded){ + _vcap = new VideoCapture(cameraIndex, Videoio.CAP_DSHOW); + + if (_vcap.isOpened()){ + System.out.println("Camera "+cameraIndex+" opened, Backend: "+_vcap.getBackendName().getString()); + capturethread = new Thread(()->{ + if (Opened != null) Opened.accept(true); + Capturing.set(true); + int lastFPS = -1; + while(Capturing.get()){ + if (_vcap.grab()){ + Mat frame = new Mat(); + if (_vcap.retrieve(frame)){ + if (!frame.empty()){ + + if (frame.cols()!= cameraWidth || frame.rows()!= cameraHeight || lastFPS!=cameraFps){ + cameraWidth = frame.cols(); + cameraHeight = frame.rows(); + lastFPS = cameraFps; + if (Status != null) Status.accept(new int[]{cameraWidth, cameraHeight, lastFPS}); + if (cameraHeight!=maxHeight || cameraWidth!=maxWidth){ + System.out.println("Changing camera resolution to "+maxWidth+"x"+maxHeight); + _vcap.set(Videoio.CAP_PROP_FRAME_WIDTH, maxWidth); + _vcap.set(Videoio.CAP_PROP_FRAME_HEIGHT, maxHeight); + continue; + } + } + if (NewFrame!=null) NewFrame.accept(frame); + frameCount.incrementAndGet(); + } + } + frame.release(); + } + try { + Thread.sleep(1); + } catch (InterruptedException e) { + Capturing.set(false); + break; + } + + } + _vcap.release(); + System.out.println("Camera "+cameraIndex+" released"); + if (Opened != null) Opened.accept(false); + }); + capturethread.setName("Camera Capture "+cameraIndex); + capturethread.setDaemon(true); + capturethread.start(); + + fpsthread = new Thread(()->{ + System.out.println("Camera "+cameraIndex+" start counting FPS"); + while (Capturing.get()){ + try { + Thread.sleep(1000); + cameraFps = frameCount.getAndSet(0); + } catch (InterruptedException e) { + Capturing.set(false); + } + } + System.out.println("Camera "+cameraIndex+" stop counting FPS"); + }); + fpsthread.setName("Camera FPS "+cameraIndex); + fpsthread.setDaemon(true); + fpsthread.start(); + } else { + System.out.println("Camera "+cameraIndex+" not opened"); + if (Opened != null) Opened.accept(false); + } + } else { + System.out.println("Library not loaded"); + if (Opened != null) Opened.accept(false); + } + } + + public void StopCamera(){ + Capturing.set(false); + if (fpsthread!=null) { + fpsthread.interrupt(); + } + if (capturethread!=null) { + capturethread.interrupt(); + } + } + + @SuppressWarnings({"UnusedReturnValue", "resource"}) + public static String[] EnumerateCameras(){ + List cameras = new ArrayList<>(); + if (LibraryLoaded){ + int i = 0; + while (i<25){ + try{ + VideoCapture vcap = new VideoCapture(i, Videoio.CAP_DSHOW); + if (vcap.isOpened()){ + System.out.println("Camera "+i+" found, Backend: "+vcap.getBackendName().getString()); + cameras.add("camera"+i); + vcap.release(); + i++; + } else throw new Exception("Camera "+i+" not opened"); + } catch(Exception e){ + //System.out.println("Camera "+i+" not found"); + break; + } + } + } + + return cameras.toArray(new String[0]); + } +} diff --git a/src/main/java/id/co/gtc/cudatester/HelloApplication.java b/src/main/java/id/co/gtc/cudatester/HelloApplication.java new file mode 100644 index 0000000..e4bcd9b --- /dev/null +++ b/src/main/java/id/co/gtc/cudatester/HelloApplication.java @@ -0,0 +1,26 @@ +package id.co.gtc.cudatester; + +import javafx.application.Application; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.stage.Stage; + +import java.io.IOException; + +public class HelloApplication extends Application { + @Override + public void start(Stage stage) throws IOException { + FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml")); + + Scene scene = new Scene(fxmlLoader.load(), 1280, 800); + + stage.setTitle("Cuda Tester v1.0"); + stage.setScene(scene); + stage.show(); + + } + + public static void main(String[] args) { + launch(); + } +} \ No newline at end of file diff --git a/src/main/java/id/co/gtc/cudatester/HelloController.java b/src/main/java/id/co/gtc/cudatester/HelloController.java new file mode 100644 index 0000000..1c69a64 --- /dev/null +++ b/src/main/java/id/co/gtc/cudatester/HelloController.java @@ -0,0 +1,123 @@ +package id.co.gtc.cudatester; + +import javafx.application.Platform; +import javafx.event.ActionEvent; +import javafx.fxml.FXML; +import javafx.scene.control.Button; +import javafx.scene.control.Label; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.BorderPane; +import org.bytedeco.opencv.opencv_core.Mat; + +import java.util.concurrent.atomic.AtomicBoolean; + + +public class HelloController { + + @FXML + private BorderPane root; + + @FXML + private Button StartStopCamera; + + @FXML + private Button StartStopProcessing; + + @FXML + private Label StatusLabel; + + @FXML + private ImageView imageView; + + private Camera camera; + + private YoloDetector yoloDetector; + + private final AtomicBoolean processing = new AtomicBoolean(false); + + @FXML + private void initialize() { + Platform.runLater(() -> { + imageView.fitHeightProperty().bind(root.heightProperty().subtract(StartStopCamera.heightProperty())); + imageView.fitWidthProperty().bind(root.widthProperty()); + }); + Camera.EnumerateCameras(); + camera = new Camera(); + yoloDetector = new YoloDetector(0); + + Runtime.getRuntime().addShutdownHook(new Thread(() -> { + System.out.println("HelloController Shutdown hook called"); + processing.set(false); + camera.StopCamera(); + })); + } + + @FXML + private void StartStopProcessingClick(ActionEvent ignoredEvent) { + if (StartStopProcessing.getText().equals("Start Processing")) { + StartStopProcessing.setText("Stop Processing"); + processing.set(true); + } else { + StartStopProcessing.setText("Start Processing"); + processing.set(false); + } + } + + @FXML + private void StartStopCameraClick(ActionEvent ignoredActionEvent) { + if (StartStopCamera.getText().equals("Start Camera")) { + camera.StartCamera(0, opened->{ + if (opened) Update_Button_Text(StartStopCamera,"Stop Camera"); + }, newstatus ->{ + if (newstatus!=null && newstatus.length==3){ + Update_Label_Text(StatusLabel,newstatus[0]+"x"+newstatus[1]+" @ "+newstatus[2]+" fps"); + } + } ,newframe ->{ + // rotate 90 degrees clockwise + Mat rotated; + rotated = Somecodes.Rotate90Clockwise(newframe); + if (processing.get()) { + Mat result = yoloDetector.Detect(rotated); + Update_ImageView(Somecodes.MatToImage(result)); + } else { + Update_ImageView(Somecodes.MatToImage(rotated)); + } + }); + + } else { + camera.StopCamera(); + Update_Button_Text(StartStopCamera, "Start Camera"); + } + } + + private void Update_ImageView(Image mm){ + if (mm!=null){ + if (Platform.isFxApplicationThread()) { + imageView.setImage(mm); + } else { + Platform.runLater(() -> imageView.setImage(mm)); + } + } + } + + private void Update_Button_Text(Button btn, String text){ + if (btn != null && text != null){ + if (Platform.isFxApplicationThread()) { + btn.setText(text); + } else { + Platform.runLater(() -> btn.setText(text)); + } + } + } + + private void Update_Label_Text(Label lbl, String text){ + if (lbl != null && text != null){ + if (Platform.isFxApplicationThread()) { + lbl.setText(text); + } else { + Platform.runLater(() -> lbl.setText(text)); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/id/co/gtc/cudatester/Libraries.java b/src/main/java/id/co/gtc/cudatester/Libraries.java new file mode 100644 index 0000000..1cb7aef --- /dev/null +++ b/src/main/java/id/co/gtc/cudatester/Libraries.java @@ -0,0 +1,99 @@ +package id.co.gtc.cudatester; + +import java.io.File; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.function.Consumer; + +public class Libraries { + private static final String currentDirectory = System.getProperty("user.dir"); + + private static final String[] opencv_libraries = { + "avif", + "cublas64_12", + "cublasLt64_12", + "cudnn64_9", + "glib-2.0-0", + "gobject-2.0-0", + "gstapp-1.0-0", + "gstaudio-1.0-0", + "gstbase-1.0-0", + "gstpbutils-1.0-0", + "gstreamer-1.0-0", + "gstriff-1.0-0", + "gstvideo-1.0-0", + "nppc64_12", + "nppial64_12", + "nppist64_12", + "openvino", + "tesseract55", + "opencv_java4100", + "opencv_videoio_ffmpeg4100_64", + "archive", + "leptonica-1.85.0", + "libcurl", + "libyuv", + "intl-8", + "gmodule-2.0-0", + "pcre2-8-0", + "ffi-7", + "gsttag-1.0-0", + "orc-0.4-0", + "zlib1", + "bz2", + "lz4", + "zstd", + "gif", + "jpeg62", + "openjp2", + "libpng16", + "libwebpmux", + "libwebp", + "liblzma", + "libcrypto-3-x64", + "tiff", + "libsharpyuv", + "z-1", + "tbb12", + "libopenblas", + "cudnn_graph64_9", + "cudnn_ops64_9", + "cudnn_cnn64_9", + "cudnn_engines_precompiled64_9", + "cudnn_heuristic64_9", + "cudnn_engines_runtime_compiled64_9" + }; + + public static String getCurrentDirectory(){ + return currentDirectory; + } + + + + public static void ExtractAll(String targetdir, Consumer new_extract, Consumer already_exists, Consumer failed){ + + for(String lib : opencv_libraries){ + String libraryname = System.mapLibraryName(lib); + File libfile = new File(targetdir, libraryname); + if (libfile.isFile()) { + if (already_exists!=null) already_exists.accept(libraryname); + } else { + try{ + InputStream input = Libraries.class.getResourceAsStream("/"+libraryname); + if (input!=null){ + Files.copy(input, libfile.toPath()); + System.out.println("Library "+libraryname+" extracted to "+libfile.getAbsolutePath()); + if (new_extract!=null) new_extract.accept(libraryname); + } else { + System.out.println("Library "+libraryname+" not found in jar"); + if (failed!=null) failed.accept(libraryname); + } + } catch (Exception e){ + System.out.println("Exception when extracting library "+libraryname+", message : "+e.getMessage()); + if (failed!=null) failed.accept(libraryname); + } + } + } + + } +} diff --git a/src/main/java/id/co/gtc/cudatester/Somecodes.java b/src/main/java/id/co/gtc/cudatester/Somecodes.java new file mode 100644 index 0000000..32aca66 --- /dev/null +++ b/src/main/java/id/co/gtc/cudatester/Somecodes.java @@ -0,0 +1,143 @@ +package id.co.gtc.cudatester; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.nio.file.Files; + +import javafx.scene.image.Image; +import org.bytedeco.javacpp.BytePointer; +import org.bytedeco.opencv.global.opencv_imgcodecs; +import org.bytedeco.opencv.global.opencv_imgproc; +import org.bytedeco.opencv.opencv_core.Mat; +import org.bytedeco.opencv.opencv_core.Rect; +import org.bytedeco.opencv.opencv_core.Scalar; +import org.bytedeco.opencv.opencv_core.Size; +import org.tinylog.Logger; + +import static org.bytedeco.opencv.global.opencv_core.flip; +import static org.bytedeco.opencv.global.opencv_core.transpose; + + +public class Somecodes { + + + private static final String currentDirectory = System.getProperty("user.dir"); + + public static boolean FileExistsInCurrentDirectory(String filename){ + if (ValidString(filename)){ + return ValidFile(new File(currentDirectory, filename).getAbsolutePath()); + } + return false; + } + + public static String getCurrentDirectory(){ + return currentDirectory; + } + + /** + * Extract resource file to current directory + * @param filename resource file name + * @return extracted file path if success, or null if failed + */ + public static String ExtractResource(String filename){ + try{ + File destination = new File(currentDirectory, filename); + + if (destination.exists()){ + return destination.getAbsolutePath(); + } + InputStream is = Somecodes.class.getResourceAsStream(filename); + + if (is!=null){ + Files.copy(is, destination.toPath()); + Logger.info("Resource File extracted: ",filename); + return destination.getAbsolutePath(); + } + } catch (Exception e){ + Logger.error("Error extracting resource: "+filename+", Message : "+e.getMessage()); + } + return null; + } + + public static boolean ValidString(String str){ + return str != null && !str.isBlank(); + } + + public static boolean ValidFile(String filename){ + if (ValidString(filename)){ + File ff = new File(filename); + return ff.isFile(); + } + return false; + } + + public static Image MatToImage(Mat mat){ + Image result = null; + if (mat != null && !mat.empty()){ + BytePointer bp = new BytePointer(); + if (opencv_imgcodecs.imencode(".bmp",mat,bp)){ + byte[] data = new byte[(int)bp.limit()]; + bp.get(data); + result = new Image(new ByteArrayInputStream(data)); + } + mat.release(); + } + return result; + } + + + + public static Mat Rotate90Clockwise(Mat mat){ + if (mat != null && !mat.empty()){ + Mat transposed = new Mat(); + Mat rotated = new Mat(); + transpose(mat, transposed); + flip(transposed, rotated, 1); + transposed.release(); + return rotated; + } + return null; + } + + public static Mat FormatToSquare(int targetsize, Mat mat){ + if (mat != null && !mat.empty()){ + int width = mat.cols(); + int height = mat.rows(); + if (width>0 && height>0){ + if (targetsize>0){ + // create square mat with width=height = max, and fill with black + Mat square = new Mat(targetsize, targetsize, mat.type(), new Scalar(0,0,0,0)); + + // resize but keep aspect ratio + double aspectRatio = (double) width / height; + // resized mat + Mat resized = new Mat(); + int newheight; + int newwidth; + if (width > height){ + // width > height + newwidth = targetsize; + newheight = (int) (targetsize / aspectRatio); + opencv_imgproc.resize(mat, resized, new Size(newwidth, newheight)); + } else { + // height >= width + newwidth = (int) (targetsize * aspectRatio); + newheight = targetsize; + opencv_imgproc.resize(mat, resized, new Size(newwidth, newheight)); + } + // copy resized mat to square mat + + // calculate x and y offset + + // create rect for square mat + resized.copyTo(square.apply(new Rect(0,0,newwidth,newheight))); + // release resized mat + resized.release(); + return square; + } + } + } + return null; + } +} diff --git a/src/main/java/id/co/gtc/cudatester/YoloDetector.java b/src/main/java/id/co/gtc/cudatester/YoloDetector.java new file mode 100644 index 0000000..cb3cff7 --- /dev/null +++ b/src/main/java/id/co/gtc/cudatester/YoloDetector.java @@ -0,0 +1,178 @@ +package id.co.gtc.cudatester; + + +import org.bytedeco.javacpp.FloatPointer; +import org.bytedeco.javacpp.IntPointer; +import org.bytedeco.javacpp.indexer.FloatRawIndexer; +import org.bytedeco.opencv.global.opencv_dnn; +import org.bytedeco.opencv.global.opencv_imgproc; +import org.bytedeco.opencv.opencv_core.*; +import org.bytedeco.opencv.opencv_dnn.Net; +import org.bytedeco.opencv.opencv_text.FloatVector; +import org.opencv.dnn.Dnn; + +import java.io.File; + +import static org.bytedeco.opencv.global.opencv_core.CV_32F; + +@SuppressWarnings({"FieldCanBeLocal", "DuplicatedCode"}) +public class YoloDetector { + private static final String yolomodel = "yolov8s-face-lindevs.onnx"; + private static String yolofile =null; + static{ + System.out.println("Loading yolo model..."); + if (!Somecodes.FileExistsInCurrentDirectory(yolomodel)){ + String ff = Somecodes.ExtractResource("/"+yolomodel); + if (Somecodes.ValidFile(ff)){ + yolofile = ff; + System.out.println("Yolo model extracted: "+ff); + } else { + System.out.println("Failed to extract yolo model"); + } + } else { + yolofile = new File(Somecodes.getCurrentDirectory(), yolomodel).getAbsolutePath(); + System.out.println("Yolo model found: "+yolofile); + } + } + + private Net net = null; + private int type = -1; // 0 for CUDA, 1 for OpenVINO + + /** + * YoloDetector constructor + * @param type 0 for CUDA, 1 for OpenVINO, default to CUDA + */ + public YoloDetector(int type) { + if (yolofile!=null) { + net = opencv_dnn.readNetFromONNX(yolofile); + if (net.empty()) { + System.out.println("Failed to load yolo model"); + } else { + System.out.println("Yolo model loaded: " + yolofile); + if (type == 1) { + this.type = 1; + net.setPreferableBackend(Dnn.DNN_BACKEND_INFERENCE_ENGINE); + net.setPreferableTarget(Dnn.DNN_TARGET_CPU); + } else { + net.setPreferableBackend(Dnn.DNN_BACKEND_CUDA); + net.setPreferableTarget(Dnn.DNN_TARGET_CUDA); + this.type = 0; + } + } + } else { + System.out.println("Yolo model not found"); + } + } + + + private final double scale=1.0/255.0; + private Size size; + private Scalar scalar; + private final boolean swapRGB = true; + private final boolean crop = false; + + // Try this code : https://github.com/JustasBart/yolov8_CPP_Inference_OpenCV_ONNX/blob/minimalistic/inference.cpp + public Mat Detect(Mat frame){ + if (frame!=null && !frame.empty()){ + Mat blob; + if (type==0 || type==1){ + //System.out.println("Detecting "+(type==0?"CUDA":"OpenVINO")+" model..."); + // For an OpenVINO-optimized face detection model (like face-detection-adas-0001), size is (672, 384) + // but check again with the model used + if (size==null) size = new Size(640, 640); + if (scalar==null) scalar = new Scalar(0, 0, 0, 0); + if (frame.channels()==4) { + // Convert to 3 channels + Mat bgr = new Mat(); + opencv_imgproc.cvtColor(frame, bgr, opencv_imgproc.COLOR_BGRA2BGR); + frame = bgr; + } + Mat square = Somecodes.FormatToSquare(640, frame); + blob = opencv_dnn.blobFromImage(square, scale, size, scalar, swapRGB, crop, CV_32F); + if (blob!=null && !blob.empty()){ + net.setInput(blob); + Mat detections = net.forward(); + if (detections!=null && !detections.empty()){ + //System.out.println("Detection :"+detections.size(0)+" "+detections.size(1)+" "+detections.size(2)+" "+detections.size(3)); + + Mat result = ProcessWithYolo(detections, frame); + if (result!=null && !result.empty()){ + return new Mat(result); + } else System.out.println("Result is empty"); + } else System.out.println("Detection is empty"); + } else System.out.println("Blob is empty"); + } else System.out.println("Invalid model type"); + } else System.out.println("Frame is empty"); + return null; + } + + + @SuppressWarnings("resource") + private Mat ProcessWithYolo(Mat detections, Mat frame){ + if (detections!=null && !detections.empty()){ + if (frame!=null && !frame.empty()){ + float confThreshold = 0.5f; + float nmsThreshold = 0.4f; + + RectVector boxes = new RectVector(); + FloatVector confidences = new FloatVector(); + + FloatRawIndexer indexer = detections.createIndexer(); + + int numberOfDetections = detections.size(2); + // Loop over detections + for (int i = 0; i < numberOfDetections; i++) { + float confidence = indexer.get(0, 4, i); // Confidence at index 4 + if (confidence > confThreshold) { + float cx = indexer.get(0,0, i); + float cy = indexer.get(0, 1, i); + float w = indexer.get(0, 2, i); + float h = indexer.get(0, 3, i); + float scale_x = 1.0f * frame.cols() / 360; + float scale_y = 1.0f * frame.rows() / 640; + + int x_padding = 50; + int y_padding = 50; + + // Convert from normalized center format to pixel box + int x = (int) ((cx - w *0.5)*scale_x) - x_padding; + int y = (int) ((cy - h *0.5)*scale_y) - y_padding; + int width = (int) (w * scale_x) + 2*x_padding; + int height = (int) (h * scale_y) + 2*y_padding; + + //System.out.println("confidence: "+confidence); + boxes.push_back(new Rect(x, y, width, height)); + confidences.push_back(confidence); + + + } + } + + if (boxes.size()>0 && boxes.size()==confidences.size()){ + FloatPointer fp = new FloatPointer(confidences.size()); + for (int i = 0; i < confidences.size(); i++) { + fp.put(i, confidences.get(i)); + } + + + // Perform Non-Maximum Suppression + IntPointer indices = new IntPointer(boxes.size()); + opencv_dnn.NMSBoxes(boxes, fp, confThreshold, nmsThreshold, indices); + + Mat cloneFrame = new Mat(frame); + // Draw boxes on the cloneFrame + for(int i=0;i + + + + + + + + + + + + + + + + + + + + + +