Jump to content
Sign in to follow this  
marco711

Problem to copy a matrix within other one

Recommended Posts

Hello,

I'm coding an SC_THREAD where I receive a flux of pixels which is saved within a buffer called image_buffer. This buffer is of size 3 lines x 720 columns. What I'm trying to do is that when the buffer is filled with two lines and the first 4 columns of the third line, it starts to copy the content of the buffer within another matrix called img. Below is the code:

void FILTER::filtering(){

  if(!reset_n){
    p_out.write(0);
    h_out.write(false);
    v_out.write(false);
    cout << "module: " << name() << "... reset!" << endl;
  }

  while(1){
    while(!h_in) wait(h_in.posedge_event()); 
    for(i=0; i<3; i++){
      for(j=0; j<720; j++){
        image_buffer.pixel[i*image_buffer.width+j] = p_in;
        wait();
        while(!h_in) wait();

        //Here I put the condition to start saving the pixels from the buffer into another matrix
        if ( (i > 1) && (j > 4) ){
          for(int bi=0; bi<576; bi++){
            for(int bj=0; bj<720; bj++){
              if (bi < 3){
                img.pixel[bi*img.width+bj] = image_buffer.pixel[bi*image_buffer.width+bj];
                
                //Here is checked that there is not difference between the two matrix
                unsigned char diff = img.pixel[bi*img.width+bj] - image_buffer.pixel[bi*image_buffer.width+bj];
                if (int(diff) != 0){ cout << "ERROR" << endl; exit(1);}
              }
              else{
                img.pixel[bi*img.width+bj] = image_buffer.pixel[(bi%3)*image_buffer.width+bj];
              }

              //Here I check that i and j are stuck in 2 and 5
              cout << "i: " << i << " j: " << j << endl;
 
//The image is savec in a png file when the the matrix is full

if ( (bi == 575)&&(bj == 719) ){ image_write( &img, "test.png" ); exit(1); } } } } wait(); } } } }

 

 

The problem I have is that when I check in the terminal how the counters i and j change, I see that they are stuck with values i = 2 and j = 5. When I check the image saved in the matrix img I see just a thin part of the image in the top (it should be the pixels of the first two lines and the first four pixels of the third line) and then the rest if full of any other thing. The problem should be related to the condition I put to start saving the pixels in the buffer into the other matrix ( if ( (i > 1) && (j > 4) ) ) but I can't figure out any other way to put this condition. Could you please give me a hint on how to solve this or what am I doing wrong?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×