Friday 26 August 2011

Text manipulations in OpenCV

Hello All,


This is regarding text operations we do in image processing using OpenCV.

All of the OpenCV users know the power of OpenCV regarding image processing operations but sometimes we need to some text manipulations operations in OpenCV. Some of the operations are as follows:
1) Text to be put on the image
2) Underline the text
3) Strike through the text
4) Wrap the text
5) Puting text in vertical direction like
O
P
E
N
C
V
6) Making text bold and italic.

These are the few operations for which i searched extensively on google to get some help but was not successful as OpenCV is more involved in image processing arena than playing with text.
So here I will tell the approach so that other people who try to get help can apply the approach and if they have better approach, then kindly inform me :)

PUTTING TEXT

OpenCV has a function name cvputtext() which helps in doing this operation. This is one of the simple operations as you just need to specify the corrdinates, font type and size of text in the input parameter list.
Format of using the function is :
cvPutText(CvArr* img, const char* text, CvPoint org, const CvFont* font, CvScalar color)
  • img – The image
  • text – The text string to be drawn
  • org – The bottom-left corner of the text string in the image
  • fontFace – The font type, one of FONT_HERSHEY_SIMPLEX , FONT_HERSHEY_PLAIN , FONT_HERSHEY_DUPLEX , FONT_HERSHEY_COMPLEX , FONT_HERSHEY_TRIPLEX , FONT_HERSHEY_COMPLEX_SMALL , FONT_HERSHEY_SCRIPT_SIMPLEX or FONT_HERSHEY_SCRIPT_COMPLEX ,
    where each of the font id’s can be combined with FONT_HERSHEY_ITALIC to get the slanted letters.
  • fontScale – The font scale factor that is multiplied by the font-specific base size
  • color – The text color
  • thickness – Thickness of the lines used to draw the text
  • lineType – The line type; see line for details
 Example:Check out this tutorial:
http://nashruddin.com/OpenCV_Examples_Part_2

2) UNDERLINE TEXT
Basic Algorithm to underline the text is as follows:
  • Get the text height and text width
  • Generate two points keeping in mind the text height and width. ( one point will be zeroth coordinate of height and width and othe rwill be zeroth point of height and max width point.
  • use cvLine to connect the points so as to get the text underlined.
NOTE: Make sure to take into account the font thickness into consideration.

3) STRIKE OUT TEXT
The algorithm is as follows 

  • Get the text height and text width.
  • Generate two points ( one point at the middle of height and at the starting of the text and othe rpoint at the end of the text and at half the text size.
  • Use cvLine to connect these two points. It will generate the effect of Underline.
 NOTE: Make sure to take the font size factor into account.

4) WRAP TEXT
I basically used some intrinsic functions of C++ to implement this.
Basic Algorithm is as follows:
  • Firstly find the text size which will have thew information about text size width. Depending on ratio of text width and image width, we can find out if we need to wrap the text or not.
  • If text width is larger than the image width, we need to wrap it and we can find out how many times we need to wrap it.
  • Depending on ratio of text width and image width, we can extract sub-string using C++ intrinsic substr() and put the text extracted using cvPutText.
  • Do it till all the text is wrapped on the image.
5) VERTICAL TEXT

This is one of the functionality which is interesting and involved some discussion with my colleagues. It involves uses of OpenCV with several intrinsocs of C++.
Basic Algorithm is as follows:
  • use strtok() to split the string into tokens. I have seen in some blogs and forum regarding not using strtok() stating memory issues but you can search for other alternatives which have been mentioned in forums.
  • For each token, use substr() to extract each character from the token carefully using the parameters of substr().
  • Use cvPuttext  according for putting each character obtained.
NOTE: Take care of the space which need to be placed between each token of string.

6) MAKING TEXT BOLD AND ITALIC 

This is easy as compared to other above mentioned functionality. Basically we can get the effect by just manipulating the cvInitfont() parameters.
cvInitFont() is defined as :
cvInitFont(CvFont* font, int fontFace, double hscale, double vscale, double shear=0, int thickness=1, int lineType=8)


For understanding on parameters,consult opencv willow-garage documentation 2.0.

In this article, I tried to tell the basic algorithmic approach. In case someone needs the code, just contact me and I can help in that regard.

Saturday 19 March 2011

After Haircut

After working in temperature above 40 degrees and suddenly someone comes and gives you a chilled Coca Cola bottle to sip...how does that feel!!! PRICELESS!!!

For me this was the same feeling when I took a haircut after 6 long long months. My hairs were all around me.All tangled among themselves, some lying just like that without giving a damn to other side of my head. But somethings I loved about long hairs are:
*  You can move your hand in your hairs when you see someone whose hairs are falling at an uncontrollable rate or a bald person. Thats when you realize the importance of Hairs whom you curse every time you go in front of mirror.

* You can make all types of hairstyle and tails..ponny...etc and try all the crazy stuff.

* After the bath, it feels good when you move your head from one side to another in a flash, you can feel all the hairs going in the same way.

But sometimes, long hairs can be a mess also.
*You have to everyday comb them..I hate that part :P 

* While sleeping, they can move all around your face and it feels like some animal is crawling which can sometime wake you up in the middle of night and then you fell like cutting the hairs at that moment.

But after the haircut, the first best thing which happened to me was when I took a bath and went outside to keep my towel in the sun, wave of cold air blew over me and my head felt so good as if somebody opened a cooler in the summer. It was amazing feeling. But I misses certain things now.

* I can't use the comb. After the bath, I took my comb and went in front of mirror and then I realize...OH la la!! No hairs to comb!!! I felt sorry for my comb and said to it...Happy Days over mate!!!

* After the  bath, when I move my head in flash, instead of hairs flowing, water droplets fall all over.

But the best part is that now no-more insect crawling feeling and I can enjoy my dreams.

By the way, by haircut, I meant really small Hairs :)

Saturday 5 March 2011

Information about free webhosting and domain name

Hello all,

here I will tell how one can register for free domain name and one of the reliable free web hosting service.

Step 1: Create a domain name. There are many services which provides free domain name but one can choose co.cc as it is simple and easy to remember. So one can register on www.co.cc  and register his/her domain name.

Step by Step guide for www.co.cc

1) Check for availability of the domain name.
2) You will see the response like this


Continue to Registration.

3) You are done with the domain registration.


Step 2: Registering for the free web hosting space:- While I was registering my websites, I went through many websites  which provide free web space. After checking many of those, i find 000webhost good in service and easy to use. So one can register on this website http://www.000webhost.com/




  Click on order now and you will see this window:
Now Enter your domain name which you have registered on CO.CC.

After creating your account, a mail will be sent to you regarding your account information , FTP and DNS.

Now Go back to your co.cc account and login. You will see this window :
Click on your Domain name then you see this:
 Go to Setup and enter these name servers in the field

Check on Apply this setting option and click on Setup.
You are done. Congratulation!!!
Now just upload the webpages on webhost servers through FTP.

In case you face some issue, just mail to me at deepak19dec@gmail.com or visit www.deepakkumarjain.co.cc

Enjoy!!!