/SemanticImage

A collection of easy-to-use image/video filter.

Primary LanguageSwiftMIT LicenseMIT

SemanticImage

A collection of easy-to-use image / video filters.

How to use

Setting Up

1, Add SemanticImage to your project as Swift Package with Swift Package Manager. Or just drag SemanticImage.swift to your project.

2, Import and initialize SemanticImage

import SemanticImage
let semanticImage = SemanticImage()

Requires iOS 14 or above

Filter Collection

Image

Get Person Mask

let maskImage:UIImage? = semanticImage.personMaskImage(uiImage: yourUIImage)

Swap the background of a person

let swappedImage:UIImage? = semanticImage.swapBackgroundOfPerson(personUIImage: yourUIImage, backgroundUIImage: yourBackgroundUIImage)

Blur the backgrond of a person

let blurredPersonImage:UIImage? = semanticImage.personBlur(uiImage:UIImage, intensity:Float)
// Blur intensity: 0~100 

Get a prominent object mask

let prominentMaskImage:UIImage? = semanticImage.saliencyMask(uiImage:image)

Swap the background of the prominent object

let backgroundSwapImage:UIImage? = semanticImage.saliencyBlend(objectUIImage: image, backgroundUIImage: bgImage)

Crop a face rectangle

let faceImage:UIImage? = semanticImage.faceRectangle(uiImage: image)

Crop a body rectangle

let bodyImage:UIImage? = semanticImage.humanRectangle(uiImage: image)

Crop face rectangles

let faceImages:[UIImage] = semanticImage.faceRectangles(uiImage: image)

Crop body rectangles

let bodyImages:[UIImage] = semanticImage.humanRectangles(uiImage: image)

Crop an animal(Cat/Dog) rectangle

let animalImage:UIImage? = semanticImage.animalRectangle(uiImage: image)

Crop multiple animal(Cat/Dog) rectangles

let animalImages:[UIImage] = semanticImage.animalRectangles(uiImage: image)

Crop and warp document

let documentImage:UIImage? = semanticImage.getDocumentImage(image: image)

Video

Apply CIFilter to Video

guard let ciFilter = CIFilter(name: "CIEdgeWork", parameters: [kCIInputRadiusKey:3.0]) else { return }
semanticImage.ciFilterVideo(videoURL: url, ciFilter: ciFilter, { err, processedURL in
    // Handle processedURL in here.
})
// This process takes about the same time as the video playback time.

Add virtual background of the person video

semanticImage.swapBackgroundOfPersonVideo(videoURL: url, backgroundUIImage: uiImage, { err, processedURL in
    // Handle processedURL in here.
})
    // This process takes about the same time as the video playback time.

Add virtual background of the salient object video

semanticImage.swapBGOfSalientObjectVideo(videoURL: url, backgroundUIImage: uiImage, { err, processedURL in
    // Handle processedURL in here.
})
    // This process takes about the same time as the video playback time.

Process video

semanticImage.applyProcessingOnVideo(videoURL: url, { ciImage in
    // Write the processing of ciImage (i.e. video frame) here.
    return newImage
}, {  err, editedURL in
   // The processed video URL is returned
})

Author

Daisuke Majima

Freelance iOS programmer from Japan.

PROFILES:

WORKS:

BLOGS: Medium

CONTACTS: rockyshikoku@gmail.com