iOS Development

iOS Swift The best way to warp a part of picture from detected supply level to vacation spot level?

Spread the love


I’ve detected particular a part of picture (blue ball) and I must warp this half from upper-point to lower-point. I’ve discovered WarpGeometryFilter however the issue is that it warp full picture to level of detected half. The best way to set supply and vacation spot correctly?I must go from this:

enter image description here

To this:
enter image description here

//Detected factors half:
ball.normalizedPoints.forEach { level in
let ballPosition = vector_float2(x: Float(level.x), y: Float(level.y))
ballVectorArray.append(ballPosition) //I've obtained 6 values 

//Warp half
let filter: WarpGeometryFilter = .init(machine: MTLCreateSystemDefaultDevice()!)

        let supply: [vector_float2] = ? (I've thought it will be my ballVectorArray but it surely works mistaken)
        
        let vacation spot: [vector_float2] = ?
        
        let warpGeometry = SKWarpGeometryGrid(columns: ?, rows: ?, sourcePositions: supply, destinationPositions: vacation spot)

        filter.setValue(sourceImage, forKey: kCIInputImageKey)
        filter.setValue(warpGeometry, forKey: kCIInputWarpGeometryKey)

        let end result = filter.outputImage!

If I am going to set supply and vacation spot like this

let supply: [vector_float2] = ballVectorArray //[SIMD2<Float>(0.23153101, 0.7204376), SIMD2<Float>(0.2829985, 0.74947053), SIMD2<Float>(0.36217925, 0.74208033), SIMD2<Float>(0.4081041, 0.7040736), SIMD2<Float>(0.35399726, 0.6966834), SIMD2<Float>(0.28009522, 0.69483584)]
let vacation spot: [vector_float2] = ballVectorNewArray// [SIMD2<Float>(0.13153102, 0.62043756), SIMD2<Float>(0.18299851, 0.6494705), SIMD2<Float>(0.26217926, 0.6420803), SIMD2<Float>(0.3081041, 0.6040736), SIMD2<Float>(0.25399727, 0.5966834), SIMD2<Float>(0.18009523, 0.5948358)]

I get this end result:
enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *