I spent an entire day getting OpenGL 4 to display data from a VAO with VBOs so I thought I’d share the results with you guys, save you some pain.
I’m using the excellent GL wrappers from Qt, and in particular QGLShaderProgram.
This is pretty straightforward, but the thing to remember is that OpenGL is looking for the vertices/other elements (color? tex coords?) to come from some bound GL buffer or from the host. So if your app is not working and nothing appears on screen, just make sure GL has a bound buffer and the shader locations match up and consistent (see the const int
I have on the class here).
Category: graphics
Sharing a small libjpeg snippet.
Some SO questions about it have only partial snippets:
- http://stackoverflow.com/questions/16390783/how-to-save-yuyv-raw-data-to-jpeg-using-libjpeg
- http://stackoverflow.com/questions/17029136/weird-image-while-trying-to-compress-yuv-image-to-jpeg-using-libjpeg
- http://stackoverflow.com/questions/19282402/how-to-compress-a-yuyv-image-into-a-jpeg
Enjoy!
Roy
Using Poppler, of course!
Poppler is a very useful tool for handling PDF, so I’ve discovered lately. Having tried both muPDF and ImageMagick’s Magick++ and failed, Poppler stepped up to the challenge and paid off.
So here’s a small example of how work the API (with OpenCV, naturally):
#include <iostream> #include <fstream> #include <sstream> #include <opencv2/opencv.hpp> #include <poppler-document.h> #include <poppler-page.h> #include <poppler-page-renderer.h> #include <poppler-image.h> using namespace cv; using namespace std; using namespace poppler; Mat readPDFtoCV(const string& filename,int DPI) { document* mypdf = document::load_from_file(filename); if(mypdf == NULL) { cerr << "couldn't read pdf\n"; return Mat(); } cout << "pdf has " << mypdf->pages() << " pages\n"; page* mypage = mypdf->create_page(0); page_renderer renderer; renderer.set_render_hint(page_renderer::text_antialiasing); image myimage = renderer.render_page(mypage,DPI,DPI); cout << "created image of " << myimage.width() << "x"<< myimage.height() << "\n"; Mat cvimg; if(myimage.format() == image::format_rgb24) { Mat(myimage.height(),myimage.width(),CV_8UC3,myimage.data()).copyTo(cvimg); } else if(myimage.format() == image::format_argb32) { Mat(myimage.height(),myimage.width(),CV_8UC4,myimage.data()).copyTo(cvimg); } else { cerr << "PDF format no good\n"; return Mat(); } return cvimg; }
All you have to do is give it the DPI (say you want to render in 100 DPI) and a filename.
Keep in mind it only renders the first page, but getting the other pages is just as easy.
That’s it, enjoy!
Roy.
Years ago I wanted to implement PTAM. I was young and naïve 🙂
Well I got a few moments to spare on a recent sleepless night, and I set out to implement the basic bootstrapping step of initializing a map with a planar object – no known markers needed, and then tracking it for augmented reality purposes.
You already know I love libQGLViewer. So here a snippet on how to do AR in a QGLViewer widget. It only requires a couple of tweaks/overloads to the plain vanilla widget setup (using the matrices properly, disable the mouse binding) and it works.
The major problems I recognize with getting a working AR from OpenCV’s intrinsic and extrinsic camera parameters are their translation to OpenGL. I saw a whole lot of solutions online, and I contributed from my own experience a while back, so I want to reiterate here again in the context of libQGLViewer, with a couple extra tips.
I came across an extremely simple color balancing algorithm here. And I thought I’ll quickly transcode it to OpenCV.
Here’s the gist:
Simple NURBS renderer [w/ code]
Don’t you just love scouring the web for a piece of simple code, come up short and then just write it yourself? Well that was the case with NURBS for me. These simple curvy lines, why doesn’t anyone just dish out a straightforward implementation of them? Well, now you have it. I wrote a simple renderer that reads a DXF file with NURBS (from Rhino3D) using DXFLIB, although the DXF file format is super easy to parse, and renders them to an image with OpenCV.
Phew. Finally this is working!
I’ve been confined to OpenGL 2.1 and GLSL 1.2 on the Mac since the Qt OpenGL context will not pick up the core OpenGL profile (a big problem on it’s own) and get an OpenGL 3.x and GLSL 1.5… So it’s back to old school GL’ing, but anyway some things are working, albeit they have their quirks.
So for all of you battling the OpenGL 2.1 war, here’s how I made VAOs work with a very simple shader.
For those of you still interested, I’ve made the move to using Qt and QGLViewer in the SfM-Toy-Lib project. Getting rid of PCL dependency (I think it’s a bloated library), and burying FLTK long in the past, I feel much better about it now.
Get it on github: https://github.com/royshil/SfM-Toy-Library