Add asynchronous face detection sample for OpenVINO Java API 2.0 (updated from deprecated API 1.0) #951
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
CNNNetwork net = core.ReadNetwork(xmlPath)
Model model = core.read_model(xmlPath)
ExecutableNetwork exec = core.LoadNetwork(net, device)
CompiledModel compiledModel = core.compile_model(model, device)
execNetwork.CreateInferRequest()
compiledModel.create_infer_request()
StartAsync()
&Wait(WaitMode)
start_async()
&wait_async()
(simplified)Blob
Tensor
objectPrePostProcessor
APIKey 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.