Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You shouldn't use directly img1.data!

Either use the img1.ptr() or img1.ptr(line) to get the pointer to the data. Then cast it to the desired data format:

ushort *pImg=(ushort*)img1.ptr();

Note that the image is not always continuous in the memory; so (pImg+ywidth+x) is not sure that will give the pixel (x,y). Check this with img1.isContinous()

You can also use the img.at<type>(y,x) operator.

img.at<vec3s>(y,x)[0]=blue.

You shouldn't use directly img1.data!

Either use the img1.ptr() or img1.ptr(line) to get the pointer to the data. Then cast it to the desired data format:

ushort *pImg=(ushort*)img1.ptr();

Note that the image is not always continuous in the memory; so (pImg+ywidth+x) is not sure that will give the pixel (x,y). Check this with img1.isContinous()

You can also use the img.at<type>(y,x) operator.

img.at<vec3s>(y,x)[0]=blue.

img.at<vec3s>(y,x)[0]=blue.etc...