Results 1 to 6 of 6

Thread: OpenCV function call within OpenGL program

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4

    OpenCV function call within OpenGL program

    Hi,

    I have an OpenGL program that uses an OpenCV function call to calculate the coordinates relative to some markers. Once that is done OpenGL should then open a window and display some graphic (e.g. point (5px)) at the coordinates calculated by the OpenCV function. The problem I have is that the cvCaptureFromCAM(CV_CAP_ANY); function causes the program to terminate with the following error:

    GLUT Fatal Error: redisplay needed for window 1, but no display callback.

    If I comment it out, then it runs (but no webcam frames ofcorse).

    The OpenGL and OpenCV functions run OK as separate programs. I'm not sure what the problem could be. Would appreciate any pointers you may have.

    Here's the code (excluding header files etc)

    void setup(void)
    {
    glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
    glPointSize(10);
    }

    void display(void)
    {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0, 0.0, 1.0);

    glBegin(GL_POINTS);
    glVertex2f(mid, 50);
    glEnd();

    glFlush();
    }

    void resize(int width, int height)
    {
    glViewport(0, 0, (GLsizei)width, (GLsizei)height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0.0, 100.0, 0.0, 100.0, -1.0, 1.0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    }

    void capture(void) //OpenCV function
    {
    CvCapture* capture = 0;
    IplImage* frame = 0;

    capture = cvCaptureFromCAM(CV_CAP_ANY);
    if(!capture)
    {
    printf("Could not initialise capturing...\n");
    }

    frame = cvQueryFrame(capture);

    ...
    }


    int main(int argc, char **argv)
    {
    // Initialize GLUT.
    glutInit(&argc, argv);

    // Set display mode as single-buffered and RGB color.
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);

    // Set OpenGL window size.
    glutInitWindowSize(500, 500);

    // Set position of OpenGL window upper-left corner.
    glutInitWindowPosition(100, 100);

    // Create OpenGL window with title.
    glutCreateWindow("Lumbar Tracking");

    // Initialize.
    setup();

    capture();

    // Register display routine.
    glutDisplayFunc(display);

    // Register reshape routine.
    glutReshapeFunc(resize);

    // Begin processing.
    glutMainLoop();

    return 0;
    }

  2. #2
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    Please use [code][/code] around source code.
    The error message contains the necessary hint: when calling capture() no display function is registered with GLUT, because you only register it in main() after the call to capture. Register your GLUT callbacks first, then call capture().

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    Thank you Carsten. This has definitely helped. T

    The problem I have now is that the OpenGL program runs through only once. If I comment out capture = cvCaptureFromCAM(CV_CAP_ANY) it runs continually (I've checked by initialising a counter and printing it to the screen using writeBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, str) after converting the number into a string).

    Your feedback would be gratefully appreciated.

    Gratefully,

    Marc

  4. #4
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    Hmm, does it perhaps crash in capture? Have you run it under a debugger? Does your code check for errors from OpenCV calls (sorry, not familiar with how OpenCV error reporting/handling works)? I don't have any more concrete suggestions, you could try posting all of the capture function.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    Hi Carsten, thanks again for getting back. You are right, it does crash in capture. I'll keep working on it and will get back when I have the solution. Your feedback has been most helpful. Thanks again

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2013
    Posts
    4
    I've got the code working. For some reason the OpenCV function would run once (function call within main() ). By moving the function call (capture()) to within the openGL display() function, this forces the tracker to recompute with each frame - now it works (a little clunky though). Not sure why it was called once from within main() though (unless capture() will not be affected by glutMainLoop())?

Similar Threads

  1. Help with Modern OpenGL Call Function to create Texture ?
    By pixie_laluna in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 11-22-2018, 08:36 AM
  2. Replies: 0
    Last Post: 06-19-2016, 07:19 AM
  3. OpenGL 3.3 glDrawElements, function call ignored.
    By cGln11 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-20-2014, 03:02 PM
  4. how can I call the function wglSwapIntervalEXT
    By GermanGuy in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 09-01-2014, 12:06 AM
  5. how can i call opengl from another Visual C++ program
    By Mystery in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 12-29-2002, 11:53 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean