AlphaWallet / alpha-wallet-ios

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

import Foundation #7114

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) } }

janviaroraa commented 3 weeks ago

Can you please specify the title in more detailed form? And what will the AC (if needs to be changed) and expection here? I'd like to work on this.

hboon commented 3 weeks ago

I'm sorry, I accidentally created this with a runaway script.