|
|
|
@ -308,15 +308,15 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssert([340] == sm.get(row: 1, col: 1)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testGetIntIntByteArray() throws { |
|
|
|
|
let m = try getTestMat(size: 5, type: CvType.CV_8UC3) |
|
|
|
|
func testGetIntIntInt8Array() throws { |
|
|
|
|
let m = try getTestMat(size: 5, type: CvType.CV_8SC3) |
|
|
|
|
var goodData = [Int8](repeating: 0, count: 9) |
|
|
|
|
|
|
|
|
|
// whole Mat |
|
|
|
|
var bytesNum = try m.get(row: 1, col: 1, data: &goodData) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(9, bytesNum) |
|
|
|
|
XCTAssert([110, 111, 112, 120, 121, 122, -126, -125, -124] == goodData) |
|
|
|
|
XCTAssert([110, 111, 112, 120, 121, 122, 127, 127, 127] == goodData) |
|
|
|
|
|
|
|
|
|
var badData = [Int8](repeating: 0, count: 7) |
|
|
|
|
XCTAssertThrowsError(bytesNum = try m.get(row: 0, col: 0, data: &badData)) |
|
|
|
@ -326,11 +326,36 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
var buff00 = [Int8](repeating: 0, count: 3) |
|
|
|
|
bytesNum = try sm.get(row: 0, col: 0, data: &buff00) |
|
|
|
|
XCTAssertEqual(3, bytesNum) |
|
|
|
|
XCTAssert(buff00 == [-26, -25, -24]) |
|
|
|
|
XCTAssert(buff00 == [127, 127, 127]) |
|
|
|
|
var buff11 = [Int8](repeating: 0, count: 3) |
|
|
|
|
bytesNum = try sm.get(row: 1, col: 1, data: &buff11) |
|
|
|
|
XCTAssertEqual(3, bytesNum) |
|
|
|
|
XCTAssert(buff11 == [-1, -1, -1]) |
|
|
|
|
XCTAssert(buff11 == [127, 127, 127]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testGetIntIntUInt8Array() throws { |
|
|
|
|
let m = try getTestMat(size: 5, type: CvType.CV_8UC3) |
|
|
|
|
var goodData = [UInt8](repeating: 0, count: 9) |
|
|
|
|
|
|
|
|
|
// whole Mat |
|
|
|
|
var bytesNum = try m.get(row: 1, col: 1, data: &goodData) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(9, bytesNum) |
|
|
|
|
XCTAssert([110, 111, 112, 120, 121, 122, 130, 131, 132] == goodData) |
|
|
|
|
|
|
|
|
|
var badData = [UInt8](repeating: 0, count: 7) |
|
|
|
|
XCTAssertThrowsError(bytesNum = try m.get(row: 0, col: 0, data: &badData)) |
|
|
|
|
|
|
|
|
|
// sub-Mat |
|
|
|
|
let sm = m.submat(rowStart: 2, rowEnd: 4, colStart: 3, colEnd: 5) |
|
|
|
|
var buff00 = [UInt8](repeating: 0, count: 3) |
|
|
|
|
bytesNum = try sm.get(row: 0, col: 0, data: &buff00) |
|
|
|
|
XCTAssertEqual(3, bytesNum) |
|
|
|
|
XCTAssert(buff00 == [230, 231, 232]) |
|
|
|
|
var buff11 = [UInt8](repeating: 0, count: 3) |
|
|
|
|
bytesNum = try sm.get(row: 1, col: 1, data: &buff11) |
|
|
|
|
XCTAssertEqual(3, bytesNum) |
|
|
|
|
XCTAssert(buff11 == [255, 255, 255]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testGetIntIntDoubleArray() throws { |
|
|
|
@ -399,7 +424,7 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssert(buff11 == [340, 341, 0, 0]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testGetIntIntShortArray() throws { |
|
|
|
|
func testGetIntIntInt16Array() throws { |
|
|
|
|
let m = try getTestMat(size: 5, type: CvType.CV_16SC2) |
|
|
|
|
var buff = [Int16](repeating: 0, count: 6) |
|
|
|
|
|
|
|
|
@ -421,6 +446,28 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssert(buff11 == [340, 341, 0, 0]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testGetIntIntUInt16Array() throws { |
|
|
|
|
let m = try getTestMat(size: 5, type: CvType.CV_16UC2) |
|
|
|
|
var buff = [UInt16](repeating: 0, count: 6) |
|
|
|
|
|
|
|
|
|
// whole Mat |
|
|
|
|
var bytesNum = try m.get(row: 1, col: 1, data: &buff) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(12, bytesNum); |
|
|
|
|
XCTAssert(buff == [110, 111, 120, 121, 130, 131]) |
|
|
|
|
|
|
|
|
|
// sub-Mat |
|
|
|
|
let sm = m.submat(rowStart: 2, rowEnd: 4, colStart: 3, colEnd: 5) |
|
|
|
|
var buff00 = [UInt16](repeating: 0, count: 4) |
|
|
|
|
bytesNum = try sm.get(row: 0, col: 0, data: &buff00) |
|
|
|
|
XCTAssertEqual(8, bytesNum) |
|
|
|
|
XCTAssert(buff00 == [230, 231, 240, 241]) |
|
|
|
|
var buff11 = [UInt16](repeating: 0, count: 4) |
|
|
|
|
bytesNum = try sm.get(row: 1, col: 1, data: &buff11) |
|
|
|
|
XCTAssertEqual(4, bytesNum); |
|
|
|
|
XCTAssert(buff11 == [340, 341, 0, 0]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testHeight() { |
|
|
|
|
XCTAssertEqual(gray0.rows(), gray0.height()) |
|
|
|
|
XCTAssertEqual(rgbLena.rows(), rgbLena.height()) |
|
|
|
@ -653,7 +700,7 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
try assertMatEqual(truth!, m1, OpenCVTestCase.EPS) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntIntByteArray() throws { |
|
|
|
|
func testPutIntIntInt8Array() throws { |
|
|
|
|
let m = Mat(rows: 5, cols: 5, type: CvType.CV_8SC3, scalar: Scalar(1, 2, 3)) |
|
|
|
|
let sm = m.submat(rowStart: 2, rowEnd: 4, colStart: 3, colEnd: 5) |
|
|
|
|
var buff = [Int8](repeating: 0, count: 6) |
|
|
|
@ -683,7 +730,37 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssert(buff == buff0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntArrayByteArray() throws { |
|
|
|
|
func testPutIntIntUInt8Array() throws { |
|
|
|
|
let m = Mat(rows: 5, cols: 5, type: CvType.CV_8UC3, scalar: Scalar(1, 2, 3)) |
|
|
|
|
let sm = m.submat(rowStart: 2, rowEnd: 4, colStart: 3, colEnd: 5) |
|
|
|
|
var buff = [UInt8](repeating: 0, count: 6) |
|
|
|
|
let buff0:[UInt8] = [10, 20, 30, 40, 50, 60] |
|
|
|
|
let buff1:[UInt8] = [255, 254, 253, 252, 251, 250] |
|
|
|
|
|
|
|
|
|
var bytesNum = try m.put(row:1, col:2, data:buff0) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
bytesNum = try m.get(row: 1, col: 2, data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
XCTAssert(buff == buff0) |
|
|
|
|
|
|
|
|
|
bytesNum = try sm.put(row:0, col:0, data:buff1) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
bytesNum = try sm.get(row: 0, col: 0, data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
XCTAssert(buff == buff1) |
|
|
|
|
bytesNum = try m.get(row: 2, col: 3, data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum); |
|
|
|
|
XCTAssert(buff == buff1) |
|
|
|
|
|
|
|
|
|
let m1 = m.row(1) |
|
|
|
|
bytesNum = try m1.get(row: 0, col: 2, data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
XCTAssert(buff == buff0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntArrayInt8Array() throws { |
|
|
|
|
let m = Mat(sizes: [5, 5, 5], type: CvType.CV_8SC3, scalar: Scalar(1, 2, 3)) |
|
|
|
|
let sm = m.submat(ranges: [Range(start: 0, end: 2), Range(start: 1, end: 3), Range(start: 2, end: 4)]) |
|
|
|
|
var buff = [Int8](repeating: 0, count: 6) |
|
|
|
@ -714,10 +791,41 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssert(buff == buff0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntArrayUInt8Array() throws { |
|
|
|
|
let m = Mat(sizes: [5, 5, 5], type: CvType.CV_8UC3, scalar: Scalar(1, 2, 3)) |
|
|
|
|
let sm = m.submat(ranges: [Range(start: 0, end: 2), Range(start: 1, end: 3), Range(start: 2, end: 4)]) |
|
|
|
|
var buff = [UInt8](repeating: 0, count: 6) |
|
|
|
|
let buff0:[UInt8] = [10, 20, 30, 40, 50, 60] |
|
|
|
|
let buff1:[UInt8] = [255, 254, 253, 252, 251, 250] |
|
|
|
|
|
|
|
|
|
var bytesNum = try m.put(indices:[1, 2, 0], data:buff0) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
bytesNum = try m.get(indices: [1, 2, 0], data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
XCTAssert(buff == buff0) |
|
|
|
|
|
|
|
|
|
bytesNum = try sm.put(indices: [0, 0, 0], data: buff1) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
bytesNum = try sm.get(indices: [0, 0, 0], data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
XCTAssert(buff == buff1) |
|
|
|
|
|
|
|
|
|
bytesNum = try m.get(indices: [0, 1, 2], data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
XCTAssert(buff == buff1) |
|
|
|
|
|
|
|
|
|
let m1 = m.submat(ranges: [Range(start: 1,end: 2), Range.all(), Range.all()]) |
|
|
|
|
bytesNum = try m1.get(indices: [0, 2, 0], data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
XCTAssert(buff == buff0) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntIntDoubleArray() throws { |
|
|
|
|
let m = Mat(rows: 5, cols: 5, type: CvType.CV_8SC3, scalar: Scalar(1, 2, 3)) |
|
|
|
|
let m = Mat(rows: 5, cols: 5, type: CvType.CV_8UC3, scalar: Scalar(1, 2, 3)) |
|
|
|
|
let sm = m.submat(rowStart: 2, rowEnd: 4, colStart: 3, colEnd: 5) |
|
|
|
|
var buff = [Int8](repeating: 0, count: 6) |
|
|
|
|
var buff = [UInt8](repeating: 0, count: 6) |
|
|
|
|
|
|
|
|
|
var bytesNum = try m.put(row: 1, col: 2, data: [10, 20, 30, 40, 50, 60] as [Double]) |
|
|
|
|
|
|
|
|
@ -731,16 +839,16 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
bytesNum = try sm.get(row: 0, col: 0, data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum); |
|
|
|
|
XCTAssert(buff == [-1, -2, -3, -4, -5, -6]) |
|
|
|
|
XCTAssert(buff == [255, 254, 253, 252, 251, 250]) |
|
|
|
|
bytesNum = try m.get(row: 2, col: 3, data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum); |
|
|
|
|
XCTAssert(buff == [-1, -2, -3, -4, -5, -6]) |
|
|
|
|
XCTAssert(buff == [255, 254, 253, 252, 251, 250]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntArrayDoubleArray() throws { |
|
|
|
|
let m = Mat(sizes: [5, 5, 5], type: CvType.CV_8SC3, scalar: Scalar(1, 2, 3)) |
|
|
|
|
let m = Mat(sizes: [5, 5, 5], type: CvType.CV_8UC3, scalar: Scalar(1, 2, 3)) |
|
|
|
|
let sm = m.submat(ranges: [Range(start: 0, end: 2), Range(start: 1, end: 3), Range(start: 2, end: 4)]) |
|
|
|
|
var buff = [Int8](repeating: 0, count: 6) |
|
|
|
|
var buff = [UInt8](repeating: 0, count: 6) |
|
|
|
|
|
|
|
|
|
var bytesNum = try m.put(indices: [1, 2, 0], data: [10, 20, 30, 40, 50, 60] as [Double]) |
|
|
|
|
|
|
|
|
@ -754,10 +862,10 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssertEqual(6, bytesNum); |
|
|
|
|
bytesNum = try sm.get(indices: [0, 0, 0], data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum); |
|
|
|
|
XCTAssert(buff == [-1, -2, -3, -4, -5, -6]) |
|
|
|
|
XCTAssert(buff == [255, 254, 253, 252, 251, 250]) |
|
|
|
|
bytesNum = try m.get(indices: [0, 1, 2], data: &buff) |
|
|
|
|
XCTAssertEqual(6, bytesNum) |
|
|
|
|
XCTAssert(buff == [-1, -2, -3, -4, -5, -6]) |
|
|
|
|
XCTAssert(buff == [255, 254, 253, 252, 251, 250]) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntIntFloatArray() throws { |
|
|
|
@ -820,7 +928,7 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssert([40, 50, 60] == m.get(indices: [0, 1, 0])) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntIntShortArray() throws { |
|
|
|
|
func testPutIntIntInt16Array() throws { |
|
|
|
|
let m = Mat(rows: 5, cols: 5, type: CvType.CV_16SC3, scalar: Scalar(-1, -2, -3)) |
|
|
|
|
let elements: [Int16] = [ 10, 20, 30, 40, 50, 60] |
|
|
|
|
|
|
|
|
@ -834,7 +942,21 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssert([40, 50, 60] == m.get(row: 2, col: 4)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntArrayShortArray() throws { |
|
|
|
|
func testPutIntIntUInt16Array() throws { |
|
|
|
|
let m = Mat(rows: 5, cols: 5, type: CvType.CV_16UC3, scalar: Scalar(-1, -2, -3)) |
|
|
|
|
let elements: [UInt16] = [ 10, 20, 30, 40, 50, 60] |
|
|
|
|
|
|
|
|
|
var bytesNum = try m.put(row: 2, col: 3, data: elements) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(Int32(elements.count * 2), bytesNum) |
|
|
|
|
let m1 = m.col(3) |
|
|
|
|
var buff = [UInt16](repeating: 0, count: 3) |
|
|
|
|
bytesNum = try m1.get(row: 2, col: 0, data: &buff) |
|
|
|
|
XCTAssert(buff == [10, 20, 30]) |
|
|
|
|
XCTAssert([40, 50, 60] == m.get(row: 2, col: 4)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntArrayInt16Array() throws { |
|
|
|
|
let m = Mat(sizes: [5, 5, 5], type: CvType.CV_16SC3, scalar: Scalar(-1, -2, -3)) |
|
|
|
|
let elements: [Int16] = [ 10, 20, 30, 40, 50, 60] |
|
|
|
|
|
|
|
|
@ -848,6 +970,20 @@ class MatTests: OpenCVTestCase { |
|
|
|
|
XCTAssert([40, 50, 60] == m.get(indices: [0, 2, 4])) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testPutIntArrayUInt16Array() throws { |
|
|
|
|
let m = Mat(sizes: [5, 5, 5], type: CvType.CV_16UC3, scalar: Scalar(-1, -2, -3)) |
|
|
|
|
let elements: [UInt16] = [ 10, 20, 30, 40, 50, 60] |
|
|
|
|
|
|
|
|
|
var bytesNum = try m.put(indices: [0, 2, 3], data: elements) |
|
|
|
|
|
|
|
|
|
XCTAssertEqual(Int32(elements.count * 2), bytesNum) |
|
|
|
|
let m1 = m.submat(ranges: [Range.all(), Range.all(), Range(start: 3, end: 4)]) |
|
|
|
|
var buff = [UInt16](repeating: 0, count: 3) |
|
|
|
|
bytesNum = try m1.get(indices: [0, 2, 0], data: &buff) |
|
|
|
|
XCTAssert(buff == [10, 20, 30]) |
|
|
|
|
XCTAssert([40, 50, 60] == m.get(indices: [0, 2, 4])) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func testReshapeInt() throws { |
|
|
|
|
let src = Mat(rows: 4, cols: 4, type: CvType.CV_8U, scalar: Scalar(0)) |
|
|
|
|
dst = src.reshape(channels: 4) |
|
|
|
|