英文:
How to make an interactive window in which the image change was displayed?
问题
有一张包含5个微电路的图像,调用了一个函数,其结果是第一个微电路变为蓝色(相应地,在第二次函数调用后,第二个微电路被涂成蓝色,最终我们得到一张包含5个蓝色微电路的图像)。问题是,如何创建一个窗口,以便可以实时观察到这些图像的变化,并且它是用Python编写的?
我尝试使用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
你可以非常简单地使用OpenCV和cv.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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论