Grabbing image from RenderView QT

177 views
Skip to first unread message

Arvid Schneider

unread,
Dec 4, 2014, 12:02:10 PM12/4/14
to python_in...@googlegroups.com
Hey Group,

me again. I am trying to grab the image from mayas render view using QImage. What I am doing right now is grabbing the whole view with "QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop().winId(), 0, 0, -1, -1).toImage()"
It would be great if this was an 32bit image, but the grabWindow probabbly just grabs 8Bit. 

Can you help me out getting a float image directly from mayas native render view? 
Or grabbing the whole viewport as an 32bit image?
Arvid

Justin Israel

unread,
Dec 4, 2014, 1:32:52 PM12/4/14
to python_in...@googlegroups.com
Have you tried saving the image via the render window editor?
http://download.autodesk.com/global/docs/maya2014/en_us/CommandsPython/renderWindowEditor.html#flagwriteImage

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/7dea2271-0085-41c7-ad78-1a4f2ff0d93e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marcus Ottosson

unread,
Dec 4, 2014, 1:49:48 PM12/4/14
to python_in...@googlegroups.com

Or grabbing the whole viewport as an 32bit image?

I suspect the issue isn’t with grabWindow, but rather about the renderview only displaying an 8-bit representation of the image, which is probably restricted to whatever depth the OS window manager is configured to.



For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Arvid Schneider

unread,
Dec 4, 2014, 6:09:09 PM12/4/14
to python_in...@googlegroups.com
Float is only supported in Maya 15 and above. And when saving the image from the render view as exr its definitely float.
What I am trying to do is getting float pixel values when hovering with the cursor above the image.

What I have done so far is grabbing the whole screen image and saving it as a qimage. Then getting the global mouse x and y to query the pixel rgb value under the cursor. Its works pretty smooth..
Now I want to extend the feature, and use it with maya's updated render view( float values)..but grabbing just grabs 8 bit..

Marcus Ottosson

unread,
Dec 5, 2014, 2:57:04 AM12/5/14
to python_in...@googlegroups.com

Now I want to extend the feature, and use it with maya’s updated render view( float values)..but grabbing just grabs 8 bit..

This is still me theorising, but remember back in Windows 95-98 when you could set your desktop to both resolution and color depth? Well, if you’d set the depth to 1-bit, the entire desktop would be black & white. Even the Maya Render View, and any image within it. I suspect that it is from this very same framebuffer that Qt grabs images from. Like the whole desktop is one big rendered image, and that image is limited to whichever bit-depth the window manager is set to render in. In the case of desktops today, this depth is typically 8-bit per channel which would explain why you’re only getting that depth when grabbing your images.

What I am trying to do is getting float pixel values when hovering with the cursor above the image.

As a solution, I think you could safely save out the image via the render view as Justin suggests, load that image and get the position and color of that instead of a grabbed image. You would subtract from the local coordinate of the Render View widget and apply it to the actual coordinates of the final image, taking Render View zoom into account. And you might probably want to delay the tooltip, as saving the image might take a second depending on its size, but tooltips typically take a second or two to show anyway so it should still work out.

If you could show me what you’ve got so far I might be able to take a closer look.


--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Marcus Ottosson
konstr...@gmail.com

Arvid Schneider

unread,
Dec 5, 2014, 4:38:07 AM12/5/14
to python_in...@googlegroups.com
This is now the whole event filter.

class PixelFilter(QtCore.QObject):
        """ This is the Pixel Event Filter, which draws a label when Pixel Information is activated.
            MMB enables the UI and prints the according pixel information inside of the RenderView.
        """

        def eventFilter(self, source, event):
            """ Creates the Pixel information event
                @param source Object where event is installed on
                @type: QtObject
                @param event Event type
                @type: QEvent
            """

            if event.type() == QtCore.QEvent.MouseButtonPress:
                if event.buttons() == QtCore.Qt.MidButton:

                    ''' Creates design of pixel label'''
                    pixelLabel.setStyleSheet("QLabel {background: rgb(150, 150, 150);"
                                             " border-style: inset;"
                                             " border-width: 1px;"
                                             "color: rgb(0, 0, 0);}")
                    pixelLabel.setAlignment(QtCore.Qt.AlignCenter)
                    self.img = QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop().winId(), 0, 0, -1, -1).toImage()
                    return False

            elif event.type() == QtCore.QEvent.MouseButtonRelease:
                pixelLabel.hide()
                source.removeEventFilter(self)
                vrGlobalVariable.pixelInformation.setChecked(False)
                return False

            if event.type() == QtCore.QEvent.MouseMove:
                if event.buttons() == QtCore.Qt.MidButton:

                    ''' Shows Pixel Information label and updates when mouse is moving'''
                    pixelLabel.show()
                    px = QtGui.QCursor.pos()
                    pixelLabel.setGeometry(px.x(), px.y() - 20, 120, 15)
                    c = self.img.pixel(px.x(), px.y())
                    color = QtGui.QColor(c).getRgbF()
                    pixelLabel.setText('R:%.2f  G:%.2f  B:%.2f \n' % (color[0], color[1], color[2]))
                    return False

            return QtCore.QObject.eventFilter(self, source, event)



On Friday, December 5, 2014 8:57:04 AM UTC+1, Marcus Ottosson wrote:

Now I want to extend the feature, and use it with maya’s updated render view( float values)..but grabbing just grabs 8 bit..

This is still me theorising, but remember back in Windows 95-98 when you could set your desktop to both resolution and color depth? Well, if you’d set the depth to 1-bit, the entire desktop would be black & white. Even the Maya Render View, and any image within it. I suspect that it is from this very same framebuffer that Qt grabs images from. Like the whole desktop is one big rendered image, and that image is limited to whichever bit-depth the window manager is set to render in. In the case of desktops today, this depth is typically 8-bit per channel which would explain why you’re only getting that depth when grabbing your images.

What I am trying to do is getting float pixel values when hovering with the cursor above the image.

As a solution, I think you could safely save out the image via the render view as Justin suggests, load that image and get the position and color of that instead of a grabbed image. You would subtract from the local coordinate of the Render View widget and apply it to the actual coordinates of the final image, taking Render View zoom into account. And you might probably want to delay the tooltip, as saving the image might take a second depending on its size, but tooltips typically take a second or two to show anyway so it should still work out.

If you could show me what you’ve got so far I might be able to take a closer look.

On 4 December 2014 at 23:09, Arvid Schneider <arvidsc...@gmail.com> wrote:
Float is only supported in Maya 15 and above. And when saving the image from the render view as exr its definitely float.
What I am trying to do is getting float pixel values when hovering with the cursor above the image.

What I have done so far is grabbing the whole screen image and saving it as a qimage. Then getting the global mouse x and y to query the pixel rgb value under the cursor. Its works pretty smooth..
Now I want to extend the feature, and use it with maya's updated render view( float values)..but grabbing just grabs 8 bit..

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_maya+unsub...@googlegroups.com.



--
Marcus Ottosson
konstr...@gmail.com

Arvid Schneider

unread,
Dec 5, 2014, 4:04:45 PM12/5/14
to python_in...@googlegroups.com
So I figured out that it would work with saving mayas rendered image as an exr and use local pixel values to query the rgb values. 
The problem is that Qt doesnt work with exr files natively and I need to find another way. 
But thanks you two for the help. 

Justin Israel

unread,
Dec 5, 2014, 4:23:48 PM12/5/14
to python_in...@googlegroups.com
You could use OpenImageIO to read and sample the image.

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/734fb17a-3705-4772-b32e-45404c8e572a%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages