简体   繁体   English

maya python api - 渲染相机并存储变量

[英]maya python api - render camera and store in variable

I'm working with Maya 2012 and what I want to do is render a camera view. 我正在使用Maya 2012,我想做的是渲染相机视图。 I have found that it's possible to do this using the MEL command 'render' (calling it through python). 我发现使用MEL命令'render'(通过python调用它)可以做到这一点。 However, as far as I know, this command renders the image and saves it to disk while only returning the path to the saved image. 但是,据我所知,此命令呈现图像并将其保存到磁盘,同时仅返回保存图像的路径。

Example: 例:

import maya.cmds as cmds
import cv2 as cv

pathToFile = cmds.render()
renderImage = cv.imread(pathToFile)

Since I'm interested in using the image to perform various computer vision algorithms, saving it to disk and then reading it from disk creates an unnecessary computational overhead. 由于我对使用图像执行各种计算机视觉算法感兴趣,将其保存到磁盘然后从磁盘读取它会产生不必要的计算开销。

Is it possible to render a camera and store the image in a variable without the need to do this? 是否可以渲染相机并将图像存储在变量中而无需执行此操作? This would allow for a quicker loop between rendering and analysing the render image. 这将允许在渲染和分析渲染图像之间更快地循环。


In case someone comes upon this question in the future: I tried the ram disk approach (using dataram RAMDisk) which was suggested and it did not yield any speed increase, unfortunately. 如果有人在将来遇到这个问题:我尝试了ram磁盘方法(使用dataram RAMDisk)这是建议的,不幸的是它没有产生任何速度增加。

If you're looking for efficiency, you may consider using the OpenMaya packages to access the OpenGL context for the views and render a Viewport 2.0 view to texture. 如果您正在寻找效率,可以考虑使用OpenMaya包访问视图的OpenGL上下文,并将Viewport 2.0视图渲染为纹理。 Then access that texture programmatically. 然后以编程方式访问该纹理。

Alternatively, you could write a plugin that wraps another rendering plugin, like Mayatomr, or the Hardware 2.0 renderer, and puts the rendered image into some shared memory space. 或者,您可以编写一个包装另一个渲染插件的插件,如Mayatomr或Hardware 2.0渲染器,并将渲染的图像放入一些共享内存空间。

But these solutions are so incredibly involved, touching on so many undocumented features. 但是这些解决方案非常令人难以置信,涉及到如此多的无证功能。 You should probably just set the renderer to Hardware 2.0, save the image as a BMP (which OpenCV reads very quickly anyway), perhaps to a RAM disk like suggested above, and call it a day. 您可能只需将渲染器设置为硬件2.0,将图像保存为BMP(无论如何OpenCV读取速度非常快),也许是上面建议的RAM磁盘,并将其称为一天。

Amendment 修订

There is an easier way, perhaps. 也许有一种更简单的方法。 Create a custom node that implements MPxHardwareShader specifications described here: 创建一个实现MPxHardwareShader描述的MPxHardwareShader规范的自定义节点:

http://images.autodesk.com/adsk/files/viewport_2_0_api_gold.pdf http://images.autodesk.com/adsk/files/viewport_2_0_api_gold.pdf

In other words, override the Hardware / Viewport 2.0 rendering for a some node. 换句话说,覆盖某个节点的Hardware / Viewport 2.0渲染。 Instead of actually drawing something, use your access to the OpenGL context to render the viewport to texture. 而不是实际绘制某些东西,使用您对OpenGL上下文的访问权来将视口渲染为纹理。

http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/ http://www.opengl-tutorial.org/intermediate-tutorials/tutorial-14-render-to-texture/

Then do whatever you want with it. 然后用它做任何你想做的事。 Clever, eh? 聪明,是吗?

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

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