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

cv::cvtColor crash! #86

Open
xiaozhi003 opened this issue Jan 18, 2024 · 4 comments
Open

cv::cvtColor crash! #86

xiaozhi003 opened this issue Jan 18, 2024 · 4 comments

Comments

@xiaozhi003
Copy link

使用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大神有空帮忙看下呗,万分感谢!!!

@nihui
Copy link
Owner

nihui commented Jan 18, 2024

opencv-mobile 不会检查 ROI 超出图片范围
在 crop 的时候,要先检查 crop_rect 是否合理

@xiaozhi003
Copy link
Author

opencv-mobile 不会检查 ROI 超出图片范围 在 crop 的时候,要先检查 crop_rect 是否合理

ROI区域如果有问题(我这边模拟过ROI区域错误的方式),应该就直接崩溃在rgb(crop_rect).copyTo(crop_face);这行了,裁剪图片就过不了,就不会往下走到cvtColor;现在是裁剪没有崩溃,崩溃在了cvtColor里面了;

@nihui
Copy link
Owner

nihui commented Jan 19, 2024

https://github.com/nihui/opencv-mobile#some-notes
opencv-mobile 没有开 exception,你得自己检查roi

@xiaozhi003
Copy link
Author

https://github.com/nihui/opencv-mobile#some-notes opencv-mobile 没有开 exception,你得自己检查roi

好的,roi我这边检查下,线上再跑跑看看cvtColor还会不会崩溃吧

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

2 participants