3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

画像からテキストを読み取る

日本語も読める。

lazy var textRecognitionRequest = {
    var request = VNRecognizeTextRequest(completionHandler: recognizeTextHandler)
    if #available(iOS 16.0, *) {
        request.automaticallyDetectsLanguage = true
    } else {
        request.recognitionLanguages = ["ja-JP"]
    }
    request.recognitionLevel = .accurate
    return request
}()

func recognizeTextHandler(request: VNRequest, error: Error?) {
    
    guard let results = self.textRecognitionRequest.results else {return}
    for observation in results {
        let label = observation.topCandidates(1)[0].string
        let box = observation.boundingBox
        let confidence = observation.confidence
        print(label)
        print(box)
        print(confidence)
    }
}

func performTextRecognition(cgImage:CGImage) {
    do {
        let requestHandler = VNImageRequestHandler(cgImage: cgImage)
        try requestHandler.perform([self.textRecognitionRequest])
    } catch _ {}
}

スクリーンショット 2024-03-30 7.55.28.png

縦書きは読めない。

🐣


フリーランスエンジニアです。
AIについて色々記事を書いていますのでよかったらプロフィールを見てみてください。

もし以下のようなご要望をお持ちでしたらお気軽にご相談ください。
AIサービスを開発したい、ビジネスにAIを組み込んで効率化したい、AIを使ったスマホアプリを開発したい、
ARを使ったアプリケーションを作りたい、スマホアプリを作りたいけどどこに相談したらいいかわからない…

いずれも中間コストを省いたリーズナブルな価格でお請けできます。

お仕事のご相談はこちらまで
rockyshikoku@gmail.com

機械学習やAR技術を使ったアプリケーションを作っています。
機械学習/AR関連の情報を発信しています。

X
Medium
GitHub

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?