How to capture multiple images from Kinect V2 (ROS)?
I created a small code that opens the Kinect IR camera. I can see the real time video that it shows, and I can capture one image. But how do I capture multiple images? It keeps on overwriting with image0
Here is my code so far:
#!/usr/bin/python
import roslib
import rospy
import cv2
import sys
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
class PositionTracker:
def __init__(self):
# subscribe to kinect image messages
self.sub = rospy.Subscriber("kinect2/qhd/image_ir", Image, self.image_callback, queue_size=1)
self.bridge = CvBridge()
def image_callback(self,data):
try:
cv_image = self.bridge.imgmsg_to_cv2(data)
except CvBridgeError as e:
print(e)
cv2.imshow("Image window", cv_image)
c=cv2.waitKey(10)%256
if c == 10:
h,w=cv_image.shape
bitmap=cv2.cv.CreateImage((w,h), cv2.cv.IPL_DEPTH_16S, 1)
cv2.cv.SaveImage('image'+str(click)+'.jpg',bitmap)
click=click+1
#time.sleep(3)
def main(args):
ic = PositionTracker()
rospy.init_node('kinect_tracker')
try:
rospy.spin()
except KeyboardInterrupt:
print("Shutting down")
cv2.destroyAllWindows()
if __name__ == '__main__':
main(sys.argv)
I have tried to use the cv.SaveImage
function. But it gives me an error. The above code opens the Kinect IR camera, but I want it to capture images and save it to the file system. How do I do it?