diff --git a/ai_controller/aiengine.cpp b/ai_controller/aiengine.cpp index b33d054..b3ab86f 100644 --- a/ai_controller/aiengine.cpp +++ b/ai_controller/aiengine.cpp @@ -82,7 +82,7 @@ void AiEngine::stop(void) void AiEngine::inferenceResultsReceivedSlot(AiEngineInferenceResult result) { mFrameCounter++; - qDebug() << "FPS = " << (mFrameCounter / (mElapsedTimer.elapsed()/1000.0f)); + //qDebug() << "FPS = " << (mFrameCounter / (mElapsedTimer.elapsed()/1000.0f)); //qDebug() << "DEBUG. inference frame counter:" << mFrameCounter; //qDebug() << "AiEngine got inference results in thread: " << QThread::currentThreadId(); diff --git a/ai_controller/aiengineinference.h b/ai_controller/aiengineinference.h index 192a7b1..2681fa8 100644 --- a/ai_controller/aiengineinference.h +++ b/ai_controller/aiengineinference.h @@ -8,8 +8,8 @@ #include "aienginedefinitions.h" -const int INFERENCE_SQUARE_WIDTH = 640; -const int INFERENCE_SQUARE_HEIGHT = 640; +const int INFERENCE_SQUARE_WIDTH = 1280; +const int INFERENCE_SQUARE_HEIGHT = 1280; class AiEngineObject { diff --git a/ai_controller/src-opi5/aiengineinferenceopi5.cpp b/ai_controller/src-opi5/aiengineinferenceopi5.cpp index 736237b..645183a 100644 --- a/ai_controller/src-opi5/aiengineinferenceopi5.cpp +++ b/ai_controller/src-opi5/aiengineinferenceopi5.cpp @@ -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(inputFrame.cols) / static_cast(inputFrame.rows); - int newWidth = targetWidth; - int newHeight = static_cast(targetWidth / aspectRatio); - if (newHeight > targetHeight) { - newHeight = targetHeight; - newWidth = static_cast(targetHeight * aspectRatio); + int newWidth = toWidth; + int newHeight = static_cast(toWidth / aspectRatio); + if (newHeight > toHeight) { + newHeight = toHeight; + newWidth = static_cast(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; diff --git a/ai_controller/src-opi5/aiengineinferenceopi5.h b/ai_controller/src-opi5/aiengineinferenceopi5.h index 84359e6..05d6bf3 100644 --- a/ai_controller/src-opi5/aiengineinferenceopi5.h +++ b/ai_controller/src-opi5/aiengineinferenceopi5.h @@ -19,7 +19,7 @@ public slots: private: image_buffer_t convertCV2FrameToImageBuffer(const cv::Mat& bgrFrame); void freeImageBuffer(image_buffer_t& imgBuffer); - cv::Mat resizeToHalfAndAssigntoTopLeft640x640(const cv::Mat& inputFrame); + cv::Mat resizeAndAssignToTopLeft(const int toWidth, const int toHeight, const cv::Mat& inputFrame); void drawObjects(cv::Mat& image, const object_detect_result_list& result_list); rknn_app_context_t mRrknnAppCtx0; diff --git a/ai_controller/src-opi5/image_utils.c b/ai_controller/src-opi5/image_utils.c index b5180a4..cf62955 100644 --- a/ai_controller/src-opi5/image_utils.c +++ b/ai_controller/src-opi5/image_utils.c @@ -666,17 +666,17 @@ int convert_image(image_buffer_t* src_img, image_buffer_t* dst_img, image_rect_t { int ret; - printf("src width=%d height=%d fmt=0x%x virAddr=0x%p fd=%d\n", - src_img->width, src_img->height, src_img->format, src_img->virt_addr, src_img->fd); - printf("dst width=%d height=%d fmt=0x%x virAddr=0x%p fd=%d\n", - dst_img->width, dst_img->height, dst_img->format, dst_img->virt_addr, dst_img->fd); - if (src_box != NULL) { - printf("src_box=(%d %d %d %d)\n", src_box->left, src_box->top, src_box->right, src_box->bottom); - } - if (dst_box != NULL) { - printf("dst_box=(%d %d %d %d)\n", dst_box->left, dst_box->top, dst_box->right, dst_box->bottom); - } - printf("color=0x%x\n", color); +// printf("src width=%d height=%d fmt=0x%x virAddr=0x%p fd=%d\n", +// src_img->width, src_img->height, src_img->format, src_img->virt_addr, src_img->fd); +// printf("dst width=%d height=%d fmt=0x%x virAddr=0x%p fd=%d\n", +// dst_img->width, dst_img->height, dst_img->format, dst_img->virt_addr, dst_img->fd); +// if (src_box != NULL) { +// printf("src_box=(%d %d %d %d)\n", src_box->left, src_box->top, src_box->right, src_box->bottom); +// } +// if (dst_box != NULL) { +// printf("dst_box=(%d %d %d %d)\n", dst_box->left, dst_box->top, dst_box->right, dst_box->bottom); +// } +// printf("color=0x%x\n", color); ret = convert_image_rga(src_img, dst_img, src_box, dst_box, color); if (ret != 0) { @@ -757,9 +757,9 @@ int convert_image_with_letterbox(image_buffer_t* src_image, image_buffer_t* dst_ dst_box.right = dst_box.left + resize_w - 1; _left_offset = dst_box.left; } - printf("scale=%f dst_box=(%d %d %d %d) allow_slight_change=%d _left_offset=%d _top_offset=%d padding_w=%d padding_h=%d\n", - scale, dst_box.left, dst_box.top, dst_box.right, dst_box.bottom, allow_slight_change, - _left_offset, _top_offset, padding_w, padding_h); +// printf("scale=%f dst_box=(%d %d %d %d) allow_slight_change=%d _left_offset=%d _top_offset=%d padding_w=%d padding_h=%d\n", +// scale, dst_box.left, dst_box.top, dst_box.right, dst_box.bottom, allow_slight_change, +// _left_offset, _top_offset, padding_w, padding_h); //set offset and scale if(letterbox != NULL){ diff --git a/ai_controller/src-opi5/yolov8.cc b/ai_controller/src-opi5/yolov8.cc index 4b26cf8..ff179e7 100644 --- a/ai_controller/src-opi5/yolov8.cc +++ b/ai_controller/src-opi5/yolov8.cc @@ -235,7 +235,7 @@ int inference_yolov8_model(rknn_app_context_t *app_ctx, image_buffer_t *img, obj } // Run - printf("rknn_run\n"); + //printf("rknn_run\n"); ret = rknn_run(app_ctx->rknn_ctx, nullptr); if (ret < 0) {