docs: Update README and compilation guides for clarity and consistency, including path corrections and improved formatting. Add copyright notices to source files and adjust file permissions for several scripts and directories.

This commit is contained in:
dian.yuan 2026-02-28 11:06:26 +08:00
parent f960c5030d
commit bd891a96dd
136 changed files with 14413 additions and 9399 deletions

View file

@ -1,36 +1,36 @@
cmake_minimum_required(VERSION 3.10...3.27)
project(yolo_world_demo)
set(CMAKE_CXX_STANDARD 17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../../../cmake")
find_package(AMLNN REQUIRED)
include_directories(${AMLNN_INCLUDE_DIR})
link_directories(${AMLNN_LIBRARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/../../../../common)
# Set 3rdparty path
set(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../../../../dependency")
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
# Android needs log
link_libraries(log)
endif()
# Find OpenCV
message(STATUS "OpenCV_DIR: ${OpenCV_DIR}")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(yolov8_demo
main.cpp
postprocess.cpp
postprocess.h
${CMAKE_SOURCE_DIR}/../../../../common/model_loader.cpp
)
target_link_libraries(yolov8_demo
${OpenCV_LIBS}
${AMLNN_LIBRARY}
)
cmake_minimum_required(VERSION 3.10...3.27)
project(yolo_world_demo)
set(CMAKE_CXX_STANDARD 17)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/../../../../cmake")
find_package(AMLNN REQUIRED)
include_directories(${AMLNN_INCLUDE_DIR})
link_directories(${AMLNN_LIBRARY_DIR})
include_directories(${CMAKE_SOURCE_DIR}/../../../../common)
# Set 3rdparty path
set(3RDPARTY_DIR "${CMAKE_SOURCE_DIR}/../../../../dependency")
if(CMAKE_SYSTEM_NAME STREQUAL "Android")
# Android needs log
link_libraries(log)
endif()
# Find OpenCV
message(STATUS "OpenCV_DIR: ${OpenCV_DIR}")
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(yolov8_demo
main.cpp
postprocess.cpp
postprocess.h
${CMAKE_SOURCE_DIR}/../../../../common/model_loader.cpp
)
target_link_libraries(yolov8_demo
${OpenCV_LIBS}
${AMLNN_LIBRARY}
)

View file

@ -100,7 +100,7 @@ int main(int argc, char** argv) {
float* outbuf2 = (float*)outdata->out[2].buf;
const int channels = 144; // 64 DFL + 80 classes
std::vector<Detection> detections = postprocess(
std::make_tuple(outbuf0, std::make_tuple(MODEL_INPUT_HEIGHT / 8, MODEL_INPUT_WIDTH / 8, channels), 8),
std::make_tuple(outbuf1, std::make_tuple(MODEL_INPUT_HEIGHT / 16, MODEL_INPUT_WIDTH / 16, channels), 16),

View file

@ -59,7 +59,7 @@ static float compute_iou(const Detection& det1, const Detection& det2) {
float area1 = (det1.x2 - det1.x1) * (det1.y2 - det1.y1);
float area2 = (det2.x2 - det2.x1) * (det2.y2 - det2.y1);
return inter / (area1 + area2 - inter);
}
@ -96,7 +96,7 @@ static std::vector<Detection> nms_by_class(const std::vector<Detection>& detecti
std::tuple<cv::Mat, float, std::tuple<int, int>> preprocess(cv::Mat img, std::tuple<int, int> new_shape) {
cv::Mat img_rgb;
if (img.empty()) {
LOGE("Preprocess received empty image");
return {};
@ -128,7 +128,7 @@ std::tuple<cv::Mat, float, std::tuple<int, int>> preprocess(cv::Mat img, std::tu
int pad_bottom = static_cast<int>(round(pad_h / 2.0 + 0.1));
cv::Mat img_padded;
cv::copyMakeBorder(img_resized, img_padded, pad_top, pad_bottom, pad_left, pad_right,
cv::copyMakeBorder(img_resized, img_padded, pad_top, pad_bottom, pad_left, pad_right,
cv::BORDER_CONSTANT, cv::Scalar(114, 114, 114));
cv::Mat img_float;
@ -155,14 +155,14 @@ cv::Mat quantize_input(const cv::Mat& float_img, float scale, int8_t zero_point)
return quantized_img;
}
static std::vector<Detection> get_detections(float* output, std::tuple<int, int, int> output_shape,
static std::vector<Detection> get_detections(float* output, std::tuple<int, int, int> output_shape,
int stride, float conf_thresh) {
std::vector<Detection> detections;
int grid_h = std::get<0>(output_shape);
int grid_w = std::get<1>(output_shape);
int channels = std::get<2>(output_shape);
const int num_classes = 80;
const int dfl_channels = 64; // 4 directions * 16 bins
@ -288,9 +288,9 @@ cv::Mat draw_detections(cv::Mat image, const std::vector<Detection>& detections)
cv::Scalar color(rgb.at<cv::Vec3b>(0, 0)[0], rgb.at<cv::Vec3b>(0, 0)[1], rgb.at<cv::Vec3b>(0, 0)[2]);
// Draw bounding box
cv::rectangle(drawn_image,
cv::rectangle(drawn_image,
cv::Point(static_cast<int>(det.x1), static_cast<int>(det.y1)),
cv::Point(static_cast<int>(det.x2), static_cast<int>(det.y2)),
cv::Point(static_cast<int>(det.x2), static_cast<int>(det.y2)),
color, 2);
// Draw label
@ -304,17 +304,17 @@ cv::Mat draw_detections(cv::Mat image, const std::vector<Detection>& detections)
label_y = static_cast<int>(det.y1) + text_size.height + 5;
// Draw label background
cv::rectangle(drawn_image,
cv::rectangle(drawn_image,
cv::Point(label_x, label_y - text_size.height - baseline),
cv::Point(label_x + text_size.width, label_y + baseline),
cv::Point(label_x + text_size.width, label_y + baseline),
color, cv::FILLED);
// Determine text color based on background brightness
int brightness = (color[0] + color[1] + color[2]) / 3;
cv::Scalar text_color = brightness < 128 ? cv::Scalar(255, 255, 255) : cv::Scalar(0, 0, 0);
cv::putText(drawn_image, label,
cv::Point(label_x, label_y),
cv::putText(drawn_image, label,
cv::Point(label_x, label_y),
cv::FONT_HERSHEY_SIMPLEX, 0.6, text_color, 1, cv::LINE_AA);
}
return drawn_image;