fix image.resize_map_pos bug and change image.resize's param object_fit to fit

This commit is contained in:
Neucrack
2025-08-13 16:41:33 +08:00
parent fe93759783
commit 9cac67a852
5 changed files with 29 additions and 8 deletions

View File

@@ -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")
{

View File

@@ -0,0 +1,20 @@
#pragma once
#include <string>
#include <vector>
namespace maix::peripheral::uart
{
std::vector<std::string> maix_uart_port_get_ports()
{
return std::vector<std::string>{
"/dev/ttyS0",
"/dev/ttyS1",
"/dev/ttyS2",
"/dev/ttyS3"
};
}
}

View File

@@ -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<int> get_sensor_size();

View File

@@ -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.

View File

@@ -1978,9 +1978,9 @@ __EXIT:
std::vector<int> 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<int> result;
float scale_x = static_cast<float>(w_out) / w_in;
float scale_y = static_cast<float>(h_out) / h_in;
std::vector<int> 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<int>((w_out - w_in * scale) / 2 + x * scale);
y = static_cast<int>(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<int>(x * scale);
y = static_cast<int>((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<int>((x - (w_out - w_in * scale) / 2) / scale);
y = static_cast<int>(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<int>(x / scale);
y = static_cast<int>((y - (h_out - h_in * scale) / 2) / scale);