3 @file check_camera_info_matrix.py 16 PKG =
'realsense_camera' 18 PROJECTION =
'projection_matrix' 19 PROJECTION_LENGHT = 12
20 DISTORTION =
'distortion_coefficients' 22 ROTATION =
'rotation_identity' 29 CAMERAS = [
'R200',
'F200',
'SR300',
'ZR300']
34 @class CheckCameraInfoMatrix 43 self.assertIn(camera_type, CAMERAS)
46 """search values of matrix type from string, 47 and organize into matrix array 52 @return matrix_array: matrix values 54 if (matrix_type == PROJECTION
and not string.find(
'P: ') == -1) \
55 or (matrix_type == DISTORTION
and 56 not string.find(
'D: ') == -1) \
57 or (matrix_type == ROTATION
and 58 not string.find(
'R: ') == -1):
59 values = re.findall(
r'([0-9]+\.[0-9]+)', string)
60 matrix_array = map(float, values)
66 """determine whether the value equal to 0 70 @return True: equal to 0; False: not equal to 0 72 if (value > -0.00000001)
and (value < 0.00000001):
78 """run rostopic to print camera info, get matrix values from stdout 85 cmd =
'rostopic echo /camera/' + stream_type +
'/camera_info' 87 process = subprocess.Popen(cmd, stdout=subprocess.PIPE,
88 stderr=subprocess.PIPE, shell=
True)
90 buff = process.stdout.readline()
91 if buff ==
'' and process.poll
is not None:
95 os.kill(process.pid, signal.SIGKILL)
100 """verify projection matrix values, adapt each stream type 101 @fn verify_projection_matrix 107 if matrix ==
'' or len(matrix) != PROJECTION_LENGHT \
108 or stream_type ==
'':
109 self.assertTrue(
False,
110 'Not get correct projection matrix or stream type.')
112 if stream_type == DEPTH:
116 self.assertTrue(
False,
'Projection matrix value is incorrect.')
117 elif (stream_type == COLOR
or 119 stream_type == IR2
or 120 stream_type == FISHEYE):
121 if (
not self.
is_zero(matrix[3])
or 124 self.assertTrue(
False,
'Projection matrix value is incorrect.')
126 self.assertTrue(
False,
127 'Stream type "' + stream_type +
'" is invalid.')
130 """verify rotation matrix values, adapt each stream type 131 @fn verify_rotation_matrix 136 if matrix ==
'' or len(matrix) != ROTATION_LENGHT:
137 self.assertTrue(
False,
'Not get correct rotation matrix.')
139 for i
in range(0, len(matrix)):
140 if i == 0
or i == 4
or i == 8:
141 if matrix[i] < 0.99999999
or matrix[i] > 1.00000001:
142 self.assertTrue(
False,
'Rotation matrix value is incorrect.')
144 if not self.
is_zero(matrix[i]):
145 self.assertTrue(
False,
'Rotation matrix value is incorrect.')
148 """verify distortion matrix values, adapt each stream type 149 @fn verify_distortion_matrix 155 if camera_type ==
'' or stream_type ==
'' or matrix ==
'' \
156 or len(matrix) != DISTORTION_LENGHT:
157 self.assertTrue(
False,
158 'Not get correct distortion matrix or stream type.')
160 if camera_type ==
'R200' or camera_type ==
'ZR300':
161 if stream_type == COLOR:
162 for i
in range(0, len(matrix)):
164 self.assertTrue(self.
is_zero(matrix[i]),
'Distortion \ 165 matrix value of color is incorrect.')
167 self.assertFalse(self.
is_zero(matrix[i]),
'Distortion \ 168 matrix value of color is incorrect.')
169 elif (stream_type == DEPTH
or 172 for i
in range(0, len(matrix)):
173 self.assertTrue(self.
is_zero(matrix[i]),
'Distortion \ 174 matrix value of (depth/IR/IR2) is incorrect.')
175 elif stream_type == FISHEYE:
176 for i
in range(0, len(matrix)):
178 self.assertFalse(self.
is_zero(matrix[i]),
'Distortion \ 179 matrix value of fisheye is incorrect.')
181 self.assertTrue(self.
is_zero(matrix[i]),
'Distortion \ 182 matrix value of fisheye is incorrect.')
184 self.assertTrue(
False,
185 'Stream type "' + stream_type +
'" is invalid.')
186 elif camera_type ==
'F200' or camera_type ==
'SR300':
187 if stream_type == COLOR:
188 for i
in range(0, len(matrix)):
189 self.assertTrue(self.
is_zero(matrix[i]),
'Distortion \ 190 matrix value of color is incorrect.')
191 elif stream_type == DEPTH
or stream_type == IR:
192 for i
in range(0, len(matrix)):
193 self.assertFalse(self.
is_zero(matrix[i]),
'Distortion \ 194 matrix value of (depth/IR) is incorrect.')
196 self.assertTrue(
False,
197 'Stream type "' + stream_type +
'" is invalid.')
200 """check projection matrix values from camera info 201 @fn test_check_projection_matrix 205 rospy.init_node(NAME, anonymous=
True, log_level=rospy.INFO)
219 if camera_type ==
'R200' or camera_type ==
'ZR300':
223 if camera_type ==
'ZR300':
229 """check rotation identity matrix values from camera info 230 @fn test_check_rotation_identity_matrix 234 rospy.init_node(NAME, anonymous=
True, log_level=rospy.INFO)
245 if camera_type ==
'R200' or camera_type ==
'ZR300':
248 if camera_type ==
'ZR300':
253 """check distortion coefficients matrix values from camera info 254 @fn test_check_distortion_coefficients 258 rospy.init_node(NAME, anonymous=
True, log_level=rospy.INFO)
272 if camera_type ==
'R200' or camera_type ==
'ZR300':
276 if camera_type ==
'ZR300':
281 if __name__ ==
'__main__':
283 rostest.rosrun(PKG, NAME, CheckCameraInfoMatrix, sys.argv)
def test_camera_info_check_distortion_coefficients(self)
def get_camera_info(self, stream_type, matrix_type)
def verify_rotation_matrix(self, matrix)
def test_camera_info_check_rotation_identity_matrix(self)
def verify_projection_matrix(self, matrix, stream_type)
def parse_camera_type(args)
def test_camera_info_check_projection_matrix(self)
def verify_distortion_matrix(self, matrix, stream_type)
def get_matrix(self, string, matrix_type)