Gazebo | Ignition | Community
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I had to add my own implementation to add noise to a depth image from a kinect camera. I simply added some gaussian noise to it and set some random pixels to zero. Can't really tell if this is a good solution or anyhow approximating the noise of a real camera, but anyway this is how I've done it:

data = rospy.wait_for_message('/camera/depth/image_raw', Image, timeout=5)
# change encoding of the image
bridge = CvBridge()
cv_image = bridge.imgmsg_to_cv2(data, desired_encoding="32FC1")
# convert to a numpy array
image = np.array(cv_image, dtype=np.float)
# adding noise to (simulated) depth image
image = image + np.random.normal(0.0, 10.0, image.shape)
# set approx. 5% of all pixels to zero
mask = (np.random.uniform(0,1,size=image.shape) > 0.95).astype(np.bool)
image[mask] = 0
# normalizing image
cv2.normalize(image, image, 0, 255, cv2.NORM_MINMAX)

I had to add my own implementation to add noise to a depth image from a kinect camera. I did this in my python program, not in a custom C++ sensor plugin. I simply added some gaussian noise to it and set some random pixels to zero. Can't really tell if this is a good solution or anyhow approximating the noise of a real camera, but anyway this is how I've done it:

data = rospy.wait_for_message('/camera/depth/image_raw', Image, timeout=5)
# change encoding of the image
bridge = CvBridge()
cv_image = bridge.imgmsg_to_cv2(data, desired_encoding="32FC1")
# convert to a numpy array
image = np.array(cv_image, dtype=np.float)
# adding noise to (simulated) depth image
image = image + np.random.normal(0.0, 10.0, image.shape)
# set approx. 5% of all pixels to zero
mask = (np.random.uniform(0,1,size=image.shape) > 0.95).astype(np.bool)
image[mask] = 0
# normalizing image
cv2.normalize(image, image, 0, 255, cv2.NORM_MINMAX)