def __init__(self):
		self.node_name = rospy.get_name()

		self.active = True
		self.image_pub_switch = rospy.get_param("~publish_corrected_image",False)
		
        # Initialize publishers and subscribers
		self.pub_image = rospy.Publisher("~corrected_image",Image,queue_size=1)
		self.pub_health = rospy.Publisher("~health",AntiInstagramHealth,queue_size=1,latch=True)
		self.pub_transform = rospy.Publisher("~transform",AntiInstagramTransform,queue_size=1,latch=True)

		#self.sub_switch = rospy.Subscriber("~switch",BoolStamped, self.cbSwitch, queue_size=1)
		#self.sub_image = rospy.Subscriber("~uncorrected_image",Image,self.cbNewImage,queue_size=1)
		self.sub_image = rospy.Subscriber("~uncorrected_image", CompressedImage, self.cbNewImage,queue_size=1)
		self.sub_click = rospy.Subscriber("~click", BoolStamped, self.cbClick, queue_size=1)

		# Verbose option 
		self.verbose = rospy.get_param('~verbose',True)  

		# Initialize health message
		self.health = AntiInstagramHealth()

		# Initialize transform message
		self.transform = AntiInstagramTransform()
		# FIXME: read default from configuration and publish it

		self.ai = AntiInstagram()
		self.corrected_image = Image()
		self.bridge = CvBridge()

		self.image_msg = None
		self.click_on = False
예제 #2
0
    def test_anti_instagram(self):
        ai = AntiInstagram()

        #### TEST SINGLE TRANSFORM ####
        error_threshold = 500
        # load test images
        failure = False

        imagesetf = [
            "inputimage0.jpg",
            "inputimage1.jpg",
        ]
        gtimagesetf = [
            "groundtruthimage0.jpg",
            "groundtruthimage1.jpg",
        ]

        package_root = get_rospkg_root('anti_instagram')
        def add_dir(x):
            return os.path.join(package_root, 'scripts', x)

        imagesetf = map(add_dir, imagesetf)
        gtimagesetf = map(add_dir, gtimagesetf)


        imageset = map(load_image, imagesetf)
        gtimageset = map(load_image, gtimagesetf)
        errors = self.correctImages(ai, imageset, gtimageset, error_threshold)
        logger.info("Test Image Errors: %s" % errors)

        self.assertLess(max(errors), error_threshold)
예제 #3
0
    def __init__(self):
        self.node_name = rospy.get_name()
        self.image_lock = threading.Lock()

        self.ai = AntiInstagram()

        # XXX: read parameters
        # XXX: parameters need to go inside config file, ask aleks about heirarchy
        self.interval = self.setup_parameter("~ai_interval", 10)
        self.color_balance_percentage = self.setup_parameter(
            "~cb_percentage", 0.8)  # XXX: change in all launch files
        self.output_scale = self.setup_parameter(
            "~scale_percent", 0.4)  # XXX: change in all launch files
        self.calculation_scale = self.setup_parameter("~resize", 0.2)

        self.bridge = CvBridge()

        self.image = None

        rospy.Timer(rospy.Duration(self.interval),
                    self.calculate_new_parameters)

        self.uncorrected_image_subscriber = rospy.Subscriber(
            '~uncorrected_image/compressed',
            CompressedImage,
            self.process_image,
            buff_size=921600,
            queue_size=1)

        self.corrected_image_publisher = rospy.Publisher(
            "~corrected_image/compressed", CompressedImage, queue_size=1)
예제 #4
0
    def __init__(self):
        self.node_name = "LineDetectorNode"

        self.bw_1 = 0
        self.bw_2 = 0

        # Thread lock
        self.thread_lock = threading.Lock()

        # Constructor of line detector
        self.bridge = CvBridge()

        self.active = True

        self.stats = Stats()

        # Only be verbose every 10 cycles
        self.intermittent_interval = 100
        self.intermittent_counter = 0

        # color correction
        self.ai = AntiInstagram()

        # these will be added if it becomes verbose
        self.pub_edge = None
        self.pub_colorSegment = None

        self.detector = None
        self.verbose = None
        self.updateParams(None)

        # Publishers
        self.pub_lines = rospy.Publisher("~segment_list",
                                         SegmentList,
                                         queue_size=1)
        self.pub_image = rospy.Publisher("~image_with_lines",
                                         Image,
                                         queue_size=1)

        # Subscribers
        self.sub_image = rospy.Subscriber("~image",
                                          CompressedImage,
                                          self.cbImage,
                                          queue_size=1)
        self.sub_transform = rospy.Subscriber("~transform",
                                              AntiInstagramTransform,
                                              self.cbTransform,
                                              queue_size=1)
        self.sub_switch = rospy.Subscriber("~switch",
                                           BoolStamped,
                                           self.cbSwitch,
                                           queue_size=1)

        rospy.loginfo("[%s] Initialized (verbose = %s)." %
                      (self.node_name, self.verbose))

        rospy.Timer(rospy.Duration.from_sec(2.0), self.updateParams)
