diff --git a/modules/java_api/bin/main/org/intel/openvino/Any.class b/modules/java_api/bin/main/org/intel/openvino/Any.class new file mode 100644 index 000000000..86feb80d9 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Any.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/CompiledModel.class b/modules/java_api/bin/main/org/intel/openvino/CompiledModel.class new file mode 100644 index 000000000..dec2a4111 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/CompiledModel.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/Core.class b/modules/java_api/bin/main/org/intel/openvino/Core.class new file mode 100644 index 000000000..443369c74 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Core.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/Dimension.class b/modules/java_api/bin/main/org/intel/openvino/Dimension.class new file mode 100644 index 000000000..23ad760d8 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Dimension.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/ElementType.class b/modules/java_api/bin/main/org/intel/openvino/ElementType.class new file mode 100644 index 000000000..a22fc3f85 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/ElementType.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/InferRequest.class b/modules/java_api/bin/main/org/intel/openvino/InferRequest.class new file mode 100644 index 000000000..e048caacb Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/InferRequest.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/InputInfo.class b/modules/java_api/bin/main/org/intel/openvino/InputInfo.class new file mode 100644 index 000000000..38fb693ab Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/InputInfo.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/InputModelInfo.class b/modules/java_api/bin/main/org/intel/openvino/InputModelInfo.class new file mode 100644 index 000000000..183105eac Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/InputModelInfo.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/InputTensorInfo.class b/modules/java_api/bin/main/org/intel/openvino/InputTensorInfo.class new file mode 100644 index 000000000..f0b068d05 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/InputTensorInfo.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/Layout.class b/modules/java_api/bin/main/org/intel/openvino/Layout.class new file mode 100644 index 000000000..55fbc636f Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Layout.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/Model.class b/modules/java_api/bin/main/org/intel/openvino/Model.class new file mode 100644 index 000000000..d578ea452 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Model.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/NativeLibrary.class b/modules/java_api/bin/main/org/intel/openvino/NativeLibrary.class new file mode 100644 index 000000000..3eb8695a5 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/NativeLibrary.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/Openvino.class b/modules/java_api/bin/main/org/intel/openvino/Openvino.class new file mode 100644 index 000000000..9814f1f87 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Openvino.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/Output.class b/modules/java_api/bin/main/org/intel/openvino/Output.class new file mode 100644 index 000000000..bd1512083 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Output.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/OutputInfo.class b/modules/java_api/bin/main/org/intel/openvino/OutputInfo.class new file mode 100644 index 000000000..ca44621c4 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/OutputInfo.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/PartialShape.class b/modules/java_api/bin/main/org/intel/openvino/PartialShape.class new file mode 100644 index 000000000..843608711 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/PartialShape.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/PrePostProcessor.class b/modules/java_api/bin/main/org/intel/openvino/PrePostProcessor.class new file mode 100644 index 000000000..e39f8bdb7 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/PrePostProcessor.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/PreProcessSteps.class b/modules/java_api/bin/main/org/intel/openvino/PreProcessSteps.class new file mode 100644 index 000000000..626e7f854 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/PreProcessSteps.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/ResizeAlgorithm.class b/modules/java_api/bin/main/org/intel/openvino/ResizeAlgorithm.class new file mode 100644 index 000000000..a79b3b9ca Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/ResizeAlgorithm.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/Tensor.class b/modules/java_api/bin/main/org/intel/openvino/Tensor.class new file mode 100644 index 000000000..db0767619 Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Tensor.class differ diff --git a/modules/java_api/bin/main/org/intel/openvino/Wrapper.class b/modules/java_api/bin/main/org/intel/openvino/Wrapper.class new file mode 100644 index 000000000..28e49f2fe Binary files /dev/null and b/modules/java_api/bin/main/org/intel/openvino/Wrapper.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/CompiledModelTests.class b/modules/java_api/bin/test/org/intel/openvino/CompiledModelTests.class new file mode 100644 index 000000000..19883bc96 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/CompiledModelTests.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/CoreTests$1.class b/modules/java_api/bin/test/org/intel/openvino/CoreTests$1.class new file mode 100644 index 000000000..050e68a17 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/CoreTests$1.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/CoreTests.class b/modules/java_api/bin/test/org/intel/openvino/CoreTests.class new file mode 100644 index 000000000..76a996216 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/CoreTests.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/ModelTests.class b/modules/java_api/bin/test/org/intel/openvino/ModelTests.class new file mode 100644 index 000000000..4479a6817 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/ModelTests.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/OVTest$1.class b/modules/java_api/bin/test/org/intel/openvino/OVTest$1.class new file mode 100644 index 000000000..f7339e371 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/OVTest$1.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/OVTest.class b/modules/java_api/bin/test/org/intel/openvino/OVTest.class new file mode 100644 index 000000000..041a38304 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/OVTest.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/OpenvinoTests.class b/modules/java_api/bin/test/org/intel/openvino/OpenvinoTests.class new file mode 100644 index 000000000..d8644dbd5 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/OpenvinoTests.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/PrePostProcessorTests.class b/modules/java_api/bin/test/org/intel/openvino/PrePostProcessorTests.class new file mode 100644 index 000000000..efcaca656 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/PrePostProcessorTests.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/TensorTests.class b/modules/java_api/bin/test/org/intel/openvino/TensorTests.class new file mode 100644 index 000000000..3d8f49a3e Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/TensorTests.class differ diff --git a/modules/java_api/bin/test/org/intel/openvino/TestsSuite.class b/modules/java_api/bin/test/org/intel/openvino/TestsSuite.class new file mode 100644 index 000000000..ab9b4f2d3 Binary files /dev/null and b/modules/java_api/bin/test/org/intel/openvino/TestsSuite.class differ diff --git a/modules/java_api/samples/face_detection_java_sample_async/build.gradle b/modules/java_api/samples/face_detection_java_sample_async/build.gradle new file mode 100644 index 000000000..7f552132f --- /dev/null +++ b/modules/java_api/samples/face_detection_java_sample_async/build.gradle @@ -0,0 +1,43 @@ +plugins { + id 'java' + id 'application' +} + +import org.gradle.internal.os.OperatingSystem + +def opencv_path = System.getenv('OpenCV_DIR') +def opencv_build_path = new File(opencv_path + '/bin') +def opencv_install_path = new File(opencv_path + '/share/java') + +if (OperatingSystem.current().isLinux()) { + opencv_build_path = new File(opencv_path + '/bin') + opencv_install_path = new File(opencv_path + '/share/java/opencv4') +} else if (OperatingSystem.current().isMacOsX()) { + opencv_build_path = new File(opencv_path + '/share/java/opencv4') + opencv_install_path = new File(opencv_path + '/share/OpenCV/java') +} else if (OperatingSystem.current().isWindows()) { + opencv_build_path = new File(opencv_path + '/java') + opencv_install_path = new File(opencv_path + '/java') +} + +if (opencv_build_path.exists() ) { + opencv_path = opencv_build_path +} else if (opencv_install_path.exists() ) { + opencv_path = opencv_install_path +} else { + throw new GradleException('Incorrect OpenCV_DIR path!') +} + +sourceSets { + main { + java { + srcDirs = ["src/main/java", "../common"] + } + } +} +mainClassName = 'Main' + +dependencies { + implementation rootProject + implementation fileTree(dir: opencv_path, include: '*.jar') +} diff --git a/modules/java_api/samples/face_detection_java_sample_async/settings.gradle b/modules/java_api/samples/face_detection_java_sample_async/settings.gradle new file mode 100644 index 000000000..ccb4053ca --- /dev/null +++ b/modules/java_api/samples/face_detection_java_sample_async/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'face_detection_java_sample_async' diff --git a/modules/java_api/samples/face_detection_java_sample_async/src/main/java/Main.java b/modules/java_api/samples/face_detection_java_sample_async/src/main/java/Main.java new file mode 100644 index 000000000..dbbc75d81 --- /dev/null +++ b/modules/java_api/samples/face_detection_java_sample_async/src/main/java/Main.java @@ -0,0 +1,253 @@ +import org.intel.openvino.*; +import org.opencv.core.*; +import org.opencv.highgui.HighGui; +import org.opencv.imgcodecs.*; +import org.opencv.imgproc.Imgproc; +import org.opencv.videoio.*; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.Map; +import java.util.Queue; +import java.util.Vector; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.TimeUnit; + +/* +This is async face detection Java sample (for OpenVINO Java API 2.0). +Upon the start-up the sample application reads command line parameters and loads a network +and an image to the Inference Engine device. When inference is done, the application will show +the image with detected objects enclosed in rectangles in new window. It also outputs the +confidence value and the coordinates of the rectangle to the standard output stream. +To get the list of command line parameters run the application with `--help` parameter. +*/ +public class Main { + static final float CONFIDENCE_THRESHOLD = 0.7f; + static int waitingTime = 1; + + static BlockingQueue processedFramesQueue = new LinkedBlockingQueue(); + static BlockingQueue detectionOutput = new LinkedBlockingQueue(); + + static String outputName; + static Queue startedRequestsIds = new LinkedList(); + static Vector inferRequests = new Vector(); + static Vector asyncInferIsFree; + + static int framesCounter = 0; + static int resultCounter = 0; + + public static Tensor imageToTensor(Mat image) { + int[] dimsArr = {1, image.rows(), image.cols(), 3}; + return new Tensor(ElementType.u8, dimsArr, image.dataAddr()); + } + + static void processInferRequests() { + while (!startedRequestsIds.isEmpty()) { + int requestId = startedRequestsIds.peek(); + InferRequest inferRequest = inferRequests.get(requestId); + + if (!inferRequest.wait_for(0)) return; + + Tensor outputTensor = inferRequest.get_output_tensor(); + float[] res = outputTensor.data(); + + detectionOutput.add(res); + + resultCounter++; + asyncInferIsFree.setElementAt(true, requestId); + startedRequestsIds.remove(); + } + } + + public static void main(String[] args) { + try { + System.loadLibrary(Core.NATIVE_LIBRARY_NAME); + } catch (UnsatisfiedLinkError e) { + System.err.println("Failed to load OpenCV library\n" + e); + System.exit(1); + } + + ArgumentParser parser = new ArgumentParser("This is async face detection sample"); + parser.addArgument("-i", "path to video"); + parser.addArgument("-m", "path to model .xml"); + parser.addArgument("-d", "device"); + parser.addArgument("-nireq", "number of infer requests"); + parser.parseArgs(args); + + String imgsPath = parser.get("-i", null); + String xmlPath = parser.get("-m", null); + String device = parser.get("-d", "CPU"); + int inferRequestsSize = parser.getInteger("-nireq", 2); + + if (imgsPath == null) { + System.out.println("Error: Missed argument: -i"); + return; + } + if (xmlPath == null) { + System.out.println("Error: Missed argument: -m"); + return; + } + + int warmupNum = inferRequestsSize * 2; + + BlockingQueue framesQueue = new LinkedBlockingQueue(); + + Runnable capture = + new Runnable() { + @Override + public void run() { + Mat frame = new Mat(); + + VideoCapture cam = new VideoCapture(); + try { + int idx = Integer.valueOf(imgsPath); + cam.open(idx); + } catch (NumberFormatException exception) { + cam.open(imgsPath); + } + + while (cam.read(frame) && !Thread.interrupted()) { + framesCounter++; + framesQueue.add(frame.clone()); + } + if (framesCounter == 0) { + System.err.println("ERROR: Can't get any video frame!"); + System.exit(1); + } + } + }; + Thread captureThread = new Thread(capture); + + Runnable infer = + new Runnable() { + @Override + public void run() { + try { + Core core = new Core(); + Model net = core.read_model(xmlPath); + + PrePostProcessor p = new PrePostProcessor(net); + p.input() + .tensor() + .set_element_type(ElementType.u8) + .set_layout(new Layout("NHWC")); + p.input().preprocess().resize(ResizeAlgorithm.RESIZE_LINEAR); + p.input().model().set_layout(new Layout("NCHW")); + p.build(); + + CompiledModel compiledModel = core.compile_model(net, device); + + asyncInferIsFree = new Vector(inferRequestsSize); + + for (int i = 0; i < inferRequestsSize; i++) { + inferRequests.add(compiledModel.create_infer_request()); + asyncInferIsFree.add(true); + } + + boolean isRunning = true; + + while (captureThread.isAlive() || !framesQueue.isEmpty()) { + if (Thread.interrupted()) break; + + processInferRequests(); + for (int i = 0; i < inferRequestsSize; i++) { + if (!asyncInferIsFree.get(i)) continue; + + Mat frame = framesQueue.poll(0, TimeUnit.SECONDS); + + if (frame == null) break; + + InferRequest request = inferRequests.get(i); + + asyncInferIsFree.setElementAt(false, i); + + processedFramesQueue.add(frame); + + Tensor imgTensor = imageToTensor(frame); + request.set_input_tensor(imgTensor); + + startedRequestsIds.add(i); + request.start_async(); + } + } + processInferRequests(); + } catch (InterruptedException e) { + e.printStackTrace(); + + for (Thread t : Thread.getAllStackTraces().keySet()) + if (t.getState() == Thread.State.RUNNABLE) t.interrupt(); + } + } + }; + Thread inferThread = new Thread(infer); + + captureThread.start(); + inferThread.start(); + + TickMeter tm = new TickMeter(); + Scalar color = new Scalar(0, 255, 0); + try { + while (inferThread.isAlive() || !detectionOutput.isEmpty()) { + + float[] detection = detectionOutput.poll(waitingTime, TimeUnit.SECONDS); + if (detection == null) continue; + + Mat img = processedFramesQueue.poll(waitingTime, TimeUnit.SECONDS); + int maxProposalCount = detection.length / 7; + + for (int curProposal = 0; curProposal < maxProposalCount; curProposal++) { + int imageId = (int) detection[curProposal * 7]; + if (imageId < 0) break; + + float confidence = detection[curProposal * 7 + 2]; + + // Drawing only objects with >70% probability + if (confidence < CONFIDENCE_THRESHOLD) continue; + + int xmin = (int) (detection[curProposal * 7 + 3] * img.cols()); + int ymin = (int) (detection[curProposal * 7 + 4] * img.rows()); + int xmax = (int) (detection[curProposal * 7 + 5] * img.cols()); + int ymax = (int) (detection[curProposal * 7 + 6] * img.rows()); + + // Draw rectangle around detected object. + Point lt = new Point(xmin, ymin); + Point br = new Point(xmax, ymax); + Imgproc.rectangle(img, lt, br, color, 2); + } + + if (resultCounter == warmupNum) { + tm.start(); + } else if (resultCounter > warmupNum) { + tm.stop(); + double worksFps = ((double) (resultCounter - warmupNum)) / tm.getTimeSec(); + double readFps = ((double) (framesCounter - warmupNum)) / tm.getTimeSec(); + tm.start(); + + String label = "Reading fps: " + String.format("%.3f", readFps); + String label1 = "Inference fps: " + String.format("%.3f", worksFps); + + Imgproc.putText(img, label, new Point(10, 50), 0, 0.7, color, 1); + Imgproc.putText(img, label1, new Point(10, 80), 0, 0.7, color, 1); + } + HighGui.imshow("Detection", img); + + if (HighGui.waitKey(1) != -1) { + inferThread.interrupt(); + captureThread.interrupt(); + break; + } + } + + HighGui.waitKey(1); + HighGui.destroyAllWindows(); + + captureThread.join(); + inferThread.join(); + } catch (InterruptedException e) { + e.printStackTrace(); + for (Thread t : Thread.getAllStackTraces().keySet()) + if (t.getState() == Thread.State.RUNNABLE) t.interrupt(); + } + } +} \ No newline at end of file