iOS Vision Framework图像整改

时间:2017-08-31 23:28:03

标签: ios ios11 apple-vision

我想使用iOS Vision Framework的VNHomographicImageRegistrationRequest来修正一对图像。有可能吗?

到目前为止,我已经获得了一个3x3的扭曲矩阵,似乎无法纠正图像。

如何使用warp矩阵(我在网上找不到任何例子)?

此外,图像校正与图像校正有何不同(我理解图像校正,但不是图像校正)?

Xcode Playground:

import UIKit
import Foundation
import Vision

var li = UIImage(named: "left.png")
var ri = UIImage(named: "right.png")

let handler = VNSequenceRequestHandler()
let request = VNHomographicImageRegistrationRequest(targetedCGImage: li!.cgImage!, options: [:]) { (req, err) in
    let observation = req.results?.first as! VNImageHomographicAlignmentObservation
    print(observation.warpTransform)
}

try! handler.perform([request], on: ri!.cgImage!)

OpenCV图片变形:

import numpy as np
import cv2

# read the pair of images
li = cv2.imread('left.png', 0)
ri = cv2.imread('right.png', 0)

# get the 3x3 warp matrix provided by Vision Framework
ios_vision_warp_mat = np.transpose(np.array([
    [0.746783, -0.0139349, -0.000149109],
    [-0.0426033, 0.861793, -2.39433e-05],
    [133.91, 22.0962, 0.999471]
]))

# warp the image
warped = cv2.warpPerspective(ri, ios_vision_warp_mat, (ri.shape[1], ri.shape[0]))
combined = cv2.addWeighted(warped, 0.5, li, 0.5, 0.0)

cv2.imshow('Combined pair', combined)
cv2.imshow('Unrectified pair', np.concatenate([li, warped], axis=1))

cv2.waitKey(0)

0 个答案:

没有答案