use INFERENCE_SQUARE_WIDTH and INFERENCE_SQUARE_HEIGHT defined in aiengineinference.h for resizing in opi5 (set them to 1280)

reorganised logs for inference output, remove some logs for more clear output
This commit is contained in:
Alex Bezdieniezhnykh
2024-10-25 17:05:16 +03:00
parent 45c19baa45
commit 5f22931e0d
6 changed files with 34 additions and 32 deletions
@@ -68,7 +68,7 @@ void AiEngineInferenceOpi5::freeImageBuffer(image_buffer_t& imgBuffer)
}
cv::Mat AiEngineInferenceOpi5::resizeToHalfAndAssigntoTopLeft640x640(const cv::Mat& inputFrame)
cv::Mat AiEngineInferenceOpi5::resizeAndAssignToTopLeft(const int toWidth, const int toHeight, const cv::Mat& inputFrame)
{
/*
// Resize input frame to half size
@@ -85,19 +85,17 @@ cv::Mat AiEngineInferenceOpi5::resizeToHalfAndAssigntoTopLeft640x640(const cv::M
return outputFrame;
*/
const int targetWidth = 640;
const int targetHeight = 640;
float aspectRatio = static_cast<float>(inputFrame.cols) / static_cast<float>(inputFrame.rows);
int newWidth = targetWidth;
int newHeight = static_cast<int>(targetWidth / aspectRatio);
if (newHeight > targetHeight) {
newHeight = targetHeight;
newWidth = static_cast<int>(targetHeight * aspectRatio);
int newWidth = toWidth;
int newHeight = static_cast<int>(toWidth / aspectRatio);
if (newHeight > toHeight) {
newHeight = toHeight;
newWidth = static_cast<int>(toHeight * aspectRatio);
}
cv::Mat resizedFrame;
cv::resize(inputFrame, resizedFrame, cv::Size(newWidth, newHeight));
cv::Mat outputFrame = cv::Mat::zeros(targetHeight, targetWidth, inputFrame.type());
cv::Mat outputFrame = cv::Mat::zeros(toHeight, toWidth, inputFrame.type());
cv::Rect roi(cv::Point(0, 0), resizedFrame.size());
resizedFrame.copyTo(outputFrame(roi));
@@ -116,19 +114,24 @@ void AiEngineInferenceOpi5::drawObjects(cv::Mat& image, const object_detect_resu
//continue;
}
fprintf(stderr, "Inference[%d] probability = %f\n", i, result.prop * 100);
//fprintf(stderr, "Inference[%d] probability = %f\n", i, result.prop * 100);
int left = result.box.left;
int top = result.box.top;
int right = result.box.right;
int bottom = result.box.bottom;
QString cName = mClassNames[result.cls_id % mClassNames.size()];
qDebug() << "x:" << left << "y:" << top
<< "| size:" << right - left << "," << bottom - top
<< "| " << qPrintable(cName) << ":" << (int)(result.prop * 100) << "% \n";
cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv::Scalar(255, 0, 0), 2);
// Text
char c_text[256];
//sprintf(c_text, "%s %d%%", coco_cls_to_name(result.cls_id), (int)(round(result.prop * 100)));
sprintf(c_text, "%s %d%%", mClassNames[result.cls_id % mClassNames.size()].toStdString().c_str(), (int)(round(result.prop * 100)));
sprintf(c_text, "%s %d%%", cName.toStdString().c_str(), (int)(round(result.prop * 100)));
cv::Point textOrg(left, top - 5);
cv::putText(image, std::string(c_text), textOrg, cv::FONT_HERSHEY_COMPLEX, 0.70, cv::Scalar(0, 0, 255), 1, cv::LINE_AA);
}
@@ -141,7 +144,7 @@ void AiEngineInferenceOpi5::performInferenceSlot(cv::Mat frame)
mActive = true;
cv::Mat scaledFrame = resizeToHalfAndAssigntoTopLeft640x640(frame);
cv::Mat scaledFrame = resizeAndAssignToTopLeft(INFERENCE_SQUARE_WIDTH, INFERENCE_SQUARE_HEIGHT, frame);
image_buffer_t imgBuffer = convertCV2FrameToImageBuffer(scaledFrame);
object_detect_result_list od_results;
@@ -156,7 +159,6 @@ void AiEngineInferenceOpi5::performInferenceSlot(cv::Mat frame)
AiEngineInferenceResult result;
for (int i = 0; i < od_results.count; i++) {
object_detect_result *det_result = &(od_results.results[i]);
qDebug() << "____box:" << det_result->box.top << det_result->box.left << det_result->box.bottom << det_result->box.right << "\n";
AiEngineObject object;
object.classId = det_result->cls_id;
object.propability = det_result->prop;