// find-latin: reads frames with Apple's Vision text recognition and prints every Latin-script line it finds, // with the frame's file name, the confidence and the box (x, y, width, height as fractions of the frame). // From AI & Things (https://aiandthings-film-method.vercel.app). macOS only. // // Use it to be sure an Arabic film shows no stray English line, even for one frame: // mkdir frames && ffmpeg -i film.mp4 -vf scale=1280:-1 -q:v 3 -start_number 0 frames/%04d.jpg // swiftc -O find-latin.swift -o find-latin // ./find-latin frames/*.jpg > latin.tsv // Then read latin.tsv. Your brand name and real interface labels will be listed too: those are expected. // Arabic text can come back as short Latin noise; ignore lines that are not words. import Vision import AppKit for path in CommandLine.arguments.dropFirst() { guard let image = NSImage(contentsOfFile: path), let cg = image.cgImage(forProposedRect: nil, context: nil, hints: nil) else { continue } let request = VNRecognizeTextRequest() request.recognitionLevel = .accurate request.recognitionLanguages = ["en-US"] request.usesLanguageCorrection = false try? VNImageRequestHandler(cgImage: cg).perform([request]) for observation in request.results ?? [] { guard let best = observation.topCandidates(1).first else { continue } let b = observation.boundingBox let name = (path as NSString).lastPathComponent print("\(name)\t\(best.string)\t\(String(format: "%.2f", best.confidence))\t\(String(format: "%.2f,%.2f,%.2f,%.2f", b.minX, 1 - b.maxY, b.width, b.height))") } }