Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 4
0
 def test_repr(self):
     mat = Mat(rows=1, cols=2)
     assert repr(mat) == "Mat(rows=1, cols=2, dtype=16)"
Ejemplo n.º 5
0
 def test_non_empty_array_is_true(self):
     mat = Mat(rows=1, cols=1)
     assert bool(mat)
Ejemplo n.º 6
0
 def test_empty_array_is_false(self):
     mat = Mat()
     assert bool(mat) == False
Ejemplo n.º 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
Ejemplo n.º 8
0
 def test_channels(self):
     mat = Mat(rows=5, cols=5, dtype=CV_8UC3)
     assert mat.channels == 3
Ejemplo n.º 9
0
 def test_empty(self):
     mat = Mat(rows=0, cols=0)
     assert mat.empty
Ejemplo n.º 10
0
 def test_cols_property(self):
     n_cols = 20
     mat = Mat(rows=10, cols=n_cols)
     assert mat.cols == n_cols
Ejemplo n.º 11
0
 def test_default_dtype_is_CV_8UC3(self):
     mat = Mat(rows=5, cols=5)
     assert mat.dtype == CV_8UC3
Ejemplo n.º 12
0
 def test_rows_property(self):
     n_rows = 10
     mat = Mat(rows=n_rows, cols=20)
     assert mat.rows == n_rows
Ejemplo n.º 13
0
def array_to_mat(array):
    """Convert np.ndarray to OpenCV Mat"""
    return Mat.fromarray(array)
Ejemplo n.º 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))
Ejemplo n.º 15
0
 def test_creation(self):
     Mat()
Ejemplo n.º 16
0
 def test_ndim(self):
     mat = Mat(rows=0, cols=0, dtype=CV_8UC3)
     assert mat.ndim == 3
Ejemplo n.º 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
Ejemplo n.º 18
0
 def test_depth(self):
     mat = Mat(rows=1, cols=1, dtype=CV_64FC3)
     assert mat.depth == CV_64F
Ejemplo n.º 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)
Ejemplo n.º 20
0
 def test_shape(self):
     mat = Mat(rows=10, cols=20, dtype=CV_8UC3)
     assert mat.shape == (10, 20, 3)
Ejemplo n.º 21
0
 def test_non_emtpy_creation(self):
     Mat(rows=10, cols=20)
Ejemplo n.º 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)