My recent visit to Chennai’s City Centre Mall changed my daily routine. I have a very bad habit of buying books whenever I stroll in to a bookstore to have a look. I visited the ubiquitous Landmark and my eyes struck a copy of “Learning OpenCV” by Gary Bradski and Adrian Kaehler.
I was educated about OpenCV quite a long time back but I never got an opportunity to get my hands on it. I bought this copy to realize my wishes. I have been struggling to write my “Hello World example” using the OpenCV libraries.
I hope you had read my earlier post on building the OpenCV library. I am a beginner in C++ programming and I felt it quite difficult to understand the arguments and commands used with the OpenCV library.
However, this tutorial by Gavin Page came to the rescue:
OpenCVTutorial_I
My new image read “Hello world!” Yupeee.
When I compiled my first code from the book, I was happy enough to press the “Start Debugging”
Now this was the error that I received 😦
I couldn’t understand what was going on. The author has made a special mention that:
A proper program would check for the existence of argv[1] and, in its absence, deliver an instructional error message for the user. We will abbreviate such necessities in this book and assume that the reader is cultured enough to understand the importance of error handling code.
I was shocked to read this. Since I had a friend who is an expert in programming, he told me that that I am using a command line argument function
He told me that I either had to use a file pointer or a command prompt to execute the code correctly.
So I searched the web for this information and found that my friend was right. I had to go to the directory where my compiled exe file is located and pass the image file as an argument to the exe file.
This is how you are supposed to do it
>opencv.exe F:\affidavit.jpg
Bingo! I was able to load my image. Now, I wanted to load a video using the example from the book. I wasn’t cultured enough to understand the problem behind the code once again. The code execution was perfect but no video was loaded!
Google came to the rescue. This is what OpenCV wiki had to say.
You have to use tools like mencoder to convert the avi files into compatible formats.
This is the command I used for the mencoder.exe file
>mencoder.exe in.avi -ovc raw -vf format=i420 -o out.avi
Please note that the converted video is of a bigger file size.
After conversion, you may execute the converted file as follows:
>opencv.exe out.avi
I am worried about the n number of surprises that I would come across in the days to come 😦