opencv-mobile icon indicating copy to clipboard operation
opencv-mobile copied to clipboard

cv::cvtColor crash!

Open xiaozhi003 opened this issue 1 year ago • 4 comments

使用opencv版本:3.4.20 线上so库偶发崩溃SIGTRAP 分析调用堆栈如下:

llvm-addr2line -C -f -e libxxxx.so 17d618 17d614 17de2c aac18
cv::errorNoReturn(int, cv::String const&, char const*, char const*, int)
color.cpp:0
cv::errorNoReturn(int, cv::String const&, char const*, char const*, int)
color.cpp:0
cv::cvtColor(cv::_InputArray const&, cv::_OutputArray const&, int, int)
color.cpp:0
getAttribute
/xxx/./src/OFace.cpp:335

发现是通过cvtColor转换RGB为GRAY崩溃 OFace.cpp调用代码如下:

cv::Mat rgb(hCtx->nHi, hCtx->nWd, CV_8UC3, (unsigned char*)hCtx->hCur);
cv::Mat crop_face;
cv::Mat gray_face;
cv::Rect crop_rect;
...
crop_rect.x = (int)info.rect.x;
crop_rect.y = (int)info.rect.y;
crop_rect.width = (int)info.rect.width;
crop_rect.height = (int)info.rect.height;
rgb(crop_rect).copyTo(crop_face);
cv::cvtColor(crop_face, gray_face, CV_RGB2GRAY);

分析opencv源码 /modules/imgproc/src/color.cpp中的cvtColor函数

void cvtColor( InputArray _src, OutputArray _dst, int code, int dcn )
{
    CV_INSTRUMENT_REGION();

    CV_Assert(!_src.empty()); // 排查发现有可能是这里崩溃,传入一个空的mat确实生成的崩溃堆栈和线上相同

    if(dcn <= 0)
            dcn = dstChannels(code);
...
}

如上分析,进行模拟让crop_face为空,但是没有模拟出来,也就是rgb(crop_rect).copyTo(crop_face);拷贝后crop_face为空,但是不理解为什么会出现这种情况?或者是否是别的地方的问题?nihui大神有空帮忙看下呗,万分感谢!!!

xiaozhi003 avatar Jan 18 '24 09:01 xiaozhi003