Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

前处理后图像发生部分列像素从右侧边界位移到左侧边界 #2386

Closed
neptune4year opened this issue May 23, 2023 · 5 comments

Comments

@neptune4year
Copy link

neptune4year commented May 23, 2023

平台(如果交叉编译请再附上交叉编译目标平台):

Platform(Include target platform as well if cross-compiling):

Android

Github版本: 2.2

编译方式: cmake build

Compiling Method

前处理过程:将相机图片转换为垂直,并转为RGB,长边等比例居中缩放到256,短边两侧补0
代码:
int _size = 256;
int w = 720;
int h = 1280;
int rotation = 0;
const float means[3] = {103.53f, 116.535f, 122.40f};
const float normals[3] = {0.01743f, 0.01751f, 0.01712f};
auto pretreat = std::shared_ptrMNN::CV::ImageProcess(
MNN::CV::ImageProcess::create(MNN::CV::RGBA, MNN::CV::RGB, means, 3, normals, 3));
auto fit = MNN::CV::Matrix::ScaleToFit::kCenter_ScaleToFit;
MNN::CV::Matrix matrix = MNN::CV::Matrix::MakeRectToRect(
MNN::CV::Rect::MakeIWH(w, h),MNN::CV::Rect::MakeIWH(_size, _size), fit);

matrix.postRotate(rotation, _size / 2, _size / 2);
if (0) {
matrix.postScale(1.0/_size, 1.0/_size);
matrix.postScale(-1.0, 1.0, 0.5, 0.0);
matrix.postScale(_size, _size);
}
matrix.invert(&matrix);
pretreat->setMatrix(matrix);
auto input = _net->getSessionInput(_session, nullptr);
pretreat->convert(pImage, w, h, 0, input);

输出结果:
lQLPJwGl2oIG8_7NAfrNAfyw3dJ7arQ538kEYlUYbUDTAA_508_506
正确结果应为:
lQLPJw-uW5Xj577NAf7NAfywKVA_bwi7jD4EYlVJvADQAA_508_510
麻烦帮忙查一下问题所在

@jxt1234
Copy link
Collaborator

jxt1234 commented May 23, 2023

原始图片也放上来吧

@neptune4year
Copy link
Author

原始图片也放上来吧

dfad

@v0jiuqi
Copy link
Collaborator

v0jiuqi commented Jun 1, 2023

hi, 我用你的代码转图片结果显示正常,代码提供给你
`auto angle = 0;
int destSize = 256;
int width = 720, height = 1280;
auto fit = Matrix::ScaleToFit::kCenter_ScaleToFit;

MNN_PRINT("size: %d, %d\n", width, height);
Matrix trans;
trans = MNN::CV::Matrix::MakeRectToRect(
MNN::CV::Rect::MakeIWH(width, height),MNN::CV::Rect::MakeIWH(destSize, destSize), fit);

trans.postRotate(angle, destSize / 2, destSize / 2);
trans.invert(&trans);

CV::ImageProcess::Config _config;
_config.sourceFormat = CV::RGBA;
_config.destFormat   = CV::RGB;
_config.filterType   = CV::NEAREST;
_config.wrap         = CV::ZERO;

std::shared_ptr<ImageProcess> pretreat(ImageProcess::create(_config));
pretreat->setMatrix(trans);
{
    std::shared_ptr<Tensor> wrapTensor(ImageProcess::createImageTensor<uint8_t>(destSize, destSize, 3, nullptr));
    pretreat->convert((uint8_t*)inputImage, width, height, 0, wrapTensor.get());
    stbi_write_png(savePath destSize, destSize, 3, wrapTensor->host<uint8_t>(), 0);
}`

@v0jiuqi
Copy link
Collaborator

v0jiuqi commented Jun 1, 2023

cvtest_output
这是我转换的结果

@neptune4year
Copy link
Author

感谢,我们找到问题所在了,MNN::CV::Rect::MakeIWH(width, height),MNN::CV::Rect::MakeIWH(destSize, destSize), fit);
这里的size好像需要-1,我们这里才能获得正确结果

@jxt1234 jxt1234 closed this as completed Jun 25, 2023
This was referenced Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants