簡體   English   中英

在iPhone模擬器中打印文本手勢

[英]print text gesture in iPhone simulator

我是iPhone開發新手,

我想打印任何用戶在屏幕上寫的內容,我在我的項目中使用了手勢,

看我的屏幕截圖,

在第一個圖像沒有任何東西,所以我想打印Entered symbol is not incorrect的第二個圖像我在屏幕上寫了A所以我想打印you selected: A

截圖截圖 這是一個代碼片段..

.h文件中的聲明

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

.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();
    }
}

當用戶雙重磁帶時,屏幕圖像將被清除,我寫入內部觸摸開始並觸摸結束方法。

我該如何實施?

提前致謝 !!

好吧,你選擇了一個相當雄心勃勃的項目。

您可能想查看Tessarect,盡管為手機編譯它還需要一些工作。

還有Pocket OCR

然后是AABBY

一個簡單的方法是標准化字母的大小,只是為了使代碼更容易,然后你可能需要建立一個字體或參考點。 比如說,要么得到用戶的每個字母的示例,要么建立“字體”,以便用戶嘗試模仿這些字母。 如果這樣做,獲得結果的最佳方法是使用已識別字母與引用的相關系數。

不僅僅是相關系數,你可能還需要運行一些濾鏡,首先要使你的圖像只是黑白,因為這可能是最簡單的方法,那么你必須分開正方形(子矩陣) )每個字母對應一個字母,然后重新調整大小或將其調整為您的參考,以便您可以計算相關系數並確定它是什么字母。

這是一個相當復雜的事情。 我不知道iOS已經開發了什么,但這只是我在另一個平台上如何做到這一點的簡要描述。 祝你好運,一定要查看信號處理論壇 ,尋求專家的幫助。

本文可能會以更詳細的方式向您提供一般概念的提示。 智能交通系統應用的車牌識別算法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM