rename OpenCVWrapper.transform to findHomography

This commit is contained in:
Paul Zabelin
2018-03-04 00:47:05 -08:00
parent c8df0dfe0e
commit 51d9c9a06a
4 changed files with 11 additions and 19 deletions

View File

@@ -29,7 +29,7 @@ class OpenCVPerformanceTest: XCTestCase {
measure {
self.repeatTimes.times {
_ = OpenCVWrapper.transform(start, to: destination)
_ = OpenCVWrapper.findHomography(from: start, to: destination)
}
}
}

View File

@@ -19,6 +19,6 @@ typedef struct Quadrilateral {
@interface OpenCVWrapper: NSObject
+ (CATransform3D)transformQuadrilateral:(Quadrilateral)origin
toQuadrilateral:(Quadrilateral)destination;
+ (CATransform3D)findHomographyFromQuadrilateral:(Quadrilateral)origin
toQuadrilateral:(Quadrilateral)destination;
@end

View File

@@ -4,8 +4,7 @@
#import "OpenCVWrapper.h"
@implementation OpenCVWrapper
+ (CATransform3D)transformQuadrilateral:(Quadrilateral)origin toQuadrilateral:(Quadrilateral)destination {
+ (CATransform3D)findHomographyFromQuadrilateral:(Quadrilateral)origin toQuadrilateral:(Quadrilateral)destination {
CvPoint2D32f *cvsrc = [self openCVMatrixWithQuadrilateral:origin];
CvMat *src_mat = cvCreateMat( 4, 2, CV_32FC1 );
cvSetData(src_mat, cvsrc, sizeof(CvPoint2D32f));

View File

@@ -5,23 +5,16 @@ class OpenCV_Spec: QuickSpec {
override func spec() {
describe("OpenCV") {
context("OpenCVWrapper") {
context("transform") {
context("findHomography") {
it("should be identity for same start and destination") {
let start = Quadrilateral(upperLeft: CGPoint.zero,
upperRight: CGPoint(x: 10, y: 0),
lowerRight: CGPoint(x: 0, y: 10),
lowerLeft: CGPoint(x: 10, y: 10))
let desination = start
var transform = OpenCVWrapper.transform(start, to: desination)
expect(transform.m41.exponent) <= -40
expect(transform.m42.exponent) <= -40
transform.m41 = transform.m41.rounded(.towardZero)
transform.m42 = transform.m42.rounded(.towardZero)
expect(CATransform3DIsIdentity(transform)) == true
var transform = OpenCVWrapper.findHomography(from: start, to: start)
expect(transform) CATransform3DIdentity
}
context("compare with algebraic solution") {
let points = [
CGPoint(x: 108.315837, y: 80.1687782),
@@ -32,7 +25,7 @@ class OpenCV_Spec: QuickSpec {
let frame = CGRect(origin: CGPoint.zero,
size: CGSize(width: 20, height: 10))
func openCVTransform() -> CATransform3D {
func openCVHomographyTransform() -> CATransform3D {
let start = Quadrilateral(upperLeft: CGPoint(x: frame.minX, y: frame.minY),
upperRight: CGPoint(x: frame.maxX, y: frame.minY),
lowerRight: CGPoint(x: frame.maxX, y: frame.maxY),
@@ -41,7 +34,7 @@ class OpenCV_Spec: QuickSpec {
upperRight: points[1],
lowerRight: points[3],
lowerLeft: points[2])
return OpenCVWrapper.transform(start, to: destination)
return OpenCVWrapper.findHomography(from: start, to: destination)
}
func algebraTransform() -> CATransform3D {
@@ -60,8 +53,8 @@ class OpenCV_Spec: QuickSpec {
return start.rectToQuad(rect: start.box(), quad: destination)
}
it("should be same") {
let openCV = openCVTransform()
it("should produce same result within precision") {
let openCV = openCVHomographyTransform()
let algebra = algebraTransform()
expect(openCV) algebra
}