Enables use of multiple TPUs in OPI5

This commit is contained in:
Tuomas Järvinen
2024-07-27 11:28:47 +03:00
parent 147213cec6
commit 7052a05d55
17 changed files with 336 additions and 65 deletions
@@ -21,10 +21,11 @@ void AiEngineInferenceOpencvOnnx::performInferenceSlot(cv::Mat frame)
mActive = true;
cv::Mat scaledImage = resizeAndPad(frame);
//cv::imwrite("/tmp/frame.png", scaledImage);
std::vector<Detection> detections = mInference.runInference(scaledImage);
AiEngineInferenceResult result;
//qDebug() << "performInferenceSlot() found " << detections.size() << " objects";
qDebug() << "performInferenceSlot() found " << detections.size() << " objects";
for (uint i = 0; i < detections.size(); ++i) {
const Detection &detection = detections[i];
@@ -38,8 +39,15 @@ void AiEngineInferenceOpencvOnnx::performInferenceSlot(cv::Mat frame)
object.rectangle.bottom = detection.box.y + detection.box.height;
object.rectangle.right = detection.box.x + detection.box.width;
result.objects.append(object);
//qDebug() << "performInferenceSlot()" << object.rectangle.top << object.rectangle.left << "and" << object.rectangle.bottom << object.rectangle.right;
}
auto end = std::remove_if(detections.begin(), detections.end(), [](const Detection& detection) {
return detection.class_id != 0;
});
detections.erase(end, detections.end());
if (result.objects.empty() == false) {
result.frame = mInference.drawLabels(scaledImage, detections);
emit resultsReady(result);
@@ -51,3 +59,9 @@ void AiEngineInferenceOpencvOnnx::performInferenceSlot(cv::Mat frame)
std::cerr << "performInferenceSlot() Error: " << e.what() << std::endl;
}
}
void AiEngineInferenceOpencvOnnx::initialize(int number)
{
(void)number;
}