Which native iOS framework is best used to eradicate this cpu hog written in OpenCV?
/// Reduce the channel elements of given Mat to a single channel
static func reduce(input: Mat) throws -> Mat {
let output = Mat(rows: input.rows(), cols: input.cols(), type: CvType.CV_8UC1)
for x in 0 ..< input.rows() {
for y in 0 ..< input.cols() {
let value = input.get(row: x, col: y)
let dataValue = value.reduce(0, +)
try output.put(row: x, col: y, data: [dataValue])
}
}
return output
}
takes about 20+ seconds to do those gets and puts on real world data I put this code through.
2
Answers
For folks such as myself who have a poor comprehension of ARM Intrinsics a simpler solution is to bridge into Objective C code as Soonts did and thusly ditch crude Swift api to opencv bypassing costly memory copying with gets and puts.
Assuming your input matrix is
CV_64FC2
, callcomputeSumX2
C function for each row.Untested.