AlphaWallet / alpha-wallet-ios

An advanced Ethereum/EVM mobile wallet
https://www.alphawallet.com
MIT License
585 stars 360 forks source link

import Foundation #7113

Closed hboon closed 3 weeks ago

hboon commented 4 weeks ago

import SVGKit import AppKit import Vision

func convertSVGToImage(svgURL: URL) -> NSImage? { guard let svgImage = SVGKImage(contentsOf: svgURL) else { print("Failed to load SVG file.") return nil }

return svgImage.nsImage

}

func processImageWithVision(_ image: NSImage) { guard let cgImage = image.cgImage(forProposedRect: nil, context: nil, hints: nil) else { print("Failed to convert NSImage to CGImage.") return }

let requestHandler = VNImageRequestHandler(cgImage: cgImage, options: [:])
let request = VNRecognizeTextRequest { (request, error) in
    guard let observations = request.results as? [VNRecognizedTextObservation] else {
        print("Unexpected result type from VNRecognizeTextRequest.")
        return
    }

    for observation in observations {
        guard let topCandidate = observation.topCandidates(1).first else { continue }
        print("Recognized text: \(topCandidate.string)")
    }
}

do {
    try requestHandler.perform([request])
} catch {
    print("Failed to perform text recognition: \(error)")
}

}

func foo() { // Example usage: if let svgURL = URL(fileURLWithPath: "/Users/hboon/Documents/workspace/playground/remarkable-rmc-test/test.svg") let rasterImage = convertSVGToImage(svgURL: svgURL) { processImageWithVision(rasterImage) } }