0

I've read a few posts about Mat element access and had some trials but all failed. Could someone give me a hint?

Mat vect(1,3, CV_32FC1);     
typedef Vec<float,1> Vec1f;  //**
// access ele. at (1,1)
vect.at<Vec1f>( Point(1,1 )) = 5;  // I used 1 channel so I defined a new element type as a workaround

I adapted the code from this post opencv multi channel element access

And, I though thet line //** can be declared like:

typedef Vec<float> Vec1f;

according to line 582 in core.hpp: Vec(_Tp v0); //!< 1-element vector constructor

However, it also doesn't work

I applied the same method for 2D matrix then it is fine:

Mat warp_mat(2,3, CV_32FC1);
typedef Vec<float,1> Vec1f;

warp_mat.at<Vec1f>( Point(0,0 )) = 1;
warp_mat.at<Vec1f>( Point(1,0 )) = 2;
warp_mat.at<Vec1f>( Point(2,0 )) = 5;
warp_mat.at<Vec1f>( Point(0,1 )) = 4;
warp_mat.at<Vec1f>( Point(1,1 )) = 5;
warp_mat.at<Vec1f>( Point(2,1 )) = 0;

it works OK!

Community
  • 1
  • 1
TSL_
  • 2,049
  • 3
  • 34
  • 55

1 Answers1

0

http://aishack.in/tutorials/opencvs-c-interface/

Mat a= Mat(4,3, CV_32FC1);

float elem_a= a.at(i,j); //access element aij, with i from 0 to rows-1 and j from 0 to cols-1

Utkarsh Sinha
  • 3,295
  • 4
  • 30
  • 46
plan9assembler
  • 2,862
  • 1
  • 24
  • 13
  • actually, I've tried 'at' function but it does not work this way. The one that works is: frame.at(30,10). Type, here is uchar, must be put at front. – TSL_ Mar 30 '12 at 07:52
  • Another problem I'm having is: that matrix is a real image with 3 channels matrix.at(i,j) gives access to element i,j but which channel?? how can I access each channel I want?? – TSL_ Mar 30 '12 at 07:54
  • "If you’re dealing with a multi-channel Mat, things are a little more complex. But still easier than the CV_MAT_ELEM or CV_IMAGE_ELEM macros. You must use the ptr method to obtain a pointer to a particular row. Then you use the [] to access a particular pixel in a particular channel:" type elem = matrix.ptr(i)[Nc*j+c] – plan9assembler Apr 07 '12 at 03:06
  • my current choice is using "at" of Mat matrix. It works pretty OK – TSL_ Apr 08 '12 at 08:11