This is my code . I can convert it into a numpy array and normalize it. but when I write it as a 16 bit image , it gets distorted. But the 8 bit depth image is fine. But for further operations I would prefer a 16 bit image .So is there any other possibility to do this?
import roslib
from matplotlib import pyplot as plt
roslib.load_manifest('beginner_tutorials')
import sys
import rospy
import cv2
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import numpy as np
i=0
np.set_printoptions(threshold='nan')
def callback(data):
try:
cv_image = CvBridge().imgmsg_to_cv2(data, "32FC1")
except CvBridgeError, e:
print e
global i
cv_image1 = np.array(cv_image, dtype=np.float)
cv2.normalize(cv_image1, cv_image1, 0, 1, cv2.NORM_MINMAX)
cv_image1=cv_image1*2**16
cv2.imwrite("/home/admin123/bagfiles/im"+str(i)+".jpg",cv_image1)
i+=1
cv2.waitKey(3)
def video():
rospy.init_node('video', anonymous=True)
im=rospy.Subscriber('/camera/depth_registered/image_rect', Image, callback)
rospy.spin()
if __name__ == '__main__':
video()