opencv基礎筆記(1)
阿新 • • 發佈:2019-02-05
floatelem_a=a.at<float>(p);//Warning: y ranges from 0 to rows-1 and x from 0 to cols-1
6、多通道Mat元素讀寫
template<typename _Tp> _Tp& at(int y,int x); // cxcore.hpp (868)
template<typename _Tp>const _Tp& at(int y,int x)const; // cxcore.hpp (870)
template<typename _Tp> _Tp& at(Point pt); // cxcore.hpp (869)
template<typename _Tp>const _Tp& at(Point pt)const; // cxcore.hpp (871)
// defineded in cxmat.hpp (454-468)
typedefVec<float,2>Vec2f;// cxcore.hpp (254)
// we can access the element like this :
Mat m(Size(3,3), CV_32FC2 );
Vec2f& elem = m.at<Vec2f>( row , col );// or m.at<Vec2f>( Point(col,row) );
elem[0]=1212.0f;
elem[1]=326.0f;
float c1 = m.at<Vec2f>( row , col )[0];// or m.at<Vec2f>( Point(col,row) );
float c2 = m.at<Vec2f>( row , col )[1];
m.at<Vec2f>( row, col )[0]=1986.0f;
m.at<Vec2f>( row, col )[1]=326.0f;
7.選取Mat上指定區域方法
Mat src; Rect rect;
Mat dst = src(rect); 或者Mat dst(src,rect);
注意:cv::Mat A;
A.row(i) = A.row(j); // 錯誤
A.row(i) = A.row(j) + 0; // 正確