Swiftpack.co - mynameisjaehoon/HideOnImage as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mynameisjaehoon.
mynameisjaehoon/HideOnImage 1.0.8
module that detects a face from a image and returns a mosaic image. Available via SPM. [Vision Framwork / Core Image CIDetector]
โญ๏ธ 10
๐Ÿ•“ 47 weeks ago
.package(url: "https://github.com/mynameisjaehoon/HideOnImage.git", from: "1.0.8")

HideOnImage

HideOnImage๋Š” ์–ผ๊ตด์ธ์‹ ์ž๋™๋ชจ์ž์ดํฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์ž๋™์œผ๋กœ ์ด๋ฏธ์ง€์˜ ์–ผ๊ตด์„ ์ธ์‹ํ•˜๊ณ  ๋ชจ์ž์ดํฌ ์ฒ˜๋ฆฌํ•ด์ค๋‹ˆ๋‹ค.

ํ•œ๊ตญ์–ด ENGLISH

์„ค์น˜

Swift Package Manager(SPM)์— ๋‹ค์Œ Package URL๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

https://github.com/mynameisjaehoon/HideOnImage.git

์‚ฌ์šฉ๋ฒ•

  • Mosaic ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
  • Mosaic ์ธ์Šคํ„ด์Šค์˜ delegate๋ฅผ ํ˜„์žฌ ์ฒ˜๋ฆฌํ•  ๋ทฐ ์ปจํŠธ๋กค๋Ÿฌ๋กœ ์ง€์ •ํ•ฉ๋‹ˆ๋‹ค.
  • UIImage์ด๋ฏธ์ง€ ๋ฐ์ดํ„ฐ๋ฅผ convert(with:)๋ฉ”์„œ๋“œ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ๋„˜๊ฒจ ๋ชจ์ž์ดํฌ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜์„ ์‹œ์ž‘ํ•ฉ๋‹ˆ๋‹ค.
  • MosaicDelegate ํ”„๋กœํ† ์ฝœ์˜ Delegate ๋ฉ”์„œ๋“œ๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.
  • mosaicImageProcessDidFinish(result:) delegate ๋ฉ”์„œ๋“œ์˜ ํŒŒ๋ผ๋ฏธํ„ฐ๋กœ ์ฃผ์–ด์ง€๋Š” ๊ฒฐ๊ณผ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
let mosaic = Mosaic()
mosaic.delegate = self

let image = UIImage(named: "my-image")
mosaic.convert(uiImage: image)

...

extension class_name: MosaicDelegate {

    func mosaicImageProcessDidFinish(with result: UIImage) {
        self.imageView.image = result
    }
}

๋ชจ์ž์ดํฌ ์„ค์ •์ •๋ณด ์ˆ˜์ •ํ•˜๊ธฐ

Mosaic๊ฐ์ฒด ๋‚ด๋ถ€์˜ configurationํ”„๋กœํผํ‹ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ชจ์ž์ดํฌ์˜ ์˜ต์…˜์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์˜ต์…˜์œผ๋กœ๋Š” ๋‹ค์Œ์„ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • ์–ผ๊ตดํƒ์ง€ ์œ ํ˜•
    • Vision Framework
    • CIDetector
  • ๋ชจ์ž์ดํฌ radius

์–ผ๊ตดํƒ์ง€ ์œ ํ˜•์„ ํƒ

์–ผ๊ตด์„ ํƒ์ง€ํ•˜๋Š”๋ฐ๋Š” Vision Framework ์™€ CIDetector ๋‘๊ฐ€์ง€ ์œ ํ˜• ์ค‘ ํ•˜๋‚˜๋ฅผ ์„ ํƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • Vision Framework๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๊ธฐ๋ณธ๊ฐ’์€ Vision Framework๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค. Vision Framework๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์‹ญ์‹œ์š”.

    let image = UIImage(named: "my-image")
    mosaic.convert(uiImage: image)
    

    ๋˜๋Š”

    let image = UIImage(named: "my-image")
    let configuration = MosaicConfiguration()
    configuration.aiType = .vision
    mosaic.configuration = configuration
    mosaic.convert(uiImage: image)
    
  • CIDetector CIDetector๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์‹ญ์‹œ์š”

    let image = UIImage(named: "my-image")
    let configuration = MosaicConfiguration()
    configuration.aiType = .ciDetector
    mosaic.configuration = configuration
    mosaic.convert(uiImage: image)
    

๋ชจ์ž์ดํฌ radius์„ค์ •

