Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Fast pixel change detection

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4

    Question Fast pixel change detection

    Hi everyone,

    I'm trying to implement a really fast method of pixel change detection.
    This has two main parts: capturing and comparing screenshots.


    For capturing:
    I'm using PBO so that glReadPixels() will return after the call.
    Extract of this part of the code is here:

    if(pboUsed){ //with PBO
    // OpenGL performs asynch DMA transfer, so glReadPixels() will return immediately.
    glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB,pboIds[index]);
    glReadPixels(posx,posy,500,500, GL_BGR_EXT, GL_UNSIGNED_BYTE,0);// posx and posy are given by the mouse position
    GLubyte* screenshot = (GLubyte*)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY_ARB);
    //ptr does now point to my screenshot..}


    For two screenshots, I'll basically have two GLubyte* screenshot1 and screenshot2

    For comparison :
    I tried to use simple and efficient memcmp: memcmp(screenshot1,screenshot2,500*500*3) but it doesn't always detect differences.
    And I'd like to detect any single pixel color change.

    Are there any OGL methods that can help me achieve this ?

    Thanks

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    Why do you want to perform the comparison with the CPU? If you do it on the GPU there is no real need for a capture (you can directly render to a texture through FBO). Also, you don't have to do a readback or any unnecessary copy, just use a fragment shader to compare the pixel values.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    Thanks for your reply.
    You are right, it would be great if everything was done on the GPU.
    Got the part for rendering to a texture through FBO. But I have questions about the fragment shader part.
    Is there anyway to compare pixels that are currently being rendered with pixels from a previous texture (holding the previous frame) using a fragment shader?
    Or should the fragment shader have two textures as inputs ?

    Sorry, I'm not familiar with fragment shaders so I may need guidance here.

    P.S: I also did some research and found these threads: http://www.opengl.org/discussion_boa...compare+images and http://www.opengl.org/discussion_boa...s-in-gpu/page2
    I will try to implement these methods and see which one has the best performance.
    Last edited by niyodanie; 07-21-2012 at 10:33 PM.

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Dec 2007
    Location
    Hungary
    Posts
    941
    Quote Originally Posted by niyodanie View Post
    Or should the fragment shader have two textures as inputs ?
    This is exactly what you have to do. Render both images to a texture through FBO and then use both textures as input to your comparison fragment shader.
    Disclaimer: This is my personal profile. Whatever I write here is my personal opinion and none of my statements or speculations are anyhow related to my employer and as such should not be treated as accurate or valid and in no case should those be considered to represent the opinions of my employer.
    Technical Blog: http://www.rastergrid.com/blog/

  5. #5
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    All right, thanks aqnuep. I also have another concern. For the case above, we were picking the whole frame. What if I need to monitor only specific portions of the frame? Let's say the user can select three different regions or portions of the screen. So here, we would have coordinates (x,y and width, height) of these regions like rectangles in windows programming. Can I use the same approach that is : using one texture with those three portions and same fragment shader ? How would I redirect those selected regions to the texture? And here, I need to be able to tell which specific region had its pixels changed.

  6. #6
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    4
    Quote Originally Posted by niyodanie View Post
    For the case above, we were picking the whole frame. What if I need to monitor only specific portions of the frame? Let's say the user can select three different regions or portions of the screen. So here, we would have coordinates (x,y and width, height) of these regions like rectangles in windows programming. Can I use the same approach that is : using one texture with those three portions and same fragment shader ? How would I redirect those selected regions to the texture? And here, I need to be able to tell which specific region had its pixels changed.
    Is there anyone who can help?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •