简体   繁体   English

如何捕获由python可视模块的box函数生成的输出图像?

[英]How to capture an output image generated by the box function of python visual module?

I am using the box() function provided by the visual module of Python.我正在使用 Python 的可视模块提供的 box() 函数。 I want to capture the output image rendered by the display() function as a .png file.我想将 display() 函数呈现的输出图像捕获为 .png 文件。 I am using scene.capture('test4312').我正在使用 scene.capture('test4312')。 But getting an error "AttributeError: 'display' object has no attribute 'capture'".但收到错误“AttributeError:'display' object has no attribute 'capture'”。 Though the output is being displayed, it is not getting stored.虽然输出正在显示,但它没有被存储。

Here is the code for reference.这是供参考的代码。

from visual import * from visual.filedialog import get_file from visual import * from visual.filedialog import get_file

scene = display(width=300, height=100,center=vector(10,7,3),background=(1,1,1)) #scene = canvas(title='3DP 4,3,-12', width=600, height=200, center=vector(5,0,0), background=(1,1,1))场景=显示(宽度=300,高度=100,中心=矢量(10,7,3),背景=(1,1,1))#场景=画布(标题='3DP 4,3,-12',宽度=600,高度=200,中心=矢量(5,0,0),背景=(1,1,1))

fd = get_file() lines_list = fd.readlines() for i in arange(0,256,1): a,b,c = (int(val) for val in lines_list[i].split()) str1="("+str(a)+","+str(b)+","+str(c)+")" fd = get_file()lines_list = fd.readlines() for i in arange(0,256,1): a,b,c = (int(val) for val inlines_list[i].split()) str1="(" +str(a)+","+str(b)+","+str(c)+")"

box(pos=vector(a,b,c),size=(1,1,1),color=(i*0.01,0,0),opacity=0.6,line=true,linecolor=color.red) box(pos=vector(a,b,c),size=(1,1,1),color=(i*0.01,0,0),opacity=0.6,line=true,linecolor=color.red)

box(pos=vector(a,b,c),size=(1,1,1),color=(0.015*i,0,0),opacity=0.6,line=true,linecolor=color.red)
label(pos=vector(a,b,c), text=str1,height=9,box=false,color=color.white,opacity=0)


#print(answer)

scene.capture('test4312')场景.capture('test4312')


Please let me know if there is any solution to this problem.请让我知道是否有解决此问题的方法。 I need to store the output as .png.我需要将输出存储为.png。

Regards, Somrita.问候,索姆丽塔。

The obsolete visual module (not supported since Jan. 2016) did not have a scene.capture() function.过时的视觉模块(自 2016 年 1 月起不支持)没有 scene.capture() 函数。 There are two current VPython environments that you can use that do include scene.capture(): At vpython.org are instructions on installing the vpython module.您可以使用两种当前的 VPython 环境,其中包括 scene.capture(): 在 vpython.org 上有安装 vpython 模块的说明。 At webvpython.org (or equivalently, glowscript.org) you can write VPython programs without installing any software at all;在 webvpython.org(或等效的 gloomscript.org),您可以编写 VPython 程序,而无需安装任何软件; your program, which is saved in the cloud, is transpiled in the browser to JavaScript and executed in the browser.您的程序保存在云端,在浏览器中被转译为 JavaScript 并在浏览器中执行。 Web VPython is very convenient, but it does have the limitation that you can't import Python libraries other than a slightly incomplete random module. Web VPython 非常方便,但它确实有一个限制,除了稍微不完整的随机模块之外,您无法导入 Python 库。 Web VPython programs run several times faster than pure Python programs, thanks to being converted to JavaScript.由于转换为 JavaScript,Web VPython 程序的运行速度比纯 Python 程序快几倍。 Do read https://www.glowscript.org/docs/VPythonDocs/experienced.html on the differences between visual and vpython.请阅读https://www.glowscript.org/docs/VPythonDocs/experienced.html了解视觉和 vpython 之间的差异。 The main difference is that you need to write "vector(1,2,3)" or "vec(1,2,3)", not "(1,2,3)".主要区别在于您需要编写“vector(1,2,3)”或“vec(1,2,3)”,而不是“(1,2,3)”。 Also, what was a "display" is now a "canvas".此外,曾经的“展示”现在变成了“画布”。 Note that others can run your Web VPython program without installing any software;请注意,其他人无需安装任何软件即可运行您的 Web VPython 程序; just give a URL, such as https://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/ElectricMotor只需给出一个 URL,例如https://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/ElectricMotor

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM