mirror of
https://github.com/zhigang1992/PerspectiveTransform.git
synced 2026-04-29 20:55:21 +08:00
add performance test for open cv
to compare perspective transform with find homography
This commit is contained in:
@@ -10,28 +10,35 @@ import XCTest
|
||||
|
||||
class OpenCVPerformanceTest: XCTestCase {
|
||||
static let reasonableTestDurationMs = 100
|
||||
var repeatTimes = OpenCVPerformanceTest.reasonableTestDurationMs * 1000
|
||||
let repeatTimes = {OpenCVPerformanceTest.reasonableTestDurationMs * 1000}()
|
||||
|
||||
func testPerformance() {
|
||||
let destination = Quadrilateral(upperLeft: CGPoint(x: 108.315837, y: 80.1687782),
|
||||
upperRight: CGPoint(x: 377.282671, y: 41.4352201),
|
||||
lowerRight: CGPoint(x: 193.321418, y: 330.023027),
|
||||
lowerLeft: CGPoint(x: 459.781253, y: 251.836131))
|
||||
var start = Quadrilateral()
|
||||
let destination = Quadrilateral(upperLeft: CGPoint(x: 108.315837, y: 80.1687782),
|
||||
upperRight: CGPoint(x: 377.282671, y: 41.4352201),
|
||||
lowerRight: CGPoint(x: 193.321418, y: 330.023027),
|
||||
lowerLeft: CGPoint(x: 459.781253, y: 251.836131))
|
||||
let start: Quadrilateral = {
|
||||
var one = Quadrilateral()
|
||||
let overlayFrame = CGRect(x: 0, y: 0, width: 1, height: 1)
|
||||
start.upperLeft = CGPoint(x: overlayFrame.minX, y: overlayFrame.minY)
|
||||
start.upperRight = CGPoint(x: overlayFrame.maxX, y: overlayFrame.minY)
|
||||
start.lowerLeft = CGPoint(x: overlayFrame.minX, y: overlayFrame.maxY)
|
||||
start.lowerRight = CGPoint(x: overlayFrame.maxX, y: overlayFrame.maxY)
|
||||
|
||||
let openCVtimesSlower = 20
|
||||
self.repeatTimes /= openCVtimesSlower
|
||||
one.upperLeft = CGPoint(x: overlayFrame.minX, y: overlayFrame.minY)
|
||||
one.upperRight = CGPoint(x: overlayFrame.maxX, y: overlayFrame.minY)
|
||||
one.lowerLeft = CGPoint(x: overlayFrame.minX, y: overlayFrame.maxY)
|
||||
one.lowerRight = CGPoint(x: overlayFrame.maxX, y: overlayFrame.maxY)
|
||||
return one
|
||||
}()
|
||||
|
||||
func testPerspectiveTransformPerformance() {
|
||||
measure {
|
||||
self.repeatTimes.times {
|
||||
(self.repeatTimes/15).times {
|
||||
_ = OpenCVWrapper.perspectiveTransform(start, to: destination)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testFindHomographyPerformance() {
|
||||
measure {
|
||||
(self.repeatTimes/20).times {
|
||||
_ = OpenCVWrapper.findHomography(from: start, to: destination)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user