2015-01-15 1 views
0

OCR (Tesseract)을 사용하여 그림을 스캔하고 있습니다. 그러나 Tesseract는 "주방"과 "감자"와 같은 단어와 단어를 인식 할 때 항상 정확하지는 않습니다. "k1thn"과 "oolat0"으로 인식 될 수 있습니다.대리자 메서드가 완료되었을 때 NSArray의 다음 항목을 반복합니다.

이 올바르지 않은 단어를 '교정'하려면 라이브러리 PermissiveResearch을 사용하여 사전 정의 된 가능한 단어 목록을 검색하고 다시 일치 시키려합니다.

라이브러리는 놀랍게도 잘 작동하지만 한 가지 단점이 있습니다. 대형 데이터 소스에서이라는 단어를 으로 검색하면 빌드됩니다. OCR 스캔의 결과는 여러 단어의 NSArray입니다.

그래서 할 수있는 논리적 인 일이 같은 NSArray를 반복하는 것입니다 :

for (ScannedWord *scannedWord in inputArray) { 
    [[PermissiveResearchDatabase sharedDatabase] searchString:scannedWord.name withOperation:ScoringOperationTypeExact]; 
} 

I는 데 문제의 검색 결과가 위임 방법에 잡힌 것을 (-(void)searchCompletedWithResults:(NSArray *)results)입니다 검색이 끝나면 번만 이라고합니다. 비록 NSArray를 반복하고 [[PermissiveResearchDatabase sharedDatabase] searchString:scannedWord.name withOperation:ScoringOperationTypeExact];을 여러 번 호출한다고해도 말입니다.

이 라이브러리를 사용하여 NSArray에서 허용 검색을 수행하려면 어떻게해야합니까?

아니면 다른 라이브러리를 사용하는 다른 접근 방식을 권장합니까?

+0

봐 같은 것을 사용할 수 있어야 여부를 명확하지 않다 : withOperation : '. 한 번에 하나씩 만 허용되며 검색은 비동기 적으로 수행됩니다. 따라서 루프가 검색을 시작하지만 각 반복은 이전 검색을 취소하고 새 반복을 시작합니다. 그래서 마지막 하나만 완료됩니다. – rmaddy

+0

@rmaddy. 내 질문은이 라이브러리를 동 기적으로 사용하는 방법 또는 여러 가지 검색을 허용하는 다른 방법입니다. – Galip

+0

해당 라이브러리를 살펴보면 편리한 메소드 인 searchString : withOperation :을 사용하는 대신 기본 작업을 사용해야하며,이를 자신의 큐에서 자체 완성 블록으로 대기열에 넣을 수 있습니다. 'searchString : withOperation :'에 대한 소스 코드와 문서 (https://github.com/leverdeterre/PermissiveResearch#create-your- first-search-operation)의 예를 보면 – Paulw11

답변

0

나는 이것을 테스트하지 않았습니다, 그리고 PermissiveResearch 라이브러리 동시 작업을 지원하지만이되는 searchString`의 코드에서이

NSOperationQueue* aQueue = [[NSOperationQueue alloc] init]; 

// If you find problems with concurrency you can limit the queue to a single operation at a time - 
// aQueue.maxConcurrentOperationCount=1;  

NSMutableArray *outputArray=[inputArray mutableCopy]; 

NSMutableArray *operationArray=[NSMutableArray new]; 

for (int i=0;i<inputArray;i++) { 

    operation = [ExactScoringOperation new]; 

    operation.searchedString = inputArray[i]; 

    SearchCompletionBlock block = ^(NSArray *results) { 
     @synchronized(outputArray) { 
      outputArray[i]=results[0]; 
     } 
    }; 

    [operation setCustomCompletionBlock:block]; 
    [operationArray addObject:operation]; 

} 

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ 
    [aQueue addOperations:operationArray waitUntilFinished:YES]; 

    // Output array now contains the updated words. 
    // Perform any UI updates on the main queue 
}); 
+0

는 매력처럼 작동합니다. :) – Galip

1

일치 단어를 inputArray에서 한 단어 만 시작하고 나머지는 위임 방법에서 계속할 수 있습니까?

가 시작

:

self.copyArray = [inputArray mutableCopy]; 
NSDictionary * scannedWord = [self.copyArray objectAtIndex:0]; 
[copyArray removeObjectAtIndex:0]; 
[[PermissiveResearchDatabase sharedDatabase] searchString:scannedWord.name withOperation:ScoringOperationTypeExact]; 

INSIDE 대의원 (성공 또는 오류에 inputArray

if(self.copyArray.count > 0) 
{ 
    NSDictionary * scannedWord = [self.copyArray objectAtIndex:0]; 
    [copyArray removeObjectAtIndex:0]; 
    [[PermissiveResearchDatabase sharedDatabase] searchString:scannedWord.name withOperation:ScoringOperationTypeExact]; 
} 

이 방법의 처리를 계속하는, 당신은 Scynhronously inputArray 요소를 반복 할 것입니다 어떤 요소가 생략되지 않습니다 내 의견.

덧붙여 말하자면 나는 xcode이 없으므로 코드에 오타가있을 수 있습니다.

+0

@rmaddy는 주석에서 코드 블록 옵션으로 '깨끗한'방법을 사용하는 편이 좋을 것이라고 제안했습니다. – Galip

+0

나는 모든 코멘트를 펼치지 않았다고 생각한다. 죄송합니다. ('NSOperationQueue'를 사용하고'maxConcurrentOperationCount'를 1로 설정하는) 클리너 방식은 여러분의 필요에 따라 과도하게 사용됩니다. – aytunch

+0

'NSInvocationOperation'에'addDependency'라는 메소드가 있습니다. 다음을 시작하는 의존성으로 이 스타일이 마음에 들면 코드를 공유 할 수 있습니다. – aytunch

관련 문제