I have the following problem. I resize image with OpenCV 1 in this way:
cvResize(img1, img2);
where:
img2= cvCreateImage( cvSize(img1->width * ratioScale + 0.5, img1->height * ratioScale + 0.5), IPL_DEPTH_8U, 1 );
Then, I want to fill the half image with 255 (just to test):
for (int j = 0; j < img2->height; j++){
for (int i = 0; i < img2->width/2; i++){
img2->imageData[j*img2->width + i] = 255;
}
}
When ratioScale
has precision 1 digit after decimal point(e.g. 1.5), it works correctly. Otherwise(e.g. 1.59), it gives several white diagonals and not half of image. I do not understand why. All images are grayscale.
I must use OpenCV 1 because it is obligation from the company.
Old OpenCV versions usually don't lay out the data continuosly in memory, but use some padding at the end of each row. The length of the row plus the padding is given by widthStep
. If you use width
you don't consider the (evantual) padding, and as a result you get this diagonalization effect.
So you need to do:
img2->imageData[j*img2->widthStep + i] = 255;
You should really avoid to use OpenCV 1, since it's 10 years old now, and it's obsolete.