zoom while drawing rectangle in tkinter
I am new to Python
Tkinter. My idea of using tkinter is to do annotation by zooming in and out of a image. Tkinter canvas zoom + move/pan I started my first course of action based on the baove mentioned stackoverflow question and answers.
But the problem i face is if i zoom in and drag to the second part of image i am not able to locate the bounding box with help of mouse events and if i draw in one point the rectangle is generated in other point of the first portion of image.
Can anyone guide me to solve this issue in tkinter with zoom in and out drawing a rectangle?
See also questions close to this topic
Cannot raise scrollable frame (tkinter)
The issue I'm having is to do with trying to raise a "scrollable frame" in tkinter once it has been created. I start the program with a parent window and then create all the frames I need, raising them to the top of the stack as necessary. But for the scrollable frame I needed to put it inside a canvas because the frame has no scrollbar widget.
I've tried tag_raise(), tkraise(), lift(), none of which seem to work. I am struggling to solve the issue because IDLE is not giving me an error report, the shell just stays blank every time I try to raise the canvas or the frame. The program definitely has not frozen because I am still able to return to my previous menus after trying to raise the canvas.
Below is a heavily abstracted version of the code, there is one title and 10 buttons within the frame and the frame is within the canvas. All widgets are created insode "frameConfig". The parent/root is passed through as a parameter.
def onFrameConfigure(canvas): canvas.configure(scrollregion=canvas.bbox("all")) def frameConfig(parent): canvas = tk.Canvas(parent, borderwidth=0) frame = Frame(canvas) vsb = tk.Scrollbar(canvas, orient="vertical", command=canvas.yview) canvas.configure(yscrollcommand=vsb.set) vsb.pack(side = "right", fill = "y") canvas.pack(side = "left", fill = "both", expand = True) canvas.create_window((0,0), window = frame, anchor = "nw") frame.bind("<Configure>", lambda event, canvas=canvas: makeTeam.onFrameConfigure(canvas)) frame.config(bg = "azure") frame.pack(fill = BOTH) frame.place(relwidth = 1.0, relheight = 1.0) def open(): frame.tkraise()
"frameConfig" is called on start up and "Open" is called whenever the frame needs to be raised. All I want to achieve is the ability to raise and lower the "scrollable frame" like all my other frames. Thank you in advance.
How do I have an object rebound off the canvas border?
I am using the canvas widget from tkinter to create an ellipse and have it move around in the canvas. However when the ellipse comes in contact with the border it gets stuck to wall instead of bouncing off. I'm struggling with debugging the code, thanks in advance!
from tkinter import * from time import * import numpy as np root = Tk() root.wm_title("Bouncing Ball") canvas = Canvas(root, width=400, height=400, bg="black") canvas.grid() size=10 x = 50 y = 50 myBall = canvas.create_oval(x-size, y-size, x+size, y+size, fill = "red") while True: root.update() root.after(50) dx = 5 dy = 0 #separating x and y cooridnates from tuple of canvas.coords x = canvas.coords(myBall)+10 y = canvas.coords(myBall)+10 coordinates = np.array([x, y], dtype = int) #Checking boundaries if coordinates-size <= 0: dx = -1*dx if coordinates+size >= 400: dx = -1*dx if coordinates-size <= 0: dy = -1*dy if coordinates+size >= 400: dy = -1*dy print(coordinates) #Used to see what coordinates are doing canvas.move(myBall, dx, dy) #Move ball by dx and dy
Make canvas background transparent - python
So I am making a Frogger game, but have run into a problem. For the collision detection, I am using the following to check if one Tkinter canvas object is overlapping another:
However, I made the background a canvas object as well:
background = self.canvas.create_image(0, 0, image = self.imageData["Background"], anchor = "nw")
So the program is detecting a collision between the player and an object 24/7. Is there any way around this? I searched SO and tried putting the background in a label, but when I packed the canvas over it the background disappeared (probably because the canvas was covering it).
I can't find a way to make the canvas transparent without making the objects on it transparent as well. I also do not want to calculate the x and y boxes of each object, as that is just cumbersome and unreliable.
If someone could suggest another way, that would be awesome.
Is there any way to detect zoomed image based on image quality?
Is there any way to detect zoomed image based on image quality, like Peak Signal to Noise Ratio (PSNR) to assess and quantify image quality?
I am looking for the possible way to discriminate extracted images from video clip. Some of them are 1:1 to 1:2 (2x zoomed) images, with good quality, but the others are 10x, 20x zoomed images with very blur pixels.
All the images are same resolution (i.e. 200x200pixels).
Is there any pipeline or tools to quantify image quality or other features to discriminate too-much-zoomed images?
MPAndroid Chart zom imageview and axis togheter
I have two component: - PhotoView (an extension of image view that let me to zoom ) - Mpandroid chart.
I need to set axis on the image and when zoom the image, the axis need to scale. The image view is in Relative Layout over the LineChart of MPAndroid Chart.
How can I do ?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="it.a3fedin.myapplication1.LineChartActivity3"> <com.github.chrisbanes.photoview.PhotoView android:id="@+id/imageViewX" android:layout_width="400dp" android:layout_height="400dp" android:elevation="5dp" app:srcCompat="@mipmap/ic_launcher" /> <com.github.mikephil.charting.charts.LineChart android:id="@+id/chart_ma" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="7" android:elevation="1dp" android:visibility="visible"> </com.github.mikephil.charting.charts.LineChart> </RelativeLayout>
Why scipy.ndimage zoom add new channel?
I was surprised when i found that python
scipy.ndimage.zoomautomatically add new channel when the zoom is performed:
from scipy.misc import imread from scipy.ndimage import zoom img = imread('lena.jpg') img=imread('lena.jpg') img.shape (468, 792, 3) x = zoom(img, 1.0) x.shape (468, 792, 3) x = zoom(img, 1.5) x.shape (702, 1188, 4) x = zoom(img, 2) x.shape (936, 1584, 6)
The width, height dimension are correct, i was not able to understand from where came from the other dimensions.
This strange behavior manifests only for colored image:
x = zoom(img[:, :, 0], 2) x.shape (936, 1584)