Avatar
前々から作りたいと思ってたのを試しに実装してみました。とりあえず動くようにしただけなので実装がかなり雑ですが・・・。色々不具合もあるかもしれません。 https://github.com/koher/EasyCamery
Contribute to EasyCamery development by creating an account on GitHub.
4:19 AM
↓みたいに使えます。 import UIKit import AVFoundation import EasyCamery import EasyImagy class ViewController: UIViewController { @IBOutlet var imageView: UIImageView! private let camera: Camera<RGBA<UInt8>> = try! Camera(sessionPreset: .vga640x480, focusMode: .continuousAutoFocus) override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) camera.start { [weak self] image in DispatchQueue.main.async { self?.imageView.image = image.uiImage } } } override func viewWillDisappear(_ animated: Bool) { camera.stop() super.viewWillDisappear(animated) } }
4:20 AM
image は EasyImagy の Image 型なので自由にピクセルにアクセスできます。 var image = Image<RGBA<UInt8>>(named: "ImageName")! print(image[x, y]) image[x, y] = RGBA(red: 255, green: 0, blue: 0, alpha: 127) image[x, y] = RGBA(0xFF00007F) // red: 255, green: 0, blue: 0, alpha: 127 // Iterates over all pixels for pixel in image { // ... } // Processes images (e.g. binarizations) let binarized: Image<Bool> = image.map { $0.gray >= 127 } // From/to `UIImage` image = Image<RGBA<UInt8>>(uiImage: imageView.image!) imageView.image = image.uiImage