Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
test_conversions.py
1from visp.core import ImageConvert
2import numpy as np
3
5 h, w = 50, 50
6 cases = [
7 {
8 'bytes': 3,
9 'input_dtype': np.uint8,
10 'fn': ImageConvert.HSVToRGB
11 },
12 {
13 'bytes': 3,
14 'input_dtype': np.float64,
15 'fn': ImageConvert.HSVToRGB
16 },
17 {
18 'bytes': 4,
19 'input_dtype': np.uint8,
20 'fn': ImageConvert.HSVToRGBa
21 },
22 {
23 'bytes': 4,
24 'input_dtype': np.float64,
25 'fn': ImageConvert.HSVToRGBa
26 }
27 ]
28 for case in cases:
29 hsv = np.zeros((3, h, w), dtype=case['input_dtype'])
30 rgb = np.ones((h, w, case['bytes']), dtype=np.uint8)
31 rgb_old = rgb.copy()
32 case['fn'](hsv, rgb)
33 assert not np.allclose(rgb, rgb_old)
34
35
37 h, w = 50, 50
38 I = np.empty((h, w, 3), dtype=np.uint8)
39 from visp.core import ImageGray
40 out = ImageGray(h, w)
41 ImageConvert.RGBToGrey(I, out)
42 out2 = np.empty((h,w), dtype=np.uint8)
43 ImageConvert.RGBToGrey(I, out2)
44 assert np.all(np.equal(out, out2))
45
46
48 h, w = 50, 50
49 I = np.empty((h, w, 3), dtype=np.uint8)
50 from visp.core import ImageRGBa
51 out = ImageRGBa(h, w)
52 ImageConvert.BGRToRGBa(I, out)
53 out2 = np.empty((h, w, 4), dtype=np.uint8)
54 ImageConvert.BGRToRGBa(I, out2)
55 assert np.all(np.equal(out, out2))
56
57
59 h, w = 50, 50
60 cases = [
61 {
62 'bytes': 3,
63 'input_dtype': np.uint8,
64 'fn': ImageConvert.RGBToHSV
65 },
66 {
67 'bytes': 3,
68 'input_dtype': np.float64,
69 'fn': ImageConvert.RGBToHSV
70 },
71 {
72 'bytes': 4,
73 'input_dtype': np.uint8,
74 'fn': ImageConvert.RGBaToHSV
75 },
76 {
77 'bytes': 4,
78 'input_dtype': np.float64,
79 'fn': ImageConvert.RGBaToHSV
80 }
81 ]
82 for case in cases:
83 hsv = np.zeros((3, h, w), dtype=case['input_dtype'])
84 rgb = np.ones((h, w, case['bytes']), dtype=np.uint8)
85 hsv_old = hsv.copy()
86 case['fn'](rgb, hsv)
87 assert not np.allclose(hsv, hsv_old)
88
89
90
92 h, w = 32, 32
93 fns = [
94 ImageConvert.demosaicRGGBToRGBaMalvar,
95 ImageConvert.demosaicGRBGToRGBaMalvar,
96 ImageConvert.demosaicGBRGToRGBaMalvar,
97 ImageConvert.demosaicBGGRToRGBaMalvar,
98 ImageConvert.demosaicRGGBToRGBaBilinear,
99 ImageConvert.demosaicGRBGToRGBaBilinear,
100 ImageConvert.demosaicGBRGToRGBaBilinear,
101 ImageConvert.demosaicBGGRToRGBaBilinear,
102 ]
103 for fn in fns:
104 for dtype in [np.uint8, np.uint16]:
105 bayer_data = np.ones((h, w), dtype=dtype) * 128
106 rgba = np.zeros((h, w, 4), dtype=dtype)
107 old_rgba = rgba.copy()
108 fn(bayer_data, rgba)
109 assert not np.allclose(rgba, old_rgba), f'Error when testing {fn}, with dtype {dtype}'