Display image in second thread, OpenCV?

后端 未结 4 1377
鱼传尺愫
鱼传尺愫 2021-02-05 15:46

I have a loop to take in images from a high speed framegrabbger at 250fps.

/** Loop processes 250 video frames per second **/
while(1){
  AcquireFrame();
  DoPr         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 16:38

    Ok. So embarrassingly my question is also its own answer.

    Using CreateThread(), CvShowImage() and CvWaitKey() as described in my question actually works-- contrary to some postings on the web which suggest otherwise.

    In any event, I implemented something like this:

    /** Global Variables **/
    bool DispThreadHasFinished;
    bool MainThreadHasFinished;
    iplImage* myImg;
    
    /** Main Loop that loops at >100fps **/
    main() {
      DispThreadHasFinished = FALSE;
      MainThreadHasFinished = FALSE;
      CreateThread(..,..,Thread,..);
    
      while( IsTheUserDone() ) {
        myImg=AcquireFrame();
        DoProcessing();
        TakeAction();
      }
      MainThreadHasFinished = TRUE;
    
      while ( !DisplayThreadHasFinished ) {
         CvWaitKey(100);
      }
    
      return;
    }
    
    /** Thread that displays image at ~30fps **/
    Thread() {
      while ( !MainThreadHasFinished ) {
        cvShowImage(myImg);
        cvWaitKey(30);
      }
    DispThreadHasFinished=TRUE;
    return;
    }
    

    When I originally posted this question, my code was failing for unrelated reasons. I hope this helps!

提交回复
热议问题