10 from sensor_msgs.msg
import CompressedImage
11 from cv_bridge
import CvBridge
12 from std_srvs.srv
import Empty
15 img = cv2.imread(filename, -1)
17 rospy.logerr(
"ERROR image file didn't load or doesn't exist: %s" % filename)
25 self.
publisher = rospy.Publisher(
'panorama/compressed', CompressedImage, queue_size=10)
34 rospy.loginfo(
'Using working directory: %s'% self.
images_path)
41 rospy.loginfo(
'Clearing images waiting to be stitched.')
42 self.
cleanup(delete_images=
True)
46 """ returns space seperated list of files in the images_path """ 53 if files ==
None or files ==
"":
54 rospy.logerr(
"Did not find any images to stitch in: %s" % self.
images_path)
57 rospy.loginfo(
"Stitching files: %s" % files)
60 self.
bash_exec(
'pto_gen -o pano.pto %s' % files)
62 self.
bash_exec(
'cpfind -o pano.pto --multirow --celeste pano.pto')
64 self.
bash_exec(
'cpclean -o pano.pto pano.pto')
66 self.
bash_exec(
'linefind -o pano.pto pano.pto')
68 self.
bash_exec(
'autooptimiser -a -m -l -s -o pano.pto pano.pto')
70 self.
bash_exec(
'pano_modify --canvas=AUTO --crop=AUTO -o pano.pto pano.pto')
72 self.
bash_exec(
'hugin_executor --stitching --prefix=output pano.pto')
74 self.
bash_exec(
'convert output.tif output.png')
76 output_file = os.path.join(self.
images_path,
'output.png')
77 if not os.path.isfile(output_file):
78 rospy.logerr(
'Hugin failed to create a panorama.')
81 rospy.loginfo(
'Panorama saved to: %s/output.png' % self.
images_path)
84 rospy.loginfo(
'Finished.')
88 compressed_image = CvBridge().cv2_to_compressed_imgmsg(img)
89 self.publisher.publish(compressed_image)
93 files_to_be_deleted = [
'output.tif',
'output.png',
'pano.pto']
97 image_types = (
'*.png',
'*.jpg',
'*.gif')
98 for file_type
in image_types:
100 files_to_be_deleted.extend(glob.glob(path))
103 for file
in files_to_be_deleted:
104 file_to_be_deleted = os.path.join(self.
images_path, file)
105 if os.path.isfile(file_to_be_deleted):
106 os.remove(file_to_be_deleted)
109 rospy.loginfo(
'Stitching panorama...')
114 sp = subprocess.Popen(cmd, shell=
True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=self.
images_path)
115 out, err = sp.communicate()
117 rospy.loginfo(
"\n%s" % out)
119 rospy.logerr(
"\n%s" % err)
120 return out, err, sp.returncode
123 rospy.init_node(
'hugin_panorama')
def cleanup(self, delete_images=False)
def stitch_callback(self, data)
def reset_callback(self, data)
def get_image_filenames(self)