Commit d74296e6 authored by Larkin Heintzman's avatar Larkin Heintzman

renamed image node and clean up

parent aff503f7
#! /usr/bin/python3
import rospy, sys, math, cv2, numpy as np, std_msgs.msg
from sensor_msgs.msg import Image
from std_msgs.msg import Header
import os.path, getpass
from cv_bridge import CvBridge, CvBridgeError
class ImageViewer():
def __init__(self):
self.bridge = CvBridge()
self.subscriber = rospy.Subscriber("usb_camera/image_raw", Image, self.imageCallback)
self.params = None
self.image = None
self.seq = None
def imageCallback(self, frame):
# self.params = self.getParams()
try:
self.image = self.bridge.imgmsg_to_cv2(frame, "bgr8")
self.seq = frame.header.seq
except CvBridgeError as err:
rospy.loginfo("there was error!")
rospy.loginfo(err)
def main():
iv = ImageViewer()
rospy.init_node("imageSaver")
windowFlag = rospy.get_param("~visualize")
saveFlag = rospy.get_param("~save")
folderName = rospy.get_param("~folderName")
# folderName = "/home/" + getpass.getuser() + "/imageDump"
if windowFlag:
cv2.namedWindow("image window")
cv2.waitKey(200)
while not rospy.is_shutdown():
if iv.image is not None:
# cv2.imshow("image window", iv.image)
if np.mod(iv.seq, 32) == 0:
if os.path.isdir(folderName):
# print ("File exist")
if windowFlag:
cv2.imshow("image window", iv.image)
rospy.loginfo("publishing image to window seq: " + iv.seq)
if saveFlag:
cv2.imwrite("/home/" + getpass.getuser() + "/" folderName + "/camera_image_{seq}.jpeg".format(seq = iv.seq), iv.image)
rospy.loginfo("saving image to folder: home-> " + folderName + "-> camera_image_{seq}.jpeg".format(seq = iv.seq) + " seq: " + str(iv.seq))
cv2.waitKey(10)
else:
rospy.loginfo("camera dir missing!")
# cv2.destroyAllWindows()
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment