Trying to insert pixels into a queue

0

I have a problem when inserting a pixel in a queue. What I want is to insert the point not what the image has at that point Thanks

What I have is this:

queue <int> cola;
for (int i = imagen.FirstRow()+1; i <=imagen.LastRow()-1; i++) {
        for (int j = imagen.FirstCol() + 1; j <imagen.LastCol()-1; j++) {
              if (imagen(i, j) <= 5)
                  cola.push(???) // aqui es donde quiero insertar el punto
                  cola.push(imagen(i,j)) // esto es el valor del punto
        }
}
    
asked by RAZVAN LISMANU 21.04.2018 в 18:52
source

1 answer

0
  

I have a problem when inserting a pixel in a queue. What I want is to insert the point not what the image has at that point. Thank you

In what way do you want to save the point: In an int? String?

For example:

  • You can save the value of i in one field and the value of j in the other field of the queue.

  • The other option would be to concatenate point i and j, converting to string, concatenating and finally saving in a string queue.

It could be like this:

std::string Convert (float number){
    std::ostringstream buff;
    buff<<number;
    return buff.str();
}

queue <int> cola;
queue <string> Puntocola;
for (int i = imagen.FirstRow()+1; i <=imagen.LastRow()-1; i++) {
    for (int j = imagen.FirstCol() + 1; j <imagen.LastCol()-1; j++) {
          if (imagen(i, j) <= 5)
              string Imagepunto = Convert(i) + "," + Convert(j);
              // aqui es donde quiero insertar el punto
              cola.push(Imagepunto)
              cola.push(imagen(i,j)) // esto es el valor del punto
    }
}
  

In case of int you would have this option.   You create a class with attributes x, y, in which you save the pixel.

public class PixelImage{
    private int x;
    private int y;

    // Constructor 
    public PixelImage(int px, int py){
        x = px;
        y = py;
    }
}

// Creas la cola tipo PixelImage. Creo que esto seria en otra clase sabiendo que es POO
PixelCola punto; 
queue <PixelImage> PixelCola;
queue <string> cola;
for (int i = imagen.FirstRow()+1; i <=imagen.LastRow()-1; i++) {
    for (int j = imagen.FirstCol() + 1; j <imagen.LastCol()-1; j++) {
          if (imagen(i, j) <= 5)
              // Creo que i es x y J es y
              punto = new PixelImage(i,j);
              PixelCola.push(punto);
              cola.push(imagen(i,j)) // esto es el valor del punto
    }
}
  

Queue of array of characters

     

Convert a float or an integer in string in c ++

    
answered by 21.04.2018 в 23:56