๋ชจ์ž์ดํฌ ์ •๋„์ธ radius๋ฅผ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ธฐ๋ณธ radius๊ฐ’์€ 15์ž…๋‹ˆ๋‹ค.
์•„๋ž˜์˜ ์ฝ”๋“œ๋Š” CIDetector๋กœ ํƒ์ง€ํ•˜๋ฉด์„œ radius๋ฅผ 30์œผ๋กœ ์„ค์ •ํ•˜๋Š” ๊ฒฝ์šฐ์ž…๋‹ˆ๋‹ค.

let image = UIImage(named: "my-image")
let configuration = MosaicConfiguration()
configuration.aiType = .ciDetector
configuration.radius = 30
mosaic.convert(uiImage: image)

์ด๋ฏธ์ง€ ํƒ€์ž… ์„ค์ •

๋‹ค์Œ ํƒ€์ž…์˜ ์ด๋ฏธ์ง€๋ฅผ ์ „๋‹ฌํ•ด ๋ชจ์ž์ดํฌ๋ฅผ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

  • UIImage
  • CGImage
  • CIImage

์„ธ๊ฐ€์ง€ ํƒ€์ž…์˜ ์ด๋ฏธ์ง€๋ฅผ ๋ฐ›๋Š” convert๋ฉ”์„œ๋“œ๊ฐ€ ์ •์˜๋˜์–ด์žˆ์Šต๋‹ˆ๋‹ค.

func convert(uiImage: UIImage?)
func convert(cgImage: CGImage?)
func convert(ciImage: CIImage?)

์„ ํƒ

- CIDetector์˜ ์ •ํ™•๋„๋Š” `CIDetectorAccuracyLow`๋กœ, ๋‚ฎ๊ฒŒ ์„ค์ •๋˜์–ด ์žˆ์Šต๋‹ˆ๋‹ค. ๋ฆฌ์†Œ์Šค ์‚ฌ์šฉ์ด ์ ๊ณ  ๋น ๋ฅด๊ฒŒ ์–ผ๊ตด์„ ๋ชจ์ž์ดํฌํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์ด ์˜ต์…˜์„ ์„ ํƒํ•˜์„ธ์š”.
- Vision Framework๋Š” ์ •ํ™•๋„๊ฐ€ ๋†’์ง€๋งŒ `CIDetector`์— ๋น„ํ•ด ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ๋งŽ์ด ๋“ฆ๋‹ˆ๋‹ค. ์ •ํ™•๋„๋ฅผ ์ค‘์š”ํ•˜๊ฒŒ ์—ฌ๊ธด๋‹ค๋ฉด ์ด ์˜ต์…˜์„ ์„ ํƒํ•˜์„ธ์š” 

โš ๏ธ ์ฃผ์˜

์‹œ๋ฎฌ๋ ˆ์ดํ„ฐ์—์„œ ์‹คํ–‰ํ•˜๋Š” ๊ฒฝ์šฐ ๋‹ค์Œ ์ฝ”๋“œ๋ฅผ ์ถ”๊ฐ€ํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค.

#if targetEnvironment(simulator)
    mosaic.faceDetectionRequest.usesCPUOnly = true
#endif

HideOnImage is a face detection automatic mosaic library. It automatically recognizes and mosaic the face of the image.

Installation

Available in Swift Package Manager (SPM) as the following package URL

https://github.com/mynameisjaehoon/HideOnImage.git

How to use it

  • Create a Mosaic instance.
  • Specifies the delegate of the Mosaic instance as the view controller to be currently processed.
  • Pass the UIImage image data to the parameters of the convert(with:) method to begin conversion into a mosaic image.
  • Implement the MosaicDelegate protocol's Delegate method.
  • We use the resulting image given as a parameter of the mosaicImageProcessDidFinish delegate method.
let mosaic = Mosaic()
mosaic.delegate = self // Important

let image = UIImage(named: "my-image")
mosaic.convert(uiImage: image)

...

extension class_name: MosaicDelegate {

    func mosaicImageProcessDidFinish(with result: UIImage) {
        self.imageView.image = result
    }
}

How to Modify Mosaic configurations

You can use the configuration properties inside the Mosaic object to select options for the mosaic. Options include:

  • Face detection type
    • Vision Framework
    • CIDetector
  • Mosaic radius

Select face detection type

