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

Add asynchronous face detection sample for OpenVINO Java API 2.0 (updated from deprecated API 1.0) #951

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

leoheim
Copy link

@leoheim leoheim commented Mar 7, 2025

  • What was done in this PR?
    Initial project structure created

Set up basic asynchronous structure with threads and queues for frame capturing and inference handling.
Implemented video capture using OpenCV’s VideoCapture class:

Frames continuously read from webcam/video file.
Frames added to a thread-safe queue (BlockingQueue).
Model loading and preprocessing implemented with new API 2.0 methods:

Core.read_model() instead of the deprecated Core.ReadNetwork().
Configured inputs with the modern PrePostProcessor API.
Full asynchronous inference logic implemented:

Created multiple InferRequest instances for parallel inference.
Leveraged start_async() and wait_async() methods clearly and efficiently.
Results processing:

Obtained inference results (Tensor) and parsed detection coordinates.
Results passed to visualization thread through a queue (BlockingQueue<float[]>).
Visualization using OpenCV (HighGui):

Real-time visualization of face detections.
Bounding boxes drawn around detected faces.
Graceful shutdown added for threads and resources:

Proper interruption and termination of threads (captureThread, inferenceThread).
Closing OpenCV windows upon exit.

Feature Deprecated Java API 1.0 New Java API 2.0 (This PR)
Load Model CNNNetwork net = core.ReadNetwork(xmlPath) Model model = core.read_model(xmlPath)
Compile Model ExecutableNetwork exec = core.LoadNetwork(net, device) CompiledModel compiledModel = core.compile_model(model, device)
Inference Request execNetwork.CreateInferRequest() compiledModel.create_infer_request()
Async Inference StartAsync() & Wait(WaitMode) start_async() & wait_async() (simplified)
Input Handling Old-style Blob Modern Tensor object
Preprocessing Verbose manual config Simplified via PrePostProcessor API
Thread Management Similar async threads Improved readability and robustness
Visualization OpenCV (unchanged) OpenCV (unchanged)

  • Key additions and improvements:
    Clean and modern Java API 2.0 usage:
    Introduced modern classes (CompiledModel, Tensor, Model, PrePostProcessor).
    Clear asynchronous logic:
    Simplified inference workflow (start_async(), wait_async()).
    Better readability and maintainability:
    Added extensive inline comments explaining each step clearly.
    Simplified queues management for multi-threading.

  • What was removed:
    Deprecated API calls (CNNNetwork, manual Blob management).
    Complex asynchronous management using deprecated WaitMode enums and ID queues.

  • JNI implementation status:
    No new JNI methods required.
    All necessary JNI methods (start_async, wait_async, tensor handling) were already implemented previously in JNI files provided in the repository.

@leoheim leoheim requested review from a team as code owners March 7, 2025 22:17
@github-actions github-actions bot added the category: java API OpenVINO Runtime Java API label Mar 7, 2025
@ilya-lavrenov ilya-lavrenov linked an issue Mar 8, 2025 that may be closed by this pull request
2 tasks
@leoheim
Copy link
Author

leoheim commented Mar 10, 2025

Hey @likholat , in this last commit, I made changes primarily based on the deprecated sample. Let me know if there's anything else I can do to improve it further. This version should be more aligned and likely to work better now. Thanks for your time and review!

@likholat
Copy link
Contributor

@leoheim please keep only source files and remove all the binaries

@leoheim leoheim requested review from a team as code owners March 17, 2025 12:48
@github-actions github-actions bot added category: CI OpenVINO public CI category: NVIDIA plugin OpenVINO NVIDIA plugin labels Mar 17, 2025
@leoheim
Copy link
Author

leoheim commented Mar 17, 2025

Hi @likholat ,

I have updated the repository to keep only the source files

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove all the binary files from PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep only changes related to Java sample and Android sample

@leoheim leoheim force-pushed the openvino-2.0-async branch from 351ffc8 to cd9cf4f Compare March 17, 2025 15:20
@github-actions github-actions bot removed category: CI OpenVINO public CI category: NVIDIA plugin OpenVINO NVIDIA plugin labels Mar 17, 2025
@leoheim
Copy link
Author

leoheim commented Mar 17, 2025

Hey @likholat, I believe it's correct now. I've removed the unnecessary files and kept only the source files as requested. Let me know if there's anything else you'd like me to adjust!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: java API OpenVINO Runtime Java API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Good First Issue]: [JAVA API] Async demo for Java API 2.0
2 participants