1. Mask 사용

CopyTo를 이용

ex) 

cv::Mat MaskClone(cv::Mat &_Src, const cv::Mat &_Mask, cv::Scalar Def)

{

Mat NewMat(_Src.size(), _Src.type(), Def);


_Src.copyTo(NewMat, _Mask);


return NewMat;

}


2. Mat 내부 벡터 초기화

Mat_ 초기화 사용

ex)

m_CameraMatrix = (Mat_<float>(4, 4) <<

_fu, 0, _cu, 0, 

0, _fv, _cv, 0,

0, 0, 0, _fu*_base,

0, 0, 1, 0);


3. Vector to Mat, Mat to Vector

Mat a(Vector<Point2f>)로 초기화시에 생성되는 Mat의 크기는 cols = 1 rows =  vector.size

ex)

cv::Mat CvtKeyPoints2PosMat(vector<KeyPoint> &_Src)

{

vector<Point2f> Src_Vector;

KeyPoint::convert(_Src, Src_Vector);

Mat Src_Channel[2];

split(Mat(Src_Vector).t(), Src_Channel);


return JMU::VCat(Src_Channel[0], Src_Channel[1]);

}


4. Reshape (Vector -> Mat)


5. Reshape (Mat -> Vector)


6. Unique 

딱히 Uniqe 함수는 없으며 std의 unique를 사용해야한다. (General하게 Mat을 받는 것은 차후에)

ex) unique한 mask를 생성

template<typename _Ty>

cv::Mat HUniq_PosMat(const cv::Mat &_Src)

{

assert(_Src.rows == 2);

Mat Temp = VCat(_Src, MakeSeq<_Ty>(Size(_Src.cols, 1)));

Temp = Temp.reshape(3, 1);


vector<Point3_<_Ty>> VecTemp(Temp.begin<Point3_<_Ty>>(), Temp.end<Point3_<_Ty>>());


std::unique(VecTemp.begin(), VecTemp.end(), 

[](const Point3_<_Ty> &a, const Point3_<_Ty> &b)

{

return a.x==b.x && a.y==b.y;

});

Mat Mask = Mat::zeros(1, _Src.cols, CV_8UC1);

unsigned char *pMask = Mask.data;


for(int i=0; i<VecTemp.size(); i++)

{

pMask[int(VecTemp[i].z)] = 1;

}


return Mask;

}

by 고민고민하지마~* 2014. 7. 18. 12:43