سؤال

I'm working with Maya 2012 and what I want to do is render a camera view. I have found that it's possible to do this using the MEL command 'render' (calling it through 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.

هل كانت مفيدة؟

المحلول

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. 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.

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.

Amendment

There is an easier way, perhaps. Create a custom node that implements MPxHardwareShader specifications described here:

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. Instead of actually drawing something, use your access to the OpenGL context to render the viewport 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 مع الإسناد
لا تنتمي إلى StackOverflow
scroll top