def test_conversion(self): indices_msg = PointIndices() while self.msg is None: indices_msg.header.stamp = rospy.Time.now() indices_msg.indices = self.indices self.pub.publish(indices_msg) rospy.sleep(0.1) self.assertEqual(len(self.msg.cluster_indices), 1) self.assertTupleEqual(self.msg.cluster_indices[0].indices, self.indices)
def test_conversion(self): indices_msg = PointIndices() while self.msg is None: indices_msg.header.stamp = rospy.Time.now() indices_msg.indices = self.indices self.pub.publish(indices_msg) rospy.sleep(0.1) self.assertEqual(len(self.msg.cluster_indices), 1) self.assertTupleEqual(self.msg.cluster_indices[0].indices, self.indices)
def _convert(self, rects_msg, img_height=None, img_width=None): H = self.img_height if img_height is None else img_height W = self.img_width if img_width is None else img_width cpi_msg = ClusterPointIndices(header=rects_msg.header) for rect in rects_msg.rects: indices_msg = PointIndices(header=rects_msg.header) ymin = max(0, int(np.floor(rect.y))) xmin = max(0, int(np.floor(rect.x))) ymax = min(H, int(np.ceil(rect.y + rect.height))) xmax = min(W, int(np.ceil(rect.x + rect.width))) indices = [ range(W * y + xmin, W * y + xmax) for y in range(ymin, ymax) ] indices_msg.indices = np.array(indices, dtype=np.int32).flatten() cpi_msg.cluster_indices.append(indices_msg) self.pub.publish(cpi_msg)
def _test_each_conversion(self, name): bridge = cv_bridge.CvBridge() imgmsg = bridge.cv2_to_imgmsg(np.zeros((30, 30), dtype=np.uint8), encoding='mono8') indices_msg = PointIndices() indices_msg.indices = np.arange(10, 30) while self.msg.get(name) is None: imgmsg.header.stamp = indices_msg.header.stamp = rospy.Time.now() self.pub_indices.publish(indices_msg) self.pub_img.publish(imgmsg) rospy.sleep(0.1) mask_in = bridge.imgmsg_to_cv2( self.msg[name], desired_encoding='mono8') mask_in = np.squeeze(mask_in) mask_expected = np.zeros((imgmsg.height, imgmsg.width), dtype=np.uint8) mask_expected.ravel()[np.arange(10, 30)] = 255 np.testing.assert_array_equal(mask_in, mask_expected)
def _test_each_conversion(self, name): bridge = cv_bridge.CvBridge() imgmsg = bridge.cv2_to_imgmsg(np.zeros((30, 30), dtype=np.uint8), encoding='mono8') indices_msg = PointIndices() indices_msg.indices = np.arange(10, 30) while self.msg.get(name) is None: imgmsg.header.stamp = indices_msg.header.stamp = rospy.Time.now() self.pub_indices.publish(indices_msg) self.pub_img.publish(imgmsg) rospy.sleep(0.1) mask_in = bridge.imgmsg_to_cv2(self.msg[name], desired_encoding='mono8') mask_in = np.squeeze(mask_in) mask_expected = np.zeros((imgmsg.height, imgmsg.width), dtype=np.uint8) mask_expected.ravel()[np.arange(10, 30)] = 255 np.testing.assert_array_equal(mask_in, mask_expected)