Giter VIP home page Giter VIP logo

imagecropper's Introduction

ImageCropper

ImageCropper is a library developed on Swift. With ImageCropper you can easily detect and crop faces, texts, barcodes or rectangles in your image with iOS 11 Vision (iOS 10 Core Image) api. It will automatically create new images containing each object found within a given image.

ImageCropper是纯swift编写的库。使用它可以容易地将给定图片中的 人脸、文本、二维码/条形码 或者 方框 裁剪出来(对于iOS 11使用Vision库,iOS 10使用Core Image)。

Features

  • Crop image
  • Detect face, text, barcode or rectangle

Example

Normal Crop Padding Crop

Requirements

  • iOS 10.0+
  • Swift 4.2

Quick Start

# CocoaPods
pod 'ImageCropperKit'

# Carthage
github "cp110/ImageCropper"

Usage

Crop faces from your image (UIImage or CGImage) in the easy way.

裁剪原图是 UIImage 或 CGImage

// `type` in this method can be face, barcode, text or rectangle
// `padding` is the inside margin of the cropped image. default is .zero
// `type`:裁剪类型(人脸、条形码/二维码、文本、方框)
// `paddind`:裁剪出来的图片的内边距(可以使裁剪图片更完整些),默认 .zero
let image = UIImage(named: "image name")
// let image = UIImage(named: "image name")?.cgImage
image?.detector.crop(type: .face, padding: UIEdgeInsets(top: 40, left: 40, bottom: 40, right: 40)) { [weak self] result in
    switch result {
        case .success(let cropImageResults): // cropImageResults: [(image: T, frame: CGRect)]
            // When the `Vision` successfully find type of object you set and successfuly crops it.
            print("Found")
        case .notFound(let image, let frame):// image: original image (原图)
            // When the image doesn't contain any type of object you did set, `result` will be `.notFound`.
            print("Not Found")
        case .failure(let image, let frame, let error): // image: original image (原图)
            // When the any error occured, `result` will be `failure`.
            print(error.localizedDescription)
        }
}

Related Projects

Author

Arthur cp110:[email protected]

License

ImageCropper is available under the MIT license. See the LICENSE file for more info.

imagecropper's People

Contributors

94cp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

imagecropper's Issues

How does this method calculate the crop area?

  private func cropImage(object: VNDetectedObjectObservation, padding: UIEdgeInsets) -> (image: CGImage, frame: CGRect)? {
        let width = object.boundingBox.width * CGFloat(detectable.width)
        let height = object.boundingBox.height * CGFloat(detectable.height)
        let x = object.boundingBox.origin.x * CGFloat(detectable.width)
        let y = (1 - object.boundingBox.origin.y) * CGFloat(detectable.height) - height
        
        let croppingRect = CGRect(x: x - padding.left, y: y - padding.top, width: width + (padding.left + padding.right), height: height + (padding.top + padding.bottom))
        
        guard let image = self.detectable.cropping(to: croppingRect) else { return nil }
        
        return (image: image, frame: croppingRect)
    }
    

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.