diff --git a/src/gui/imgview.py b/src/gui/imgview.py --- a/src/gui/imgview.py +++ b/src/gui/imgview.py @@ -13,10 +13,10 @@ log=logging.getLogger(__name__) class ImgView(ResizableCanvas): - def __init__(self,master=None,parent=None): + def __init__(self,gui,master=None): super().__init__(master) - self._parent=parent + self._gui=gui self._corners=Corners() self._boardGrid=None @@ -31,7 +31,9 @@ class ImgView(ResizableCanvas): self.delete("all") if self._img: - img=self._img.resize((int(self._width),int(self._height))) + w,h=self._img.size + ratio=min(self._width/w, self._height/h) + img=self._img.resize((int(w*ratio),int(h*ratio))) self._tkImg=ImageTk.PhotoImage(img) # just to save the image from garbage collector self.create_image(self._width//2, self._height//2, anchor="center", image=self._tkImg) @@ -66,7 +68,8 @@ class ImgView(ResizableCanvas): log.debug(self._corners.corners) self._boardGrid=Grid(self._corners.corners) corners=[self._transformPoint(c) for c in self._corners.corners] - self._parent.detector.setCorners(corners) + self._gui.detector.setCorners(corners) + self._gui.preview() self.redraw() @@ -96,9 +99,10 @@ class ImgView(ResizableCanvas): w=int(self._width) h=int(self._height) wo,ho=self._img.size # o for original + log.debug("image: %sx%s, view: %sx%s",wo,ho,w,h) widthRatio=wo/w heightRatio=ho/h - self._imgSizeCoef=max(widthRatio,heightRatio) + imgSizeCoef=max(widthRatio,heightRatio) # shift compensates possible horizontal or vertical empty margins from unmatching aspect ratios - self._imgShift=EPoint(wo-w*self._imgSizeCoef,ho-h*self._imgSizeCoef)/2 - return EPoint(self.canvasx(point.x),self.canvasy(point.y)) * self._imgSizeCoef + self._imgShift + imgShift=EPoint(wo-w*imgSizeCoef,ho-h*imgSizeCoef)/2 + return EPoint(self.canvasx(point.x),self.canvasy(point.y)) * imgSizeCoef + imgShift