From 9cac67a8525e29104e0e27d110e7004f913e1d34 Mon Sep 17 00:00:00 2001 From: Neucrack Date: Wed, 13 Aug 2025 16:41:33 +0800 Subject: [PATCH] fix image.resize_map_pos bug and change image.resize's param object_fit to fit --- components/ext_devs/ext_dev/src/maix_imu.cpp | 2 +- .../port/maixcam/maix_uart_port.cpp | 20 +++++++++++++++++++ components/vision/include/maix_camera.hpp | 1 + components/vision/include/maix_image.hpp | 4 ++-- components/vision/src/maix_image.cpp | 10 +++++----- 5 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 components/peripheral/port/maixcam/maix_uart_port.cpp diff --git a/components/ext_devs/ext_dev/src/maix_imu.cpp b/components/ext_devs/ext_dev/src/maix_imu.cpp index c80974db..9e172b5d 100644 --- a/components/ext_devs/ext_dev/src/maix_imu.cpp +++ b/components/ext_devs/ext_dev/src/maix_imu.cpp @@ -94,7 +94,7 @@ IMU::IMU(std::string driver, int i2c_bus, int addr, int freq, imu::Mode mode, im bool found = false; - if(driver == "default") + if(driver.empty() || driver == "default") { if(sys::device_id() == "maixcam_pro") { diff --git a/components/peripheral/port/maixcam/maix_uart_port.cpp b/components/peripheral/port/maixcam/maix_uart_port.cpp new file mode 100644 index 00000000..2ebf08bd --- /dev/null +++ b/components/peripheral/port/maixcam/maix_uart_port.cpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + + +namespace maix::peripheral::uart +{ + std::vector maix_uart_port_get_ports() + { + return std::vector{ + "/dev/ttyS0", + "/dev/ttyS1", + "/dev/ttyS2", + "/dev/ttyS3" + }; + } +} + + diff --git a/components/vision/include/maix_camera.hpp b/components/vision/include/maix_camera.hpp index 381510d1..09a954ed 100644 --- a/components/vision/include/maix_camera.hpp +++ b/components/vision/include/maix_camera.hpp @@ -429,6 +429,7 @@ namespace maix::camera /** * Get sensor size * @return Return a list of sensor sizes, the format is [w, h]. + * @maixpy maix.camera.Camera.get_sensor_size */ std::vector get_sensor_size(); diff --git a/components/vision/include/maix_image.hpp b/components/vision/include/maix_image.hpp index 75a46a10..a7442314 100644 --- a/components/vision/include/maix_image.hpp +++ b/components/vision/include/maix_image.hpp @@ -532,7 +532,7 @@ namespace maix::image * Resize image, will create a new resized image object * @param width new width, if value is -1, will use height to calculate aspect ratio * @param height new height, if value is -1, will use width to calculate aspect ratio - * @param object_fit fill, contain, cover, by default is fill + * @param fit fill, contain, cover, by default is fill * @param method resize method, by default is NEAREST * @return Always return a new resized image object even size not change, So in C++ you should take care of the return value to avoid memory leak. * And it's better to judge whether the size has changed before calling this function to make the program more efficient. @@ -541,7 +541,7 @@ namespace maix::image * img = img->resize(width, height); * @maixpy maix.image.Image.resize */ - image::Image *resize(int width, int height, image::Fit object_fit = image::Fit::FIT_FILL, image::ResizeMethod method = image::ResizeMethod::NEAREST); + image::Image *resize(int width, int height, image::Fit fit = image::Fit::FIT_FILL, image::ResizeMethod method = image::ResizeMethod::NEAREST); /** * Affine transform image, will create a new transformed image object, need 3 points. diff --git a/components/vision/src/maix_image.cpp b/components/vision/src/maix_image.cpp index 7378706e..77b02ed3 100644 --- a/components/vision/src/maix_image.cpp +++ b/components/vision/src/maix_image.cpp @@ -1978,9 +1978,9 @@ __EXIT: std::vector resize_map_pos(int w_in, int h_in, int w_out, int h_out, image::Fit fit, int x, int y, int w, int h) { + std::vector result; float scale_x = static_cast(w_out) / w_in; float scale_y = static_cast(h_out) / h_in; - std::vector result; if (fit == image::Fit::FIT_FILL) { @@ -1998,7 +1998,7 @@ __EXIT: else if (fit == image::Fit::FIT_CONTAIN) { float scale = std::min(scale_x, scale_y); - if (w_out > h_out) + if (scale_x > scale_y) { x = static_cast((w_out - w_in * scale) / 2 + x * scale); y = static_cast(y * scale); @@ -2017,7 +2017,7 @@ __EXIT: else if (fit == image::Fit::FIT_COVER) { float scale = std::max(scale_x, scale_y); - if (w_out > h_out) + if (scale_x > scale_y) { x = static_cast(x * scale); y = static_cast((h_out - h_in * scale) / 2 + y * scale); @@ -2071,7 +2071,7 @@ __EXIT: else if (fit == image::Fit::FIT_CONTAIN) { float scale = std::min(scale_x, scale_y); - if (w_out > h_out) + if (scale_x > scale_y) { x = static_cast((x - (w_out - w_in * scale) / 2) / scale); y = static_cast(y / scale); @@ -2090,7 +2090,7 @@ __EXIT: else if (fit == image::Fit::FIT_COVER) { float scale = std::max(scale_x, scale_y); - if (w_out > h_out) + if (scale_x > scale_y) { x = static_cast(x / scale); y = static_cast((y - (h_out - h_in * scale) / 2) / scale);