2017-03-13 6 views
1

저는 Swift 3을 사용하고 사용자가 사진을 찍고 Tesseract OCR을 사용하여 텍스트를 인식하는 응용 프로그램을 개발 중입니다.Swift 3 - Tesseract는 이미지 조작에 대한 던지기 오류를 인식합니다.

다음 코드 블록이 작동합니다.

Error in pixCreateHeader: depth must be {1, 2, 4, 8, 16, 24, 32} 
Error in pixCreateNoInit: pixd not made 
Error in pixCreate: pixd not made 
Error in pixGetData: pix not defined 
Error in pixGetWpl: pix not defined 
2017-03-13 11:13:05.336796 ProjectName[35238:9127211] Cannot convert image to Pix with bpp = 64 
Error in pixSetYRes: pix not defined 
Error in pixGetDimensions: pix not defined 
Error in pixGetColormap: pix not defined 
Error in pixClone: pixs not defined 
Error in pixGetDepth: pix not defined 
Error in pixGetWpl: pix not defined 
Error in pixGetYRes: pix not defined 
Please call SetImage before attempting recognition.Please call SetImage before attempting recognition.2017-03-13 11:13:05.343568 EOB-Reader[35238:9127211] No recognized text. Check that -[Tesseract setImage:] is passed an image bigger than 0x0. 

나는 사진을 회전하는 조작 할 몇 가지 :

나는 모든 ( stillPicture.image!)에서 사진을 조작하려고하면

func processPhoto() { 
    if let tesseract = G8Tesseract(language: "eng") { 
     tesseract.delegate = self 

     // this is the resulting picture gotten after running the capture delegate 
     tesseract.image = stillPicture.image! 
     tesseract.recognize() 
    } 
} 

그러나, 나는 다음과 같은 오류가 발생합니다

// Rotate taken picture 
let orig_image = stillPicture.image! 

let new_image_canvas = UIGraphicsImageRenderer(size: CGSize(width: stillPicture.image!.size.height, 
                    height: stillPicture.image!.size.width)) 
let new_image = new_image_canvas.image { _ in 
    let curr_context = UIGraphicsGetCurrentContext()! 
    curr_context.translateBy(x: 0, y: stillPicture.image!.size.width) 
    curr_context.rotate(by: -.pi/2) 
    stillPicture.image!.draw(at: .zero) 
} 

tesseract.image = new_image 

내가 그렇게하면 붐! 위의 오류가 발생합니다.

내가하는 또 다른 조작은 이미지의 일부를 잘라내는 것입니다.

let finalImage : UIImage 

let crop_section = CGRect(x: 590.0, y: 280.0, width: 950.0, height: 550.0) 

let cg_image = stillPicture.image!.cgImage?.cropping(to: crop_section) 
finalImage = UIImage(cgImage: cg_image!)  

tesseract.image = final_image 

또 다시, 붐! 오류가 나타납니다. 왜 이런 일이 일어나고 내 이미지 조작으로 인해 문제가 발생하는지 생각해보십시오. 당신의 도움을 주셔서 감사합니다!

답변

1

이미지를 변형해도 Tesseract가 이해할 수없는 형식으로 남겨 둡니다. Tesseract는 Leptonica 라이브러리를 사용하여 이미지 형식을 처리하고 Leptonica는 특정 형식의 이미지 만 이해할 수 있습니다.

첫 번째 줄 :

Error in pixCreateHeader: depth must be {1, 2, 4, 8, 16, 24, 32} 

이미 오류가 무엇인지에 큰 힌트입니다. 비트 심도는 사용자가 보유한 픽셀 당 몇 비트를 의미합니다. 예를 들어, 24 비트 이미지는 대개 RGB입니다. 빨간색, 녹색 및 파란색 각각 8 비트 (또는 1 바이트)가 있습니다. 총 24 비트입니다. 32 비트는 ARGB (RGB + 알파 채널) 용입니다. 1 비트는 흑백입니다.

http://search.cpan.org/dist/Image-Leptonica/lib/Image/Leptonica/Func/pix1.pm#pixCreateHeader 참조 - pixCreateHeader는 leptopnica 기능입니다.

다음을 시도해보십시오 - 이미지를 파일로 저장하고 일부 이미지 편집기에서 열고 어떤 이미지 유형인지 확인하십시오 (예 : esp). 비트 깊이.

분명히 당신의 이미지는 이상한 비트 깊이를 사용하고 있습니다. 또한 이것이 Error in pixCreateHeader: depth must be {1, 2, 4, 8, 16, 24, 32}도 언급 된 유일한 질문이기 때문에 Node.js 20x slower than browser (Safari) with Tesseract.Js을보십시오.

+0

답변 해 주셔서 감사합니다. 실제로, 나는 그것을 고칠 수있는 것을 모르지만, 나는 내 사진 회전을 한 코드를 꺼내었고, 사진은 여전히 ​​(어떤 이유로) 회전되어 있고 더 이상 오류가 없다. : / – noblerare