Ask Your Question
1

image step not continuous after dividing an image

asked 2015-08-24 06:31:52 -0500

valentine gravatar image

Hi everyone,

I am try to divide an image into blocks in opencv and i get the "Error image step is not continuous". Pls here is my code need your help.

vector<Mat> ilmage;
    int N = (images[0].cols * images[0].rows) / (x*y);
    Mat t;

    int m = images[0].rows / x;
    int n = images[0].cols / y;
    int i2, i3, i4, i5;
    Size smallsize(n, m);

    for (int i = 0; i < images.size(); i++){
        for (int j = 0; j < images[i].rows; j += smallsize.height){
            for (int k = 0; k < images[i].cols; k += smallsize.width ){
                //i2 = k*n, i3 = n, i4 = j*m; i5 = m;
                t = images[i](Rect(k, j, smallsize.width,smallsize.height));
                ilmage.push_back(transpose(t.reshape(0, N)));
            }
        }
        pImage.push_back(ilmage);
        ilmage.clear();
    }

Regards.

edit retag flag offensive close merge delete

Comments

2

i did not try your code. i suggest you to try

t = images[i](Rect(k, j, smallsize.width,smallsize.height)).clone(); // try changing this line
sturkmen gravatar imagesturkmen ( 2015-08-24 06:59:10 -0500 )edit

@berak could you convert your comment as answer

sturkmen gravatar imagesturkmen ( 2015-08-24 07:36:03 -0500 )edit
2

i got another idea: @valentine, would you apply the proposed changes, and submit the successful results as an answer ?

berak gravatar imageberak ( 2015-08-24 07:41:06 -0500 )edit

Its working now. i had to clone the image before reshaping. @berak the x and y values are the different blocks am dividing the cols and rows of the image into. Thanks sturkmen and berak.

valentine gravatar imagevalentine ( 2015-08-24 07:41:42 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-08-24 07:14:50 -0500

berak gravatar image

^^ ah, nicely spotted. indeed, you cannot reshape() a roi (without cloning).

@valentine, i got 2 other objections:

 int m = images[0].rows / x;  // y !!
 int n = images[0].cols / y;    // x !!

and:

for (int j = 0; j < images[i].rows - m; j += m) {
for (int k = 0; k < images[i].cols - n; k += n) {
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-08-24 06:31:52 -0500

Seen: 52 times

Last updated: Aug 24 '15