PaddlePaddle / FlyCV

FlyCV is a high-performance library for processing computer visual tasks.
Apache License 2.0
580 stars 61 forks source link

cvt_color 转换格式 bgr2yuv #186

Closed snow-tyan closed 1 year ago

snow-tyan commented 1 year ago

平台: ARM64 版本: release/v1.1.0

 fcv::Mat fcv_img = fcv::imread(image_path);
  printf("image width=%d, height=%d, channels=%d\n", fcv_img.width(), fcv_img.height(),
         fcv_img.channels());

  int padding_h = (fcv_img.height() + 1) / 2 * 2 - fcv_img.height();
  int padding_w = (fcv_img.width() + 1) / 2 * 2 - fcv_img.width();
  fcv::copy_make_border(fcv_img, fcv_img, 0, padding_h, 0, padding_w,
                        fcv::BorderType::BORDER_CONSTANT, fcv::Scalar(114, 114, 114));

  fcv::Mat fcv_yuv_img;
  fcv::cvt_color(fcv_img, fcv_yuv_img, fcv::ColorConvertType::CVT_PA_BGR2NV21);
  printf("yuv image width=%d, height=%d, channels=%d\n", fcv_yuv_img.width(), fcv_yuv_img.height(),
         fcv_yuv_img.channels());

跑到 padding 的时候会崩掉:gdb

Using host libthread_db library "/lib/aarch64-linux-gnu/libthread_db.so.1".
image width=2048, height=1365, channels=3

Program received signal SIGSEGV, Segmentation fault.
__memcpy_generic () at ../sysdeps/aarch64/multiarch/../memcpy.S:185
185     ../sysdeps/aarch64/multiarch/../memcpy.S: No such file or directory.
(gdb) bt
#0  __memcpy_generic () at ../sysdeps/aarch64/multiarch/../memcpy.S:185
#1  0x0000000000415b58 in fcv::copy_make_border_common(fcv::Mat&, fcv::Mat&, int, int, int, int, fcv::BorderType, fcv::Scalar_<double> const&)
    ()
#2  0x0000000000414394 in fcv::copy_make_border(fcv::Mat&, fcv::Mat&, int, int, int, int, fcv::BorderType, fcv::Scalar_<double> const&) ()
#3  0x0000000000405dec in MiniPadding (img=...) at /home/work/AtlasProjects/MaiAtlas/flycv_test/convert_test.cpp:23
#4  0x0000000000405f18 in main (argc=3, argv=0xfffffffff038) at /home/work/AtlasProjects/MaiAtlas/flycv_test/convert_test.cpp:40

另外,有时候会崩在cvt_color处 w=2048, h=1365 padding成功 w=2048, h=1366

Thread 1 "test" received signal SIGSEGV, Segmentation fault.
_int_malloc (av=av@entry=0xfffeff8e3a70 <main_arena>, bytes=bytes@entry=638400) at malloc.c:3924
3924    malloc.c: No such file or directory.
(gdb) bt
#0  _int_malloc (av=av@entry=0xfffeff8e3a70 <main_arena>, bytes=bytes@entry=638400) at malloc.c:3924
#1  0x0000fffeff807444 in __GI___libc_malloc (bytes=638400) at malloc.c:3075
#2  0x000000000065e720 in fcv::cpu_allocator::cpu_allocator(unsigned long) ()
#3  0x000000000065e284 in fcv::get_allocator_from_platform(unsigned long, fcv::PlatformType, int) ()
#4  0x000000000064ce68 in fcv::Mat::Mat(int, int, fcv::FCVImageType, int, fcv::PlatformType) ()
#5  0x000000000064d7ac in fcv::cvt_color(fcv::Mat const&, fcv::Mat&, fcv::ColorConvertType) ()

test

TomasRan commented 1 year ago

fcv::copy_make_border(fcv_img, fcv_img, 0, padding_h, 0, padding_w, fcv::BorderType::BORDER_CONSTANT, fcv::Scalar(114, 114, 114)); flycv接口设计上输入和输出需要是不同的对象,所以不能使用fcv_img既做输入又做输出,可以声明一个dst变量传入。

snow-tyan commented 1 year ago

fcv::copy_make_border(fcv_img, fcv_img, 0, padding_h, 0, padding_w, fcv::BorderType::BORDER_CONSTANT, fcv::Scalar(114, 114, 114)); flycv接口设计上输入和输出需要是不同的对象,所以不能使用fcv_img既做输入又做输出,可以声明一个dst变量传入。

明白了,感谢回复