Popular Posts

Wednesday, May 11, 2011

Worker Threads!

Many times you need to call a function/method that does some really heavy work. However, you don't want this function call to block your main application. You want to maintain a responsive GUI, for example!

This famous problem has a solution using multi-threading. From my background in the C++ Qt framework, I know the basic principles involved. And there is a very famous Qt example that explains how this "Worker Thread" solution can be implemented: The Madelbrot Example

Today I wanted to solve the same problem but in the C# (.Net Framework) context. Fortunately, the MSDN had a similar example that illustrates the solution to this problem, making use of the BackgroundWorker class:
http://msdn.microsoft.com/en-us/library/hybbz6ke.aspx

Reading and Writing .Net Applications Settings

Sometimes you have to deal with the .Net framework in a way or another. I was forced to use a .Net C# closed-source library. And that library was automatically reading file paths from ConfigurationManager.AppSettings[]. So, I needed a way to read and modify those settings. Fortunately, this post saved my life!

To read:
string value = ConfigurationManager.AppSettings["oldPlace"];


To modify/write:
System.Configuration.Configuration config =ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

config.AppSettings.Settings["oldPlace"].Value = "3";
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");


More information can be retrieved from the MSDN:
http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.appsettings.aspx

Sunday, May 8, 2011

Precision and Recall

One of the most important metrics used in evaluating the performance of binary classifiers is the Precision-Recall curve.

From Wikipedia:

It is possible to interpret precision and recall not as ratios but as probabilities:
* Precision is the probability that a (randomly selected) retrieved document is relevant.
* Recall is the probability that a (randomly selected) relevant document is retrieved in a search.




This page contains some illustrations to better understand the definitions of Precision and Recall:
http://newadonis.creighton.edu/hsl/searching/Recall-Precision.html

Also, this paper relates Precision-Recall curves to the Receiver Operator Characteristic curves:
http://www.biostat.wisc.edu/~page/rocpr.pdf

Finally, this page is further explaining the concepts and elaborating on the F-measure metric that tries to combine Precision and Recall into one measure:
http://streamhacker.com/2010/05/17/text-classification-sentiment-analysis-precision-recall/

Thursday, May 5, 2011

Splitting a video into frames using ffmpeg

I needed a quick way to split a video sequence into its individual frames and save those frames as images. FFmpeg seemed like a good handy solution. And the short answer is to do this:

ffmpeg -i inputfile.avi -f image2 image-%07d.png


This was a solution proposed in this thread. And for more information you can refer to the detailed documentation of FFmpeg.

PS: FFmpeg is available on Windows and you can get the installers here. If you just need the executable then download one of the static builds.