예제 #5
0
    def __init__(self):
        self.node_name = rospy.get_name()

        self.active = True
        self.locked = False

        self.image_pub_switch = rospy.get_param("~publish_corrected_image",
                                                False)

        # Initialize publishers and subscribers
        self.pub_image = rospy.Publisher("~corrected_image",
                                         Image,
                                         queue_size=1)
        self.pub_health = rospy.Publisher("~health",
                                          AntiInstagramHealth,
                                          queue_size=1,
                                          latch=True)
        self.pub_transform = rospy.Publisher("~transform",
                                             AntiInstagramTransform,
                                             queue_size=1,
                                             latch=True)

        #self.sub_switch = rospy.Subscriber("~switch",BoolStamped, self.cbSwitch, queue_size=1)
        #self.sub_image = rospy.Subscriber("~uncorrected_image",Image,self.cbNewImage,queue_size=1)
        self.sub_image = rospy.Subscriber("~uncorrected_image",
                                          CompressedImage,
                                          self.cbNewImage,
                                          queue_size=1)
        self.sub_click = rospy.Subscriber("~click",
                                          BoolStamped,
                                          self.cbClick,
                                          queue_size=1)

        self.trans_timer = rospy.Timer(rospy.Duration.from_sec(20),
                                       self.cbPubTrans, True)
        # Verbose option
        self.verbose = rospy.get_param('line_detector_node/verbose', True)

        # Initialize health message
        self.health = AntiInstagramHealth()

        # Initialize transform message
        self.transform = AntiInstagramTransform()
        # FIXME: read default from configuration and publish it
        self.ai_scale = np.array(
            [2.2728408473337893, 2.2728273205024614, 2.272844346401005])
        self.ai_shift = np.array(
            [21.47181119272393, 37.14653160247276, 4.089311860796786])

        self.ai = AntiInstagram()
        self.corrected_image = Image()
        self.bridge = CvBridge()

        self.image_msg = None
        self.click_on = False
예제 #6
0
파일: ldn.py 프로젝트: light5551/dt-core
    def __init__(self):
        EasyNode.__init__(self, "line_detector2", "line_detector_node2")

        self.detector = None
        self.bridge = CvBridge()
        self.ai = AntiInstagram()
        self.active = True

        # Only be verbose every 10 cycles
        self.intermittent_interval = 100
        self.intermittent_counter = 0
예제 #7
0
    def __init__(self):
        self.node_name = "Line Detector2"

        # Thread lock
        self.thread_lock = threading.Lock()

        # Constructor of line detector
        self.bridge = CvBridge()
        self.detector = LineDetector2()

        # Parameters
        self.active = True

        self.intermittent_interval = 100
        self.intermittent_counter = 0

        self.updateParams(None)

        # color correction
        self.ai = AntiInstagram()

        # Publishers
        self.pub_lines = rospy.Publisher("~segment_list",
                                         SegmentList,
                                         queue_size=1)
        self.pub_image = rospy.Publisher("~image_with_lines",
                                         Image,
                                         queue_size=1)

        # Verbose option
        if self.verbose:
            self.pub_edge = rospy.Publisher("~edge", Image, queue_size=1)
            self.pub_colorSegment = rospy.Publisher("~segment",
                                                    Image,
                                                    queue_size=1)

        # Subscribers
        self.sub_image = rospy.Subscriber("~image",
                                          CompressedImage,
                                          self.cbImage,
                                          queue_size=1)
        self.sub_transform = rospy.Subscriber("~transform",
                                              AntiInstagramTransform,
                                              self.cbTransform,
                                              queue_size=1)
        self.sub_switch = rospy.Subscriber("~switch",
                                           BoolStamped,
                                           self.cbSwitch,
                                           queue_size=1)
        rospy.loginfo("[%s] Initialized." % (self.node_name))

        self.timer = rospy.Timer(rospy.Duration.from_sec(1.0),
                                 self.updateParams)
