Thursday, January 20, 2011

HK Smartone-Vodaphone, iPhone, Voicemail

Just realized that there is a rewind function in your smartone-vodaphone voicemail.

While listening to the voicemail, you can always press 1 for rewinding.
Even after the operator prompts for your inputs to either skip to the next voicemail or store the current voicemail, you can still press 1 to rewind! COOL!

Sunday, January 16, 2011

OpenCV + Visual Studio 2010 [I]

This entry documents my upcoming trials to solve the vs2010 + opencv 2.x problem.

To date, i have been able to run OpenCV 2.1 with VS2010 in Release mode. Precisely speaking, linking to release library of OpenCV 2.1 works without problems, but linking to debug library of OpenCV2.1(cv210d.lib, cxcore210d.lib, highgui210.lib)[1] wont' let me proceed.

#include "stdafx.h"
#include \
#include \
#include \

int _tmain(int argc, _TCHAR* argv[])
IplImage *img = cvLoadImage("C:\\output.JPG");

return 0;
The above code can be compiled and executed without the infamous curse: "0 x c0150002".
To run without the infamous curse in Release mode, i only needed to install the VS2010 redistributable package[]

However, in debug mode, i still don't have much luck.

[1] Apparently, linking to cv210d.lib proceeded without errors; the problems emerge when linking the other two d-libs.

Wednesday, January 12, 2011

The art of toggling

Toggline is the idea is to set something that is originally to true to false and vice versa. Or, precisely speaking, we want to negate the logical value.

Say, you originally declared a variable: (let's walk this through in C#)

private bool someValue= false;

In some codes, we often see ...

public void toggleSomeValue(bool b)
this.someValue = b;
However, the above is not exactly toggling. It's more like setting someValue to some arbitrary value that you demand.

It should be re-written as:

public void toggleSomeValue()
this.someValue = !this.someValue;

public void toggle(bool someValue)
// if someValue is declared as class variables
someValue = !someValue;


public bool toggle(bool someValue)
// you actually don't need this, but FYI.
return !someValue;

Then, down the page, you would have a function that makes use of the toggled value

public void doSomethingBasedOnSomeValue()
//do this
//do that

toggleSomeValue(); //or toggle(this.someValue);

-my tuppence worth

Wednesday, January 5, 2011

OpenCV and IOS

Very good material!
Thanks Yoshimasa Niwa.

// NOTE you SHOULD cvReleaseImage() for the return value when end of the code. - (IplImage *)CreateIplImageFromUIImage:(UIImage *)image {   // Getting CGImage from UIImage   CGImageRef imageRef = image.CGImage;    CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();   // Creating temporal IplImage for drawing   IplImage *iplimage = cvCreateImage(     cvSize(image.size.width,image.size.height), IPL_DEPTH_8U, 4   );   // Creating CGContext for temporal IplImage   CGContextRef contextRef = CGBitmapContextCreate(     iplimage->imageData, iplimage->width, iplimage->height,     iplimage->depth, iplimage->widthStep,     colorSpace, kCGImageAlphaPremultipliedLast|kCGBitmapByteOrderDefault   );   // Drawing CGImage to CGContext   CGContextDrawImage(     contextRef,     CGRectMake(0, 0, image.size.width, image.size.height),     imageRef   );   CGContextRelease(contextRef);   CGColorSpaceRelease(colorSpace);    // Creating result IplImage   IplImage *ret = cvCreateImage(cvGetSize(iplimage), IPL_DEPTH_8U, 3);   cvCvtColor(iplimage, ret, CV_RGBA2BGR);   cvReleaseImage(&iplimage);    return ret; } 

Don’t forget release IplImage after using it by cvReleaseImage!

And creating UIImage from IplImage is like this.

// NOTE You should convert color mode as RGB before passing to this function - (UIImage *)UIImageFromIplImage:(IplImage *)image {   CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();   // Allocating the buffer for CGImage   NSData *data =     [NSData dataWithBytes:image->imageData length:image->imageSize];   CGDataProviderRef provider =     CGDataProviderCreateWithCFData((CFDataRef)data);   // Creating CGImage from chunk of IplImage   CGImageRef imageRef = CGImageCreate(     image->width, image->height,     image->depth, image->depth * image->nChannels, image->widthStep,     colorSpace, kCGImageAlphaNone|kCGBitmapByteOrderDefault,     provider, NULL, false, kCGRenderingIntentDefault   );   // Getting UIImage from CGImage   UIImage *ret = [UIImage imageWithCGImage:imageRef];   CGImageRelease(imageRef);   CGDataProviderRelease(provider);   CGColorSpaceRelease(colorSpace);   return ret; }