I am completely new with OpenCV. I started reading Learing OpenCV a few days ago and now I would like to do some tests.
I wanted to program an ASCII art conversor. I have done the image iteration and grouped pixels by squares to calculate each region brightness to associate it to a respective character. So now I need to know how bright is a character in order to link each image region to a character. My idea was to make another program that gives me the brightness of some characters. The approach is as follows:
I think that my program is ok, but I'm getting strange results... Just to check it, I am displaying the images with each character and something strange is going on. The image shows what I am talking about.
This is the code I am using:
...
char c = 'a'; //or whatever
IplImage *img = cvCreateImage(cvSize(150, 150), IPL_DEPTH_8U, 1);
char buffer[7];
sprintf(buffer, "%c", c);
CvFont font;
cvInitFont(&font, CV_FONT_HERSHEY_SIMPLEX, 0.5, 0.5);
cvPutText(img, buffer, cvPoint(2, 15), &font, cvScalar(255));
//iteration to calculate brightness will go here
cvNamedWindow(buffer);
cvShowImage(buffer, img);
cvMoveWindow(buffer, 50*(c-first), 20);
...
I am developing on MacOS Lion (if it helps...). Thank you for reading (and helping!).
You did not initialize the image content: you've just allocate the memory and you see some kind of memory garbage.
Just add cvSet(img, cvScalarAll(0)) to set your image to black.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With