forked from chicagoedt/revo_robot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgabor.py
executable file
·75 lines (59 loc) · 2.13 KB
/
gabor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
import sys
import cv2
import rospy
import math
from dynamic_reconfigure.server import Server
from lane_detection import LaneDetection
from line_detection.cfg import LineDetectionConfig
###############################################################################
# Chicago Engineering Design Team
# Gabor filter using Python OpenCV for autonomous robot Scipio
# (IGVC competition).
#
# This node runs the Gabor filter on input images and publishes them.
#
# @author Basheer Subei
# @email [email protected]
class Gabor(LaneDetection):
roi_top_left_x = 0
roi_top_left_y = 0
roi_width = 2000
roi_height = 2000
gabor_ksize = 4
gabor_sigma = 7
gabor_theta = 0
gabor_lambda = 27
gabor_gamma = 4.0
def __init__(self, namespace, node_name):
LaneDetection.__init__(self, namespace, node_name)
# this is what gets called when an image is received
def image_callback(self, ros_image):
cv2_image = self.ros_to_cv2_image(ros_image)
roi = self.get_roi(cv2_image)
mono = self.convert_to_mono(roi)
# apply Gabor filter
gabor_kernel = cv2.getGaborKernel((self.gabor_ksize, self.gabor_ksize),
self.gabor_sigma,
self.gabor_theta * math.pi / 180,
self.gabor_lambda,
self.gabor_gamma)
final_image = cv2.filter2D(mono, -1, gabor_kernel)
final_image_message = LaneDetection.cv2_to_ros_message(
self, final_image
)
# publishes final image message in ROS format
self.line_image_pub.publish(final_image_message)
# end image_callback()
def main(args):
node_name = "gabor"
namespace = rospy.get_namespace()
# create a gabor object
g = Gabor(namespace, node_name)
# start the line_detector node and start listening
rospy.init_node("gabor", anonymous=True)
# starts dynamic_reconfigure server
srv = Server(LineDetectionConfig, g.reconfigure_callback)
rospy.spin()
if __name__ == '__main__':
main(sys.argv)