You can choose between Vision Framework and CIDetector to detect faces.

  • Vision Framework The default is to use the Vision Framework. To use the Vision Framework:

    let image = UIImage(named: "my-image")
    mosaic.convert(uiImage: image)
    

    Or

    let image = UIImage(named: "my-image")
    let configuration = MosaicConfiguration()
    configuration.aiType = .vision
    mosaic.configuration = configuration
    mosaic.convert(uiImage: image)
    
  • CIDetector To use CIDetector, use as follows

    let image = UIImage(named: "my-image")
    let configuration = MosaicConfiguration()
    configuration.aiType = .ciDetector
    mosaic.configuration = configuration
    mosaic.convert(uiImage: image)
    

Mosaic radius setting

You can set the radius, which is the degree of mosaic. The default radius value is 15.
The code below is for detecting CIDetector and setting radius to 30.

let image = UIImage(named: "my-image")
let configuration = MosaicConfiguration()
configuration.aiType = .ciDetector
configuration.radius = 30
mosaic.convert(uiImage: image)

Set Image Type

The following types of images can be passed to process mosaic:

  • UIImage
  • CGImage
  • CIImage

A convert method that receives three types of images is defined.

func convert(uiImage: UIImage?)
func convert(cgImage: CGImage?)
func convert(ciImage: CIImage?)

Select

  • The accuracy of the CIDetector is set to CIDetectorAccuracyLow. Select this option if you are using less resources and want to mosaic image's' faces quickly.
  • The Vision Framework is more accurate, but it takes more overhead and resources than the CIDetector. Choose this option if you want your face detection to be accurate

โš ๏ธ CAUTION

When running on a simulator, you must add the following code:

#if targetEnvironment(simulator)
mosaic.faceDetectionRequest.usesCPUOnly = true
#endif

GitHub

link
Stars: 10
Last commit: 6 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

HideOnImage-1.0.8
47 weeks ago
  • ๋ชจ์ž์ดํฌ ์ฒ˜๋ฆฌ์˜ ์„ค์ •์ •๋ณด๋ฅผ ๋‹ด์€ ๊ตฌ์กฐ์ฒด MosaicConfiguration์„ ์ƒ์„ฑํ•˜์˜€์Šต๋‹ˆ๋‹ค.
  • Mosaic๊ฐ์ฒด๊ฐ€ configurationํ”„๋กœํผํ‹ฐ๋กœ MosaicConfiguration์ธ์Šคํ„ด์Šค๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
  • ์‚ฌ์šฉ์ž๊ฐ€ MosaicConfiguration์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์–ผ๊ตดํƒ์ง€์— ์‚ฌ์šฉํ•  ๋„๊ตฌ(Vision Framework, CIDetector)์™€ ๋ชจ์ž์ดํฌ ์ •๋„(radius)๋ฅผ ์„ ํƒํ•˜๊ณ , ๋ชจ๋“ˆ์˜ ์„ค์ •์ •๋ณด๋กœ ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    ์•„๋ž˜๋Š” ์–ผ๊ตด ํƒ์ง€์— CIDetector๋ฅผ ์‚ฌ์šฉํ•˜๊ณ , ๋ชจ์ž์ดํฌ์˜ radius๋ฅผ 30์œผ๋กœ ์„ค์ •ํ•œ ์„ค์ •์ •๋ณด๋ฅผ ์ ์šฉํ•œ ๊ฒƒ์ž…๋‹ˆ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ์„ค์ •์ •๋ณด๋ฅผ ๋„˜๊ฒจ์ฃผ์ง€ ์•Š์œผ๋ฉด ๊ธฐ๋ณธ๊ฐ’์ธ Vision Framework๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  radius๊ฐ’์œผ๋กœ 15๋ฅผ ์‚ฌ์šฉํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
    let image = UIImage(named: "my-image")
    let configuration = MosaicConfiguration()
    configuration.aiType = .ciDetector
    configuration.radius = 30
    mosaic.convert(uiImage: image)
    
  • CGImage, CIImage๋ฅผ ๋„˜๊ฒจ๋ฐ›์•„ ๋ชจ์ž์ดํฌ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ๋ฉ”์„œ๋“œ๋ฅผ ์ถ”๊ฐ€ํ•˜์˜€์Šต๋‹ˆ๋‹ค. ๋‹ค์Œ ๋ฉ”์„œ๋“œ๋“ค์„ ์‚ฌ์šฉํ•ด์„œ ๋ชจ์ž์ดํฌ ์ฒ˜๋ฆฌ๋ฅผ ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
func convert(uiImage: UIImage?)
func convert(cgImage: CGImage?)
func convert(ciImage: CIImage?)

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics