花了好几个小时的奇葩Mat为0问题

问题 

1、

Mat mserMat = adaptive_image_from_points(contour, rect);
CCharacter character;
character.setCharacterMat(mserMat);
//character.m_characterPos = rect;

vecShapeSelectionSCharacter.push_back(character);
//cout << vecShapeSelectionSCharacter[0].getCharacterMat().size() << endl;
//cout << vecShapeSelectionCCharacter.front().getCharacterMat().size() << endl;
}

打印

[0 x 0]

[0 x 0]

[0 x 0]

解决

class CCharacter {
public:
CCharacter(Mat &mserMat)
{
m_characterMat = Mat();
m_characterMat = mserMat.clone();
m_characterPos = Rect();
m_characterStr = "";
m_score = 0;
}

CCharacter(const CCharacter& other)
{

这个缺了个m_characterMat = other.m_characterMat;要不就没有这个拷贝构造函数也行
m_characterPos = other.m_characterPos;
m_characterStr = other.m_characterStr;
m_score = other.m_score;
}

原因push_back会调用拷贝构造

原文地址:https://www.cnblogs.com/fdd566/p/6733329.html