Jan 27

Bootstrap3 fluid container with custom width sidebar

I was looking for a way to get a fluid container live side-by-side with a custom width sidebar.
A custom width sidebar can't be achieved with a Bootstrap column, and is a total mess to get right with floats if you then need a fluid container to get a grid system for the main section.
So, here's one solution:

JSFiddle: https://jsfiddle.net/6sfog80k/


Jan 15

YUYV to JPEG conversion with libjpeg

Sharing a small libjpeg snippet.

Some SO questions about it have only partial snippets:



Aug 03

Smallest ATTiny45 USB

USB ATTiny45-20

USB ATTiny45-20

Just wanted to report on completing a quick electronics prototyping project - making a very tiny ATTiny45-based simple USB dongle.
Read the rest of this entry »


May 08

Quickly: How to render a PDF to an image in C++?

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;
    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) {
    } else if(myimage.format() == image::format_argb32) {
    } 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!


Apr 20

מאגר שמות ישראליים בעברית - Israeli hebrew names dataset

זהו פוסט ראשון בבלוג בעברית, מאחר והוא דן בנושא שמות ישראליים בעברית. לאחרונה יצא לי להתעסק בכריית שמות מדפי אינטרנט ומהר הבנתי שלא אתקדם הרבה אם לא תהיה לי רשימת מילים שהן למעשה שמות, כדי להפריד בקלות את הטקסט מהשמות.
לא מצאתי רשימה כזו פשוטה, למרות שבאתר מ.י.ל.ה של הטכניון יש לקסיקון די נרחב של מילים בעברים עם טיוג גם לשמות. למרות שאפשר בקלות לדלות משם את השמות עם JAXB על הסכמה של הXML, לא עשיתי זאת מפאת חוסר זמן וקוצר רוח.
אז עשיתי רשימה בעצמי. התחלתי ממאגר שמות שקיים אצלי ופירקתי לשם פרטי ומשפחה באמצעות רווחים, ולאחר מכן התחלתי במלאכת הכרייה שהוסיפה הרבה מאוד שמות למאגר.
לאחר מכן חזרתי למאגר שלי ומניתי את המופעים של כל שם כשם פרטי ושם משפחה, כדי לעזור בכרייה עתידית. כך אפשר למצוא עוד שמות למשל אם לוקחים את המילה שבאה לפני שם משפחה מובהק מאוד.
עם זאת ישנם שמות מאוד מבלבלים מבחינת שיוך לשם פרטי או משפחה, למשל "גל", "שלום", או "ברק". לעומתם שמות מובהקים לכאן או לכאן כמו "אהוד" או "לוי"

בכל מקרה, הנה הרשימה לשימושכם החופשי.
נא לקחת בחשבון שזו רשימה חלקית ביותר, וכן המנייה של השמות חלקית ביותר גם היא.

This is the first hebrew speaking post on the MTT blog, since it speaks of names in Hebrew. This is also not a translation of the above text, just a preamble to it. I've collected a list of Hebrew first and last names and counted the number of times a name appears as first and last on a private database of names. The result may be useful for someone extracting Hebrew names from the web.



Mar 16

Bootstrapping planar AR and tracking without markers [w/code]

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.
Read the rest of this entry »


Mar 09

Apache Tapestry 5 Progress Bar with jQuery+Bootstrap [w/code]

Just sharing a code snippet about how to implement a jQuery+Bootstrap progress bar for a background operation in Tapestry 5. There's not a lot to it, but it took me a while and serious digging through the internet to find how to make it work. Essentially it's based on a couple of examples and references I found:

But I simplified things because I don't like the over-design Java can easily make you do...
Read the rest of this entry »


Feb 17

Augmented Reality on libQGLViewer and OpenCV-OpenGL tips [w/code]

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.
Read the rest of this entry »


Feb 07

Simplest 20-lines OpenCV video stabilizer [w/ code]

Just sharing a simple recipe for a video stabilizer in OpenCV based on goodFeaturesToTrack() and calcOpticalFlowPyrLK().
Well... it's a bit more than 20 lines, but it is short. And it doesn't work for every kind of video (although the results are funny anyway! :).
Read the rest of this entry »


Feb 05

Using Hidden Markov Models for staff line removal (in OMR) [w/code]

So lately I'm into Optical Music Recognition (OMR), and a central part of that is doing staff line removal. That is when you get rid of the staff lines that obscure the musical symbols to make recognition much easier. There are a lot of ways to do it, but I'm going to share with you how I did it (fairly easily) with Hidden Markov Models (HMMs), which will also teach us a good lesson on this wonderfully useful approach.

OMR has been around for ages, and if you're interested in learning about it [Fornes 2014] and [Rebelo 2012] are good summary articles.
The matter of Staff Line Removal has occupied dozens of researchers for as long as OMR exists; [Dalitz 2008] give a good overview. Basically the goal is to remove the staff lines that obscure the musical symbols, so they would be easier to recognize.
Screen Shot 2015-01-24 at 10.11.00 PM
But, the staff lines are connected to the symbols, so simply removing them will cut up the symbols and make them hardly recognizable.
So let's see how we could do this with HMMs.
Read the rest of this entry »


Older posts «

» Newer posts