- 单通道mat元素访问:使用 img.at<float>(row,col)
1 #include2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 using namespace cv; 9 int main()10 {11 Mat img(3, 4, CV_32FC1, Scalar_ (12.625));12 13 cout< < < img.cols; col++)29 {30 cout< (row,col)<<" ";31 }32 cout<
备注1:创建图像Mat时候可以用到
Mat img(3, 4, CV_32FC1, Scalar_(12.625));3乘4的图片~Mat_ 对应的是CV_8U,Mat_ 对应的是CV_8S,Mat_ 对应的是CV_32S,Mat_ 对应的是CV_32F,Mat_ 对应的是CV_64F,对应的数据深度如下: Scalar_<**>的**处填上对应的类型!! CV_8U - 8-bit unsigned integers ( 0..255 ) CV_8S - 8-bit signed integers ( -128..127 ) CV_16U - 16-bit unsigned integers ( 0..65535 ) CV_16S - 16-bit signed integers ( -32768..32767 ) CV_32S - 32-bit signed integers ( -2147483648..2147483647 ) CV_32F - 32-bit ?oating-point numbers ( -FLT_MAX..FLT_MAX, INF, NAN ) CV_64F - 64-bit ?oating-point numbers ( -DBL_MAX..DBL_MAX, INF, NAN )
备注2
因为单通道,所以上例访问元素时候对应写成
img.at(row,col)
...
- 多通道mat元素访问:
1 #include2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 using namespace cv; 9 int main()10 {11 Mat img(3, 4, CV_64FC2, Scalar_ (12.625,3.141592653));12 //Mat_(Vec)13 cout< < < img.cols; col++)28 {29 cout< (row,col)[0]<<" "< (row,col)[1]<<"\t";30 }31 cout<
备注3:创建图像Mat时候,注意点同上~
备注4:使用at时img.at<**>(row,col)的**处对应选项~
typedef VecVec2b;typedef Vec Vec3b;typedef Vec Vec4b;typedef Vec Vec2s;typedef Vec Vec3s;typedef Vec Vec4s;typedef Vec Vec2w;typedef Vec Vec3w;typedef Vec Vec4w;typedef Vec Vec2i;typedef Vec Vec3i;typedef Vec Vec4i;typedef Vec Vec6i;typedef Vec Vec8i;typedef Vec Vec2f;typedef Vec Vec3f;typedef Vec Vec4f;typedef Vec Vec6f;typedef Vec Vec2d;typedef Vec Vec3d;typedef Vec Vec4d;typedef Vec Vec6d;
题外话:
我一次Mat img(3,4,CV8S,~)....而访问时候,用的img.at<int>(i,j)出现访存错误,我的本意是用CV32S,不对应就会出现访存错误。。。