Beispiel #1
0
 def test_setting_value_in_buffer(self):
     mat = Mat(rows=1, cols=2, dtype=CV_32FC3)
     array1 = mat.asarray()
     array1[0, 0, :] = [0, 1, 2]
     array2 = mat.asarray()
     assert np.array_equal(array2[0, 0, :], np.array([0, 1, 2]))
     del array1
     del array2
Beispiel #2
0
def test_read_write_flo(tmpdir):
    flow_path = str(tmpdir / 'test.flo')
    rows = 20
    cols = 30
    channels = 2
    flow_np = (np.random.rand(rows, cols, channels) * 20).astype(np.float32)
    flow = Mat.fromarray(flow_np, copy=True)

    write_flo(flow, flow_path)
    flow2 = np.array(read_flo(flow_path))

    assert_array_equal(flow2, flow)
Beispiel #3
0
 def test_asarray_uint(self):
     mat = Mat(rows=1, cols=2, dtype=CV_8UC3)
     array = mat.asarray()
     assert array.dtype == np.uint8
     assert array.shape == (1, 2, 3)
Beispiel #4
0
 def test_repr(self):
     mat = Mat(rows=1, cols=2)
     assert repr(mat) == "Mat(rows=1, cols=2, dtype=16)"
Beispiel #5
0
 def test_non_empty_array_is_true(self):
     mat = Mat(rows=1, cols=1)
     assert bool(mat)
Beispiel #6
0
 def test_empty_array_is_false(self):
     mat = Mat()
     assert bool(mat) == False
Beispiel #7
0
 def test_fromarray_maintains_shape(self):
     array = np.zeros((5, 10, 3), dtype=np.uint8)
     mat = Mat.fromarray(array)
     assert (5, 10, 3) == mat.shape
Beispiel #8
0
 def test_channels(self):
     mat = Mat(rows=5, cols=5, dtype=CV_8UC3)
     assert mat.channels == 3
Beispiel #9
0
 def test_empty(self):
     mat = Mat(rows=0, cols=0)
     assert mat.empty
Beispiel #10
0
 def test_cols_property(self):
     n_cols = 20
     mat = Mat(rows=10, cols=n_cols)
     assert mat.cols == n_cols
Beispiel #11
0
 def test_default_dtype_is_CV_8UC3(self):
     mat = Mat(rows=5, cols=5)
     assert mat.dtype == CV_8UC3
Beispiel #12
0
 def test_rows_property(self):
     n_rows = 10
     mat = Mat(rows=n_rows, cols=20)
     assert mat.rows == n_rows
Beispiel #13
0
def array_to_mat(array):
    """Convert np.ndarray to OpenCV Mat"""
    return Mat.fromarray(array)
Beispiel #14
0
def to_rgb(grayscale_img: np.ndarray):
    assert grayscale_img.ndim == 2
    return Mat.fromarray(
        np.stack([grayscale_img] * 3, axis=-1).astype(np.uint8))
Beispiel #15
0
 def test_creation(self):
     Mat()
Beispiel #16
0
 def test_ndim(self):
     mat = Mat(rows=0, cols=0, dtype=CV_8UC3)
     assert mat.ndim == 3
Beispiel #17
0
 def test_asarray_float(self):
     mat = Mat(rows=1, cols=2, dtype=CV_32FC2)
     array = mat.asarray()
     assert array.dtype == np.float32
     assert array.shape == (1, 2, 2)
     del array
Beispiel #18
0
 def test_depth(self):
     mat = Mat(rows=1, cols=1, dtype=CV_64FC3)
     assert mat.depth == CV_64F
Beispiel #19
0
 def test_fromarray_preserves_data(self):
     array = np.random.randint(0, 255, size=(4, 5, 3), dtype=np.uint8)
     mat = Mat.fromarray(array)
     mat_as_array = mat.asarray()
     assert_equal(array, mat_as_array)
Beispiel #20
0
 def test_shape(self):
     mat = Mat(rows=10, cols=20, dtype=CV_8UC3)
     assert mat.shape == (10, 20, 3)
Beispiel #21
0
 def test_non_emtpy_creation(self):
     Mat(rows=10, cols=20)
Beispiel #22
0
def make_random_uint8_mat(rows, cols, channels):
    return Mat.fromarray((np.random.rand(rows, cols, channels) * 255).astype(
            np.uint8), copy=True)