如何创建一个交互式窗口,其中显示图像变化?

huangapple go评论77阅读模式
英文:

How to make an interactive window in which the image change was displayed?

问题

有一张包含5个微电路的图像,调用了一个函数,其结果是第一个微电路变为蓝色(相应地,在第二次函数调用后,第二个微电路被涂成蓝色,最终我们得到一张包含5个蓝色微电路的图像)。问题是,如何创建一个窗口,以便可以实时观察到这些图像的变化,并且它是用Python编写的?

5个芯片
5个蓝色芯片

我尝试使用tkinter来实现这一点,但我仍然没有弄清楚如何使其窗口具有交互性。

英文:

There is an image of 5 microcircuits, a function is called, the result of which is the blue coloring of the first microcircuit (accordingly, after the second function call, the second microcircuit is painted over and as a result we get an image with 5 blue microcircuits). The question is, how to create a window in which these image changes could be observed in real time and that it was written in Python?
5 chips
5 blue chips

I tried to do this using tkinter, but I still didn't figure out how to make its window interactive.

答案1

得分: 1

你可以非常简单地使用OpenCVcv.imshow()来实现,如下所示:

#!/usr/bin/env python3

import cv2 as cv

# 以BGR格式加载图像
im = cv.imread('z88rQ.png')

# 绘制窗口并等待用户按键,最多等待2秒
cv.imshow("Image", im)
cv.waitKey(2000)

# 迭代五个点,每个点位于黑色对象中的一个
for y in [80, 200, 500, 700, 900]:

    # 用蓝色填充下一个黑色对象
    cv.floodFill(im, None, (100, y), [255, 0, 0])

    # 绘制窗口并等待用户按键,最多等待2秒
    cv.imshow("Image", im)
    cv.waitKey(2000)

如何创建一个交互式窗口,其中显示图像变化?

英文:

You can very simply use OpenCV and cv.imshow() like this:

#!/usr/bin/env python3

import cv2 as cv

# Load image as BGR
im = cv.imread('z88rQ.png')

# Draw the window and wait up to 2s for user to press a key
cv.imshow("Image", im)
cv.waitKey(2000)

# Iterate over five points, one in each of the black objects
for y in [80,200,500,700,900]:

    # Fill next black item with blue
    cv.floodFill(im, None, (100, y), [255,0,0])

    # Draw the window and wait up to 2s for user to press a key
    cv.imshow("Image", im)
    cv.waitKey(2000)

如何创建一个交互式窗口,其中显示图像变化?

huangapple
  • 本文由 发表于 2023年5月28日 04:35:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/76348926.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定