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