Ask Your Question
1

Access and save information in Mat Array

asked 2017-02-23 03:47:25 -0600

zms gravatar image

i have declared a mat and i need to access and change the value one by one.

Mat M(1,63, CV_8UC1, Scalar(0,255,0));

and

 M.at<double>(1,i)=<data>;i++;

It does not work. Anyone can gelp?

Rgds Zamani

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-02-23 03:58:57 -0600

berak gravatar image

"It does not work." -- no wonder. well, almost everything is wrong in you current attempt.

  1. if your Mat is of type 8UC1(single channel), initializing it with a 3 channel Scalar(0,255,0) does not make any sense (only the 1st 0 will be used.)

  2. you must access it as: M.at<uchar>(y,x) , not as M.at<double>()

  3. if your Mat has a single row only, it must be M.at<uchar>(0,i) , using 1 as index is already out of bounds.

  4. " i need to access and change the value one by one." -- this is clearly an anti-pattern in opencv. 99% of all cases can be solved faster and more safe by using a high-level builtin function. try to learn opencv, not to defeat it.

edit flag offensive delete link more

Comments

@berak, thanks for the response. Finally resolve all the errors. :)

zms gravatar imagezms ( 2017-03-06 02:18:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-02-23 03:47:25 -0600

Seen: 195 times

Last updated: Feb 23 '17