Can't extract elements from a Mat object into an int array (C++)

I’m new to OpenCV, and I’m trying to extract the int values of a CV_8U type (1 channel) Mat object. I can extract one value at a time, but if I put it into a loop, the program aborts in the console at runtime.

I’d like to have an int array because I want to convert the image into ASCII art, Please see below code? Is the console running out of memory or something?

Thanks in advance for the help.

please, NO useless screenshots of code or errors here. replace with TEXT, thank you.

you messed up the indices.

(i,j) ~ (y,x)
(x,y) ~ (j,i)

cv::Mat takes (i,j) indexing, and so does the C array.

please learn about “row-major” storage. that’s the standard, unless you’re Fortran or OpenGL.

storage and iteration orders matter. if you do it wrong, the CPU cache becomes useless.

don’t just use [x][y] indexing into a C array because it “looks good”. it goes against convention, so to everyone else it’ll look wrong.

use int numbVersion[480][640] and index with [i][j]

allocating the C array is also pointless. you have the same data in the cv::Mat.

for “ascii art”, you should be allocating something smaller, if a “pixel” should be one character.

you should use cv::resize() to downsample the input image. use appropriate fx, fy (characters aren’t square) and INTER_AREA mode.