Ask Your Question

Access and save information in Mat Array

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

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));


It does not work. Anyone can gelp?

Rgds Zamani

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

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

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:<uchar>(y,x) , not as<double>()

  3. if your Mat has a single row only, it must be<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


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

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

Question Tools

1 follower


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

Seen: 121 times

Last updated: Feb 23 '17