当我试图在OpenCV IOS中为变量赋予属性时,出现了奇怪的崩溃
Weird crash when I try to attribute a variable in OpenCV IOS
有些事情我不明白。我正在为我的IOS设备使用OpenCV IOS。
我有一个带有私有变量cv::Rect
的C++类。这个变量位于我的.h文件中。在.cpp文件中,我有一个创建cv::Rect
的方法。然后,我想将这个新创建的cv::Rect归因于我的类变量,但它崩溃了,我不明白为什么。
.h文件
class detection {
public:
detection();
cv::Mat processImage(cv::Mat frame);
cv::Mat detectFace(cv::Mat frame);
public:
cv::Rect getRectangleDetection();
void setRectangleDetection(cv::Rect& rect);
private:
cv::Rect _rectangeDetect;
};
.cpp文件
cv::Mat detection::processImage(cv::Mat frame){
Mat originalColorImage;
frame.copyTo(originalColorImage);
int cx = frame.cols/2;
int cy = frame.rows/2;
int width = 1000;
int height = 1000;
NSLog(@"[INFO] Rectangle creation");
cv::Rect rect1(cx-width/2, cy-height/2, width,height);
cv::Rect test2;
//test2 = rect1;//It works !
setRectangleDetection(rect1); // or _rectangeDetect = rect1 --> both don't work
cv::rectangle( originalColorImage,rect1,
cv::Scalar(255, 0, 0),4);
return originalColorImage;
}
我看了一眼事故报告,发现:
exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 detect 0x000000010007f580 cv::Rect_<int>::operator=(cv::Rect_<int> const&) (types.hpp:1689)
1 detect 0x000000010007f504 OpenCV::setRectangleDetection(cv::Rect_<int>) (OpenCV.mm:172) //This is the setter but If I'm not using the setter the error will come from _rectangleDetect = rect1.
我还尝试初始化变量cv::Rect,但行为相同。
你知道发生了什么吗?真的,我试图弄清楚为什么,但没有成功。我以前用过很多OpenCv,这是第一次发生这样的事情。
谢谢!
好的,我发现了问题。这是一个愚蠢的决定。事实上,在我的另一个类上,当我使用检测类时,我忘记了初始化对象。
Detection _detect = new Detection()
由于我没有从下面的行中得到任何错误,而且行为似乎很好(即使进行了一些调试(,所以我没有想到这一点。
_detect->processImage(frame);
无论如何,谢谢你们。
相关文章:
- 当回溯以零开始时,如何调试崩溃
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- 内联映射初始化的动态atexit析构函数崩溃
- 执行函数时导致崩溃的变量
- C++概念:如何使用'concept'检查模板化结构的属性?
- 程序崩溃并显示"std::out_of_range"错误
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- CoInitialize()在单独的线程上崩溃而不返回
- 使用调试/崩溃报告将应用程序部署到客户端
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- 为什么所有C++编译器都会崩溃或挂起此代码
- 为什么lambda在clang上崩溃而不是在gcc上崩溃
- 当删除上下文属性中的QLIST对象时,QT QML应用程序崩溃
- UI 按钮 OnClicked 属性编译但导致 UE4 崩溃
- 当我试图在OpenCV IOS中为变量赋予属性时,出现了奇怪的崩溃
- 当不使用某些顶点属性时,glDrawElements崩溃