0

我正在尝试找出程序崩溃问题的原因。

此崩溃发生在几个小时的执行后。我使用 gdb 运行它,它告诉我它在哪一行代码中崩溃了。Gdb 告诉我该程序在以下行有一个浮点异常段错误:

(*itCand)->setCandidateObjectData(centroid,
                                    (*itCand)->_toSendCentroid,
                                    bbox,
                                    sumAreaFilled,
                                    sumAreaEdges,
                                    height ,
                                    (*itCand)->_sumAreaMask / (*itCand)->_nTimesAlive,
                                    (*itCand)->_sumAreaEdges / (*itCand)->_nTimesAlive,
                                    (*itCand)->_sumHeight / (*itCand)->_nTimesAlive ,
                                    sumAreaEdges,
                                    height,
                                    maxHeight,
                                    false,
                                    false,
                                    false,
                                    true,
                                    hasChangedPosition);

此函数将数据分配给对象。参数 sumAreaFilled、sumAreaEdges 和 height 是增量参数,在执行过程中每秒都在增加,因此它们是 unsigned long long 类型,以避免任何内存问题。

参数 nTimesAlive 初始化为 1,并且每帧也不断递增,因此它永远不会为零。

其余的操作都是简单的分配,所以我认为它们不是任何问题的根源,但我会粘贴函数和数据类型,以便您可以获得掌握问题所需的所有信息。

class CandidateObject
{
public:
    CandidateObject(const cv::Point centroid, const cv::Rect bboxNormal);

    ~CandidateObject();

    void setCandidateObjectData(const cv::Point centroid, const cv::Point toSendCentroid, const cv::Rect bboxNormal,
            const unsigned long long sumAreaMask, const unsigned long long sumAreaEdges, const unsigned long long sumHeight,
            const double meanAreaMask, const double meanAreaEdges, const double meanHeight, const double instantEdgeArea, const double height,
            const double maxHeight, const bool isToDelete, const bool isDuplicate, const bool isBeingDoubleChecked, const bool isMatched,
            const bool hasChangedPosition);

    cv::Point _centroid;                //-- blob centroid
    cv::Point _toSendCentroid;          //-- blob centroid to send to the conversion function
    cv::Rect _bboxNormal;               //-- normal bounding box
    unsigned long long _sumAreaMask;    //-- pixel sum on object bounding box mask
    unsigned long long _sumAreaEdges;   //-- pixel sum on edge
    unsigned long long _sumHeight;      //-- sum of height instances
    double _meanAreaMask;               //-- mean of total instances of object area in bounding box mask
    double _meanEdgeAreaMask;           //-- mean of total instances of object area in the edge bounding box mask
    double _meanHeight;                 //-- mean of total instances of object height
    double _instantEdgeArea;            //-- Area of edges that correspond to a certain object
    unsigned short _nTimesAlive;        //-- number of times blob appears
    bool _isToDelete;                   //-- flag that indicates if candidate object is no longer valid and to be deleted from vector
    bool _isDuplicate;                  //-- indicates if same object is detected multiple times
    bool _isBeingDoubleChecked;         //-- indicates if object is being double checked after first matching fails
    bool _isMatched;                    //-- indicates if object has already been matched, in order to avoid unnecessary processing
    bool _hasChangedPosition;           //-- indicates if the object has changed its position significantly
    double _height;                     //-- object height
    double _maxHeight;                  //-- max height
    unsigned int _label;
};

和功能:

void CandidateObject::setCandidateObjectData(const cv::Point centroid, const cv::Point toSendCentroid, const cv::Rect bboxNormal,
        const unsigned long long sumAreaMask, const unsigned long long sumAreaEdges, const unsigned long long sumHeight,
        const double meanAreaMask, const double meanAreaEdges, const double meanHeight, const double instantEdgeArea, const double height,
        const double maxHeight, const bool isToDelete, const bool isDuplicate, const bool isBeingDoubleChecked, const bool isMatched, const bool hasChangedPosition)
{
    _centroid = centroid;
    _toSendCentroid = toSendCentroid;
    _bboxNormal = bboxNormal;
    _sumAreaMask += sumAreaMask;
    _sumAreaEdges += sumAreaEdges;
    _sumHeight += sumHeight;
    _meanAreaMask = meanAreaMask;
    _meanEdgeAreaMask = meanAreaEdges;
    _meanHeight = meanHeight;
    _instantEdgeArea = instantEdgeArea;
    _isToDelete = isToDelete;
    _isDuplicate = isDuplicate;
    _isBeingDoubleChecked = isBeingDoubleChecked;
    _isMatched = isMatched;
    _height = height;
    _maxHeight = maxHeight;
    _hasChangedPosition = hasChangedPosition;

    return;
}
4

1 回答 1

1

看起来问题发生在控件到达函数体之前。所以我认为最可能的错误来源在以下几行中:

(*itCand)->_sumAreaMask / (*itCand)->_nTimesAlive,
(*itCand)->_sumAreaEdges / (*itCand)->_nTimesAlive,
(*itCand)->_sumHeight / (*itCand)->_nTimesAlive ,

使用 GDB,您可以检查指向 itCand 的指针是否有效,以及发生异常时 _nTimesAlive 的值是多少。您也可以尝试在函数调用之前声明 3 个临时变量来保存这 3 个计算结果,然后将它们传递给函数。因此,您将使 GDB 报告导致问题的确切行并收集有关故障的更多详细信息。

于 2014-04-04T10:03:00.530 回答