Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Spock, did you see the looks on their faces?" "Yes, Captain, a sort of vacant contentment."


devel / comp.lang.python / Re: Tkinter and cv2: "not responding" popup when imshow launched from tk app

SubjectAuthor
o Re: Tkinter and cv2: "not responding" popup when imshow launchedJohn O'Hagan

1
Re: Tkinter and cv2: "not responding" popup when imshow launched from tk app

<mailman.2318.1678845672.20444.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=22428&group=comp.lang.python#22428

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: resea...@johnohagan.com (John O'Hagan)
Newsgroups: comp.lang.python
Subject: Re: Tkinter and cv2: "not responding" popup when imshow launched
from tk app
Date: Wed, 15 Mar 2023 13:00:44 +1100
Lines: 105
Sender: "John O'Hagan" <johnmohagan@gmail.com>
Message-ID: <mailman.2318.1678845672.20444.python-list@python.org>
References: <fbb73dcc4a7bc45c57ce959e09cde2986aacb0b6.camel@johnohagan.com>
<2ec2f29b-02f7-f85f-e3c8-4e43e2effde8@tompassin.net>
<b5a5aeca05fdac48c9c43e0f651d409b4484da30.camel@johnohagan.com>
Mime-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Trace: news.uni-berlin.de 1DEdXhpPl/JxgDGwecIuaAuCCI8pyNeMGgSCeSA0FFMg==
Return-Path: <johnmohagan@gmail.com>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=gmail.com header.i=@gmail.com header.b=WUsQxrak;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.017
X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'generated': 0.03;
'(which': 0.04; 'def': 0.04; '(e.g.': 0.05; 'arrays': 0.07;
'subject:when': 0.07; 'tkinter': 0.07; 'line:': 0.09; 'numpy':
0.09; 'subject:not': 0.09; 'import': 0.15; 'memory': 0.15;
'that.': 0.15; '(except': 0.16; '6:54': 0.16; 'arrays.': 0.16;
'caching': 0.16; 'closes': 0.16; 'default.': 0.16; 'demonstrates':
0.16; 'displayed': 0.16; 'heavily': 0.16; 'image,': 0.16; 'paths':
0.16; 'slow': 0.16; 'subject:: "': 0.16; 'subject:app': 0.16;
'zoom': 0.16; 'zooming': 0.16; 'wrote:': 0.16; 'problem': 0.16;
'tue,': 0.19; 'to:addr:python-list': 0.20; 'option': 0.20; "i've":
0.22; 'code': 0.23; 'anything': 0.25; 'saying': 0.25;
'available,': 0.26; 'cover': 0.26; "wasn't": 0.26; 'creating':
0.27; "isn't": 0.27; 'header:User-Agent:1': 0.30; 'whole': 0.30;
'am,': 0.31; 'approach': 0.31; 'think': 0.32; 'elements': 0.32;
'here,': 0.32; 'received:209.85.214': 0.32; 'window': 0.32;
'received:192.168.1': 0.32; 'but': 0.32; "i'm": 0.33; 'able':
0.34; 'same': 0.34; 'requires': 0.34; 'header:In-Reply-To:1':
0.34; 'received:google.com': 0.34; 'trying': 0.35; 'close': 0.35;
'display': 0.36; 'subject:from': 0.37; 'using': 0.37; "it's":
0.37; 'received:209.85': 0.37; 'disclosure': 0.37;
'received:192.168': 0.37; 'could': 0.38; 'thanks': 0.38;
'received:209': 0.39; 'changes': 0.39; 'list': 0.39; 'use': 0.39;
'methods': 0.39; 'still': 0.40; 'appears': 0.40; 'seconds': 0.40;
'want': 0.40; 'in,': 0.60; 'skip:i 50': 0.60; 'sample': 0.61;
'above': 0.62; 'brief': 0.62; 'here': 0.62; 'limited': 0.62;
'subject': 0.63; 'button': 0.64; 'down': 0.64; 'specifics': 0.64;
'your': 0.64; 'pay': 0.65; 'time.': 0.66; 'back': 0.67; 'that,':
0.67; 'per': 0.68; 'exactly': 0.68; 'forcing': 0.69; 'took': 0.69;
'within': 0.69; 'waiting': 0.73; 'features': 0.75; 'clicking':
0.76; 'out,': 0.78; 'click': 0.83; 'billion': 0.84; 'billions':
0.84; 'cycle': 0.84; 'fraction': 0.84; 'received:192.168.1.109':
0.84; 'sender:addr:gmail.com': 0.84; 'subject: \n ': 0.84;
'very,': 0.84; 'clicks': 0.93
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20210112; t=1678845669;
h=mime-version:user-agent:references:in-reply-to:date:to:from:subject
:message-id:sender:from:to:cc:subject:date:message-id:reply-to;
bh=W2Jp+98E3dWvxnqAnK7e+JOe9ScN9pf6K7GsV72s8xk=;
b=WUsQxrak+M+OA5m+JM+9fh6iCgqfA0uEIQXjnE6ZP3RFoNJ1Kewg6KPq2lr/Lvo8Pl
wxPRHaNA4OSdDUkSD/STWyNIOfWN9n0KS1yQPrbiMdUXQnZ1iLmy8c0UXLNMCFekhUAd
Migk0gVicmkbjXuP7UrtnyAka0+53wMXDEqdcDOlLiGO/EaivkycYyGRW1Ip5dcECaMY
oMPU2TD8rQud3DhKv6J9vz0U2f8TMrahYNQfpQ7cx/xJsrEQjgBDyyIBMr/j1nSBOMQw
O1hZYVuYKYWzUzFh0JcRBAidKknvlr74d2ukuuG4Bkeo2XqA83JDiUr7bkNbcfmKOGvy
P2Aw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20210112; t=1678845669;
h=mime-version:user-agent:references:in-reply-to:date:to:from:subject
:message-id:sender:x-gm-message-state:from:to:cc:subject:date
:message-id:reply-to;
bh=W2Jp+98E3dWvxnqAnK7e+JOe9ScN9pf6K7GsV72s8xk=;
b=f7VseJAgzaqA5B0n8YNMYHuVHIAm5LWd9IMF0cnRItiSV14R8HGoOPQn/hV9mDQPpL
AlccK1cqJ0jH5GtK8sHmoO78Dtp7QRFJLqmYMLIO7Iui43pmpC9yiuImKqcpwQ/FYmN7
SNdF0uV3l0mkqoKt5+VLCD5+xy7SbHVc1NgiclfuEDVDyFyRJ9m6zj4yDe4Lxcqyyqqv
7mWAgL7J4FvEtOvtCildznNWx3QJ/3fvvQmdAG2ljzmpjNch+3Ruvlhy4kFKh+RpxV8s
BB+j5DQJUmkzGQa1jPKfu1dWu7Bs+5fW4CpSIChTmnWHS7AUes21uar1F1mUZz+f73t8
1VzQ==
X-Gm-Message-State: AO0yUKVS89/LILgMODB0Zr4ONBJrg9nlaXMBgn/eYcGmfAS0HH648PDc
5m5dU1zSlHICYnToAxk2+QaaDikE30Q=
X-Google-Smtp-Source: AK7set9YtDOUOrwgOilbFiGsDMxr3lmft9eavCHSLaaeYR8ivpaU41LCI+/vgtwAc23WKPZYynZqKQ==
X-Received: by 2002:a17:90a:1a44:b0:233:f7a5:9940 with SMTP id
4-20020a17090a1a4400b00233f7a59940mr39534927pjl.1.1678845668925;
Tue, 14 Mar 2023 19:01:08 -0700 (PDT)
In-Reply-To: <2ec2f29b-02f7-f85f-e3c8-4e43e2effde8@tompassin.net>
User-Agent: Evolution 3.46.4-1
X-Content-Filtered-By: Mailman/MimeDel 2.1.39
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <b5a5aeca05fdac48c9c43e0f651d409b4484da30.camel@johnohagan.com>
X-Mailman-Original-References: <fbb73dcc4a7bc45c57ce959e09cde2986aacb0b6.camel@johnohagan.com>
<2ec2f29b-02f7-f85f-e3c8-4e43e2effde8@tompassin.net>
 by: John O'Hagan - Wed, 15 Mar 2023 02:00 UTC

On Tue, 2023-03-14 at 08:07 -0400, Thomas Passin wrote:
> On 3/14/2023 6:54 AM, John O'Hagan wrote:
> > Hi list
> >
> > I'm trying to use cv2 to display images created as numpy arrays,
> > from
> > within a tkinter app (which does other things with the arrays
> > before
> > they are displayed as images). The arrays are colour-coded
> > visualisations of genomes and can be over a billion elements in
> > size,
> > and I've found the PIL methods to display images in tkinter are too
> > slow and memory-heavy.
> >
> > Here is minimal code that demonstrates the problem in the subject
> > line:
> >
> > import cv2
> > from tkinter import *
> >
> > images=['a.jpg', 'b.jpg', 'c.jpg'] #change to image paths
> >
> > cv2.namedWindow('W', cv2.WND_PROP_FULLSCREEN)
> > cv2.setWindowProperty('W', cv2.WND_PROP_FULLSCREEN,
> > cv2.WINDOW_FULLSCREEN)
> > counter=[0]
> > def show():
> >     cv2.imshow('W', cv2.imread(images[counter[0] % len(images)]))
> >     cv2.waitKey(1)
> >     counter[0] += 1
> >
> > root=Tk()
> > root.wm_attributes("-topmost", 1)
> > Button(root, text=' Show ', command=show).pack()
> > mainloop()
> >
> > It works up to a point - I can cycle through the images by clicking
> > the
> > button - but if I mouse-click on the displayed image (e.g. to use
> > the
> > zooming and panning features of cv2), nothing happens, and a few
> > seconds later the image greys out and a popup appears saying
> > "'Unknown'
> > is not responding" and giving the option of waiting or forcing
> > close
> > (but sometimes these options are greyed out too). Clicking "wait",
> > if
> > available, closes the popup but it comes back a few seconds later.
> > If I
> > then click on the tkinter window titlebar, the popup changes
> > to "'Tk'
> > is not responding". Clicking on the button still works and after a
> > few
> > clicks the popup closes.

[...]

> I don't know anything about the specifics here, but with billions of
> elements you will not be able to show more than a small fraction on
> the
> screen.  

Hi Thomas

Thanks for your reply.

In the real app I use interpolating methods to fit the whole image on
the screen. In cv2:

cv2.imshow('W', cv2.resize(array, (width, height))

It's very quick, fractions of a second even for a billion+ sized array.
The PIL/Tk equivalent:

im = ImageTk.PhotoImage(Image.fromarray(array).resize((width, height)))
canvas.create_image(width/2, height/2, image=im)

did the same thing but was very, very slow for such large arrays (15
minutes or more per image, with memory heavily swapped out).

Having said all that, the specific problem I'm having isn't related to
the size of the arrays. The code I posted above triggers the problem
even with small images.

> So I think that a progressive disclosure approach would pay
> off.  Sample the arrays down to a more workable size before creating
> the
> screen images.  If you want to zoom in, resample them and recreate
> new
> images that only cover the zoomed in region in more detail.
>
> It would also be useful to cache the generated images so they can be
> re-displayed without needing to be regenerated each time.

This is exactly the approach I took in the first draft (except the
caching idea)! I wasn't using interpolating methods and was limited to
a minimum of one pixel per array element, and therefore limited in how
much of the array could be displayed. Even this got pretty slow in
tkinter if fully zoomed out, although the caching would have helped
with that. But the project brief requires the whole genome to be
visible by default.

Thanks

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor