简体   繁体   中英

print text gesture in iPhone simulator

i am new to iPhone development,

i want to print whatever user writes on the screen, i used gesture in my project,

see my screen shot,

in first image there is nothing, so i want to print Entered symbol is not incorrect in second image i wrote A in screen so i want to print you selected: A

截图截图 here is a code snippet..

declaration in .h file

    CGPoint lastPoint;
    UIImageView *drawImage;
    BOOL mouseSwiped;   
    int mouseMoved;

code in .m file

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    mouseSwiped = NO;
    UITouch *touch = [touches anyObject];

    if ([touch tapCount] == 2) {
        drawImage.image = nil;
        return;
    }

    lastPoint = [touch locationInView:self.view];
    lastPoint.y -= 20;

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    mouseSwiped = YES;

    UITouch *touch = [touches anyObject];   
    CGPoint currentPoint = [touch locationInView:self.view];
    currentPoint.y -= 20;


    UIGraphicsBeginImageContext(self.view.frame.size);
    [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
    CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
    CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
    CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
    CGContextBeginPath(UIGraphicsGetCurrentContext());
    CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
    CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
    CGContextStrokePath(UIGraphicsGetCurrentContext());
    drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    lastPoint = currentPoint;

    mouseMoved++;

    if (mouseMoved == 10) {
        mouseMoved = 0;
    }

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];

    if ([touch tapCount] == 2) {
        drawImage.image = nil;
        return;
    }


    if(!mouseSwiped) {
        UIGraphicsBeginImageContext(self.view.frame.size);
        [drawImage.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
        CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
        CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 5.0);
        CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1.0, 0.0, 0.0, 1.0);
        CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
        CGContextStrokePath(UIGraphicsGetCurrentContext());
        CGContextFlush(UIGraphicsGetCurrentContext());
        drawImage.image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
    }
}

when user double tapes the screen image will be cleared, i written this inside touches begin and touches end method at very start.

HOW CAN I IMPLEMENT THIS ?

Thanks In Advance !!

Well, you've chosen a rather ambitious project.

You might want to check out the Tessarect although it will take some work to even compile it for the phone.

There's also Pocket OCR .

Then there is AABBY .

An easy way to go is to standardize the size of your letters, just to make your code easier, then you would probably have to establish a font or a reference point. Say for example either you get an example of every letter of your user or you establish a "font", so that the user tries to imitate those letters. If you do that the best way to get results is by using the correlation coefficient of the identified letters with your references.

There is more than just the correlation coefficient, you also will probably have to run a few filters, first to make your image just black and white, because that's probably the easiest way to go, then you would have to separate squares (sub-matrixes) each corresponding to one letter and then re-sizing it or adjusting it to your references so that you can calculate the correlation coefficient and determine what letter it is.

This is a rather complex thing to talk about. I don't know what's already developed for the iOS but that's just a brief description on how I did this in another platform. Good luck and be sure to check the Signal Processing Forum for some help of the experts.

This article can probably give you a hint of the general idea in a much more detailed way. A License Plate-Recognition Algorithm for Intelligent Transportation System Applications .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM