0

I'm trying to make a program that allows me to tag objects in a photo. I'm using QRubberBand to create selection rectangles over an image. This image is a QLabel where I set a QPixmap. It's important to note that I resized the original images.

Right now I'm able to get TopLeft and BottomRight coordinates of those selection rectangles, but I want to get the equivalent rectangle in the original image. I have an idea for how to do it, but I need to know the coordinates of the first pixel in order to do it.

  • I have tried to use both pos() and geometry() of that QLabel. Both of them gave me a value of (0,0).
  • Important: I already tried to map it like I did with TopLeft and BottomRight but the return is still 0.

Here is the definition of my QLabel:

self.image_box = QLabel(self)
self.set_image(self.img_paths[0])
self.layout_window.addWidget(self.image_box, alignment=Qt.AlignmentFlag.AlignHCenter)

And here is the set_image() function:

def set_image(self, path):
    pixmap = QPixmap(path)

    #Conseguir el tamaƱo original de la foto.
    width_original = pixmap.width()
    height_original = pixmap.height()

    if width_original >= height_original:
        #pixmap = pixmap.scaledToWidth(self.img_panel_width - margin)
        pixmap = pixmap.scaledToWidth(self.img_panel_width)
    else:
        #pixmap = pixmap.scaledToHeight(self.img_panel_height - margin)
        pixmap = pixmap.scaledToHeight(self.img_panel_height)

    #pixmap = pixmap.scaled(self.img_panel_width, self.img_panel_height)

    self.ratioEscW = width_original / pixmap.width()
    self.ratioEscH = height_original / pixmap.height()
    
    self.image_box.setPixmap(pixmap)
tdy
  • 36,675
  • 19
  • 86
  • 83
Mordred
  • 9
  • 1

0 Answers0