HideOnImage
๋ ์ผ๊ตด์ธ์ ์๋๋ชจ์์ดํฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์
๋๋ค. ์๋์ผ๋ก ์ด๋ฏธ์ง์ ์ผ๊ตด์ ์ธ์ํ๊ณ ๋ชจ์์ดํฌ ์ฒ๋ฆฌํด์ค๋๋ค.
Swift Package Manager(SPM)์ ๋ค์ Package URL๋ก ์ฌ์ฉํ ์ ์์ต๋๋ค.
https://github.com/mynameisjaehoon/HideOnImage.git
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
๋๊ฐ์ง ์ ํ ์ค ํ๋๋ฅผ ์ ํํ ์ ์์ต๋๋ค.
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๊ฐ์ 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.
Available in Swift Package Manager (SPM) as the following package URL
https://github.com/mynameisjaehoon/HideOnImage.git
delegate
of the Mosaic instance as the view controller to be currently processed.UIImage
image data to the parameters of the convert(with:)
method to begin conversion into a mosaic image.MosaicDelegate
protocol's Delegate method.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
}
}
Mosaic
configurationsYou can use the configuration properties inside the Mosaic object to select options for the mosaic. Options include:
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)
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)
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?)
CIDetector
is set to CIDetectorAccuracyLow
. Select this option if you are using less resources and want to mosaic image's' faces quickly.CIDetector
. Choose this option if you want your face detection to be accurateWhen running on a simulator, you must add the following code:
#if targetEnvironment(simulator)
mosaic.faceDetectionRequest.usesCPUOnly = true
#endif
link |
Stars: 10 |
Last commit: 6 weeks ago |
MosaicConfiguration
์ ์์ฑํ์์ต๋๋ค.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