OpenCV: Brox Optical Flow Sample, possible fix

08 Sep 2012 . category: . Comments

I had some fun getting OpenCV with CUDA support and the demo to work that required OpenGL that for some yet unknown reason would not connect in properly. So I thought I would share my experience.

First of compile OpenCV with CUDA

image

 

You can also enable OpenGL, but this didn’t work for me yet it did enable the #define HAVE_OPENGL compile it up and copy out the brox example and make the following corrections, aka #defeine out the OPENGL window parts.

1 2 cout << "OpenCV / NVIDIA Computer Vision" << endl; 3 cout << "Optical Flow Demo: Frame Interpolation" << endl; 4 cout << "=========================================" << endl; 5 6 namedWindow("Forward flow"); 7 namedWindow("Backward flow"); 8 9 #ifdef HAVE_OPENGL 10 11 namedWindow("Needle Map", WINDOW_OPENGL); 12 setGlDevice(); 13 14 #endif 15 16 namedWindow("Interpolated frame"); 17 18

To note you may need to #undef HAVE_OPENGL. For a full easy run source you can get from here

 

Reference: Body of code taken from OpenCV Sample

 

basketball1basketball2

imageimage

Left – Forward Optical flow, Right – Backward Optical flow

 

Some interesting performance info for computation of Brox Optical Flow it took 0.01s, but the Image Copy to GPU took 6.485s [e.g. GpuMat d_frame0(frame0Gray) ]. This was on a laptop spec of i7 (8 thread), 10gb ram, GeForce GT540M 1GB. I will try on another machine sometime see if can get a faster performance specifically in image copy.

 

Note:

  • There may be a better way to overcome the OpenGL requirement this was just a quick work around
  • NVIDIA CUDA compiler does not currently support Visual Studio 2012 therefore for CUDA you need to use 2010.
  • </ul>
    Stuart James  ...


Stuart James

Assistant Professor in Visual Computing at Durham University. Stuart's research focus is on Visual Reasoning to understand the layout of visual content from Iconography (e.g. Sketches) to 3D Scene understanding and their implications on methods of interaction. He is currently a co-I on the RePAIR EU FET, DCitizens EU Twinning, and BoSS EU Lighthouse. He was a co-I on the MEMEX RIA EU H2020 project coordinated at IIT for increasing social inclusion with Cultural Heritage. Stuart has previously held a Researcher & PostDoc positions at IIT as well as PostDocs at University College London (UCL), and the University of Surrey. Also, at the University of Surrey, Stuart was awarded his PhD on visual information retrieval for sketches. Stuart holds an External Scientist at IIT, Honorary roles UCL and UCL Digital Humanities, and an international collaborator of ITI/LARSyS. He also regularly organises Vision for Art (VISART) workshop and Humanities-orientated tutorials and was Program Chair at British Machine Conference (BMVC) 2021.