简体   繁体   English

在iPhone模拟器中打印文本手势

[英]print text gesture in iPhone simulator

i am new to iPhone development, 我是iPhone开发新手,

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 在第一个图像没有任何东西,所以我想打印Entered symbol is not incorrect的第二个图像我在屏幕上写了A所以我想打印you selected: A

截图截图 here is a code snippet.. 这是一个代码片段..

declaration in .h file .h文件中的声明

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

code in .m file .m文件中的代码

- (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. 您可能想查看Tessarect,尽管为手机编译它还需要一些工作。

There's also Pocket OCR . 还有Pocket OCR

Then there is AABBY . 然后是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. 我不知道iOS已经开发了什么,但这只是我在另一个平台上如何做到这一点的简要描述。 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 . 智能交通系统应用的车牌识别算法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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