mirror of
https://github.com/azaion/autopilot.git
synced 2026-04-22 22:46:33 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f22931e0d |
@@ -82,7 +82,7 @@ void AiEngine::stop(void)
|
|||||||
void AiEngine::inferenceResultsReceivedSlot(AiEngineInferenceResult result)
|
void AiEngine::inferenceResultsReceivedSlot(AiEngineInferenceResult result)
|
||||||
{
|
{
|
||||||
mFrameCounter++;
|
mFrameCounter++;
|
||||||
qDebug() << "FPS = " << (mFrameCounter / (mElapsedTimer.elapsed()/1000.0f));
|
//qDebug() << "FPS = " << (mFrameCounter / (mElapsedTimer.elapsed()/1000.0f));
|
||||||
//qDebug() << "DEBUG. inference frame counter:" << mFrameCounter;
|
//qDebug() << "DEBUG. inference frame counter:" << mFrameCounter;
|
||||||
|
|
||||||
//qDebug() << "AiEngine got inference results in thread: " << QThread::currentThreadId();
|
//qDebug() << "AiEngine got inference results in thread: " << QThread::currentThreadId();
|
||||||
|
|||||||
@@ -8,8 +8,8 @@
|
|||||||
#include "aienginedefinitions.h"
|
#include "aienginedefinitions.h"
|
||||||
|
|
||||||
|
|
||||||
const int INFERENCE_SQUARE_WIDTH = 640;
|
const int INFERENCE_SQUARE_WIDTH = 1280;
|
||||||
const int INFERENCE_SQUARE_HEIGHT = 640;
|
const int INFERENCE_SQUARE_HEIGHT = 1280;
|
||||||
|
|
||||||
|
|
||||||
class AiEngineObject {
|
class AiEngineObject {
|
||||||
|
|||||||
@@ -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
|
// Resize input frame to half size
|
||||||
@@ -85,19 +85,17 @@ cv::Mat AiEngineInferenceOpi5::resizeToHalfAndAssigntoTopLeft640x640(const cv::M
|
|||||||
return outputFrame;
|
return outputFrame;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const int targetWidth = 640;
|
|
||||||
const int targetHeight = 640;
|
|
||||||
float aspectRatio = static_cast<float>(inputFrame.cols) / static_cast<float>(inputFrame.rows);
|
float aspectRatio = static_cast<float>(inputFrame.cols) / static_cast<float>(inputFrame.rows);
|
||||||
int newWidth = targetWidth;
|
int newWidth = toWidth;
|
||||||
int newHeight = static_cast<int>(targetWidth / aspectRatio);
|
int newHeight = static_cast<int>(toWidth / aspectRatio);
|
||||||
if (newHeight > targetHeight) {
|
if (newHeight > toHeight) {
|
||||||
newHeight = targetHeight;
|
newHeight = toHeight;
|
||||||
newWidth = static_cast<int>(targetHeight * aspectRatio);
|
newWidth = static_cast<int>(toHeight * aspectRatio);
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::Mat resizedFrame;
|
cv::Mat resizedFrame;
|
||||||
cv::resize(inputFrame, resizedFrame, cv::Size(newWidth, newHeight));
|
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());
|
cv::Rect roi(cv::Point(0, 0), resizedFrame.size());
|
||||||
resizedFrame.copyTo(outputFrame(roi));
|
resizedFrame.copyTo(outputFrame(roi));
|
||||||
|
|
||||||
@@ -116,19 +114,24 @@ void AiEngineInferenceOpi5::drawObjects(cv::Mat& image, const object_detect_resu
|
|||||||
//continue;
|
//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 left = result.box.left;
|
||||||
int top = result.box.top;
|
int top = result.box.top;
|
||||||
int right = result.box.right;
|
int right = result.box.right;
|
||||||
int bottom = result.box.bottom;
|
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);
|
cv::rectangle(image, cv::Point(left, top), cv::Point(right, bottom), cv::Scalar(255, 0, 0), 2);
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
char c_text[256];
|
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%%", 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::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);
|
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;
|
mActive = true;
|
||||||
|
|
||||||
cv::Mat scaledFrame = resizeToHalfAndAssigntoTopLeft640x640(frame);
|
cv::Mat scaledFrame = resizeAndAssignToTopLeft(INFERENCE_SQUARE_WIDTH, INFERENCE_SQUARE_HEIGHT, frame);
|
||||||
image_buffer_t imgBuffer = convertCV2FrameToImageBuffer(scaledFrame);
|
image_buffer_t imgBuffer = convertCV2FrameToImageBuffer(scaledFrame);
|
||||||
|
|
||||||
object_detect_result_list od_results;
|
object_detect_result_list od_results;
|
||||||
@@ -156,7 +159,6 @@ void AiEngineInferenceOpi5::performInferenceSlot(cv::Mat frame)
|
|||||||
AiEngineInferenceResult result;
|
AiEngineInferenceResult result;
|
||||||
for (int i = 0; i < od_results.count; i++) {
|
for (int i = 0; i < od_results.count; i++) {
|
||||||
object_detect_result *det_result = &(od_results.results[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;
|
AiEngineObject object;
|
||||||
object.classId = det_result->cls_id;
|
object.classId = det_result->cls_id;
|
||||||
object.propability = det_result->prop;
|
object.propability = det_result->prop;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public slots:
|
|||||||
private:
|
private:
|
||||||
image_buffer_t convertCV2FrameToImageBuffer(const cv::Mat& bgrFrame);
|
image_buffer_t convertCV2FrameToImageBuffer(const cv::Mat& bgrFrame);
|
||||||
void freeImageBuffer(image_buffer_t& imgBuffer);
|
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);
|
void drawObjects(cv::Mat& image, const object_detect_result_list& result_list);
|
||||||
|
|
||||||
rknn_app_context_t mRrknnAppCtx0;
|
rknn_app_context_t mRrknnAppCtx0;
|
||||||
|
|||||||
@@ -666,17 +666,17 @@ int convert_image(image_buffer_t* src_img, image_buffer_t* dst_img, image_rect_t
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
printf("src width=%d height=%d fmt=0x%x virAddr=0x%p fd=%d\n",
|
// 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);
|
// 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",
|
// 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);
|
// dst_img->width, dst_img->height, dst_img->format, dst_img->virt_addr, dst_img->fd);
|
||||||
if (src_box != NULL) {
|
// if (src_box != NULL) {
|
||||||
printf("src_box=(%d %d %d %d)\n", src_box->left, src_box->top, src_box->right, src_box->bottom);
|
// printf("src_box=(%d %d %d %d)\n", src_box->left, src_box->top, src_box->right, src_box->bottom);
|
||||||
}
|
// }
|
||||||
if (dst_box != NULL) {
|
// 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("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("color=0x%x\n", color);
|
||||||
|
|
||||||
ret = convert_image_rga(src_img, dst_img, src_box, dst_box, color);
|
ret = convert_image_rga(src_img, dst_img, src_box, dst_box, color);
|
||||||
if (ret != 0) {
|
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;
|
dst_box.right = dst_box.left + resize_w - 1;
|
||||||
_left_offset = dst_box.left;
|
_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",
|
// 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,
|
// scale, dst_box.left, dst_box.top, dst_box.right, dst_box.bottom, allow_slight_change,
|
||||||
_left_offset, _top_offset, padding_w, padding_h);
|
// _left_offset, _top_offset, padding_w, padding_h);
|
||||||
|
|
||||||
//set offset and scale
|
//set offset and scale
|
||||||
if(letterbox != NULL){
|
if(letterbox != NULL){
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ int inference_yolov8_model(rknn_app_context_t *app_ctx, image_buffer_t *img, obj
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
printf("rknn_run\n");
|
//printf("rknn_run\n");
|
||||||
ret = rknn_run(app_ctx->rknn_ctx, nullptr);
|
ret = rknn_run(app_ctx->rknn_ctx, nullptr);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user