Ios Swift 3-Tesseract可识别任何图像处理的抛出错误

Ios Swift 3-Tesseract可识别任何图像处理的抛出错误,ios,swift,swift3,avfoundation,tesseract,Ios,Swift,Swift3,Avfoundation,Tesseract,我正在使用Swift 3并开发一个应用程序,用户在其中拍摄照片并使用Tesseract OCR识别其中的文本 下面的代码块可以工作 func processPhoto() { if let tesseract = G8Tesseract(language: "eng") { tesseract.delegate = self // this is the resulting picture gotten after running the capture

我正在使用Swift 3并开发一个应用程序,用户在其中拍摄照片并使用Tesseract OCR识别其中的文本

下面的代码块可以工作

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()
    }
}
但是,如果我试图操纵图片(
stillPicture.image!
),我会得到以下错误:

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.
我操作图片的一些操作是旋转它:

// 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

再一次,轰!出现错误。你知道为什么会发生这种情况,为什么我的图像处理会引起问题吗?谢谢你的帮助

无论您对图像进行何种转换,都会以Tesseract无法理解的格式保留图像。Tesseract使用Leptonica库处理图像格式,Leptonica只能理解特定格式的图像

第一行:

Error in pixCreateHeader: depth must be {1, 2, 4, 8, 16, 24, 32}
这已经是一个很大的错误提示。位深度是指每像素有多少位。例如,24位图像通常是RGB-红色、绿色和蓝色各有8位(或一个字节)-总共24位。32位用于ARGB(RGB+alpha通道)。1位为单色

请参阅-pixCreateHeader是一个leptopnica函数

因此,请尝试以下操作-将图像保存到文件中,并在某个图像编辑器中打开它,检查它是什么类型的图像,尤其是位深度


显然,你的图像使用了一些奇怪的位深度。另外请看,因为这是我在pixCreateHeader中找到的唯一一个问题,
错误:深度必须是{1,2,4,8,16,24,32}
也提到了。

感谢您的回答。事实上,我甚至不知道是什么修复了它,但我取出了进行照片旋转的代码,照片仍在旋转(出于某种原因),没有更多的错误/@你是怎么修好的?我也有这个问题。