def setup():
    img = random_image(Params.shape[0], Params.shape[1])
    ai = AntiInstagram()
    return ai, img
예제 #9
0
def main():
    # check number of arguments
    if len(sys.argv) != 3:
        print(
            'This program expects exactly two arguments: an image filename and an output directory.'
        )
        sys.exit()

    # store inputs
    file = sys.argv[1]
    outdir = sys.argv[2]

    # check if file exists
    if not os.path.isfile(file):
        print('file not found')
        sys.exit(2)

    # check if dir exists, create if not
    if not os.path.exists(outdir):
        os.makedirs(outdir)

    # read the image
    input_img = cv2.imread(file, cv2.IMREAD_UNCHANGED)

    # lets do the masking!
    surf = identifyLaneSurface(input_img, use_hsv=False, grad_thresh=20)
    input_img = np.expand_dims(surf, -1) * input_img
    print('masked image!')
    cv2.imshow('mask', input_img)
    cv2.waitKey(0)

    # create instance of AntiInstagram
    ai = AntiInstagram()

    ai.calculateTransform(input_img)
    print('Transform Calculation completed!')

    corrected_img = ai.applyTransform(input_img)
    print('Transform applied!')
    cv2.imshow('mask', corrected_img)
    cv2.waitKey(0)

    #  polygons for pic1_smaller.jpg and pic2_smaller.jpg (hardcoded for now)
    polygon_black = [(280, 570), (220, 760), (870, 750), (810, 580)]
    polygon_white = [(781, 431), (975, 660), (1040, 633), (827, 418)]
    polygon_yellow = [(131, 523), (67, 597), (99, 609), (161, 530)]
    polygon_red = [(432, 282), (418, 337), (577, 338), (568, 283)]
    """
    #  polygons for pic3_smaller.jpg and pic2_smaller.jpg (hardcoded for now)
    polygon_black = [(280, 570), (220, 760), (870, 750), (810, 580)]
    polygon_white = [(900, 520), (1000, 640), (1060, 620), (970, 515)]
    polygon_yellow = [(234, 430), (190, 485), (230, 490), (270, 430)]
    polygon_red = [(285, 435), (250, 490), (830, 480), (800, 437)]


    #  polygons for pic4_smaller.jpg (hardcoded for now)
    polygon_black = [(316, 414), (215, 623), (783, 605), (673, 422)]
    polygon_white = [(710, 388), (947, 656), (1018, 620), (788, 400)]
    polygon_yellow = [(148, 474), (94, 537), (133, 542), (184, 475)]
    polygon_red = [(285, 435), (250, 490), (830, 480), (800, 437)]


    #  polygons for pic5_smaller.jpg (hardcoded for now)
    polygon_black = [(354, 418), (291, 612), (804, 590), (677, 396)]
    polygon_white = [(783, 424), (949, 602), (1002, 564), (840, 420)]
    polygon_yellow = [(344, 307), (331, 319), (354, 319), (366, 306)]
    polygon_red = [(135, 325), (119, 332), (325, 316), (332, 309)]
    """

    # create dictionary containing colors
    polygons = {
        'black': polygon_black,
        'white': polygon_white,
        'yellow': polygon_yellow,
        'red': polygon_red
    }

    # initialize estimateError class
    E = estimateError(corrected_img)
    # set polygons
    E.createPolygon(polygons)
    # estimate error
    E.GetErrorEstimation()

    # write the corrected image
    date = datetime.datetime.now().strftime("%H-%M-%S")
    path = outdir + '/' + str(date) + '_polygon.jpg'

    cv2.imwrite(path, E.out_image)
# check if dir exists, create if not
if not os.path.exists(outdir):
    os.makedirs(outdir)


# read the image
input_img = cv2.imread(file, cv2.IMREAD_UNCHANGED)

#lets do the masking!
#surf = identifyLaneSurface(input_img, use_hsv=False, grad_thresh=20)
#input_img = np.expand_dims(surf, -1) * input_img
#cv2.imshow('mask', input_img)
#cv2.waitKey(0)

# create instance of AntiInstagram
ai = AntiInstagram()

ai.calculateTransform(input_img)
print('Transform Calculation completed!')

corrected_img = ai.applyTransform(input_img)
print('Transform applied!')


# write the corrected image
date = datetime.datetime.now().strftime("%H-%M-%S")
path = outdir + '/' + str(date) + '_corrected.jpg'

cv2.imwrite(path, corrected_img)