Results 1 to 7 of 7

Thread: Edge-detection (maybe using QGL?)

  1. #1
    Join Date
    Nov 2011
    Location
    Brazil
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Edge-detection (maybe using QGL?)

    Hi everybody.

    I have a working QGLWidget which inserts colored cones according to mouse click, and shows part of them by depth-comparison, like in the image at the link below:
    http://upload.wikimedia.org/wikipedi...noi_2D.svg.png

    The boundaries where the colors change represent points with the same depth. I've spent now many days searching and trying via OpenGL coding, using stencil and depth buffers, but I'm not managing to get into a result like in the image at the link below:
    http://mathworld.wolfram.com/images/...iagram_700.gif

    i.e., a white image with only the boundaries filled with black.

    I found this tutorial: http://igortrindade.wordpress.com/20...l-and-shaders/
    which now makes me wonder if there's a very simple way to achieve the result I want only using some basic QGL properties.

    Thank you once again, masters.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Edge-detection (maybe using QGL?)

    If you are interested only in displaying the edges (and not collecting the edge data), then google for something like "edge detection shader", there should be many solutions ready to use. I've had one implemented in GLSL using the sobel matrix, but can't find it now...
    Using image processing lib like OpenCV could be another solution, but probably you don't need that, simple edge detection shader should do the job.

  3. #3
    Join Date
    Nov 2011
    Location
    Brazil
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Edge-detection (maybe using QGL?)

    Hi stampede, thanks a lot for your support. Actually, before posting here, I tried several different combinations of convolution without success. It simply doesn't work. Most probably it's my fault, since I'm still a newbie, but I can't see why. I tried to assign some convolution code to the mouse right button click event. The event is ok, I included some other things just to debug it, but the convolution doesn't happen at all.

    I've found some examples in the internet using glConvolutionFilter2DEXT but Qt doesn't recognize this function ("not declared"), though glConvolutionFilter2D is supported, so I tried many combinations of it but all without success.

    Please, check if you see something really wrong or missing here:
    Qt Code:
    1. [...]
    2. if (event->button() == Qt::RightButton) {
    3. GLfloat laplacian[3][3] = {
    4. { -0.125, -0.125, -0.125 },
    5. { -0.125, 1.0 , -0.125 },
    6. { -0.125, -0.125, -0.125 },
    7. };
    8. glConvolutionFilter2D(GL_CONVOLUTION_2D, GL_LUMINANCE, 3, 3, GL_LUMINANCE, GL_FLOAT, laplacian);
    9. glEnable(GL_CONVOLUTION_2D);
    10. }
    11. [...]
    To copy to clipboard, switch view to plain text mode 

    This is only one of my 50+ tries...

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Edge-detection (maybe using QGL?)

    Can you verify that:
    1) this code actually does the job, by testing for example in separate app ?
    2) your qglwidget OpenGL context is the current one - by calling makeCurrent() before any opengl method calls you do outside the resizeGL, paintGL methods (and call doneCurrent() after that)

  5. #5
    Join Date
    Nov 2011
    Location
    Brazil
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Edge-detection (maybe using QGL?)

    I don't have enough knowledge to try a separate app, actually my app is already the simplest I could think of... And I tried inserting makeCurrent() before and doneCurrent() after that convolution block, but still nothing happens. Thanks again for your support.

  6. #6
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Edge-detection (maybe using QGL?)

    You've said that this code is from the internet, maybe a full compilable example is included as well, just to test that this code is really doing edge detection.
    What about shaders, have you tried that ? Edge detection shader should be just few lines of code.

  7. The following user says thank you to stampede for this useful post:

    mwgobetti (20th January 2012)

  8. #7
    Join Date
    Nov 2011
    Location
    Brazil
    Posts
    10
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Edge-detection (maybe using QGL?)

    Yes, after a lot of research it looks like that QGLShader and QGLShaderProgram are the answer to my problem. Qt always has its own easy way of doing everything, that's why I created this thread, I knew someone would link me to that way.

Similar Threads

  1. Replies: 1
    Last Post: 17th August 2011, 19:57
  2. Filll Edge QScintilla
    By wirasto in forum Qt Tools
    Replies: 0
    Last Post: 12th January 2011, 07:39
  3. Filll Edge QScintilla
    By wirasto in forum Qt Programming
    Replies: 0
    Last Post: 12th January 2011, 07:39
  4. How to draw rectangle with moveable edge
    By sagirahmed in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2010, 06:21
  5. how to color the top edge of a rect
    By dreamer in forum Newbie
    Replies: 4
    Last Post: 15th May 2008, 14:15

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.