-
Notifications
You must be signed in to change notification settings - Fork 0
/
objNode.py
44 lines (38 loc) · 1.36 KB
/
objNode.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
#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import String
from object.detector import Detector
import sys
try:
sys.path.remove('/opt/ros/kinetic/lib/python2.7/dist-packages')
except ValueError:
pass
import cv2
class RosObjDetector(object):
def __init__(self, save_path):
self.detector = Detector(save_path=save_path)
self.pub = rospy.Publisher('Main_Sub', String, queue_size=10)
rospy.init_node('Obj_py', anonymous=False)
def callback(self, data):
# print("Here is callback")
if data.data == "Object_detect":
cam_id = 'http://192.168.3.66:4747/video'
detected_frame = self.detector.detect_cam(cam_id)
cv2.imshow("Camera", detected_frame)
cv2.waitKey(3000)
cv2.destroyWindow('Camera')
if not rospy.is_shutdown():
done_msg = "Object_detected"
rospy.loginfo(done_msg)
self.pub.publish(done_msg)
def listen(self):
# rospy.init_node('listener', anonymous=True)
print("waiting for object detect message")
rospy.Subscriber("Main_Pub", String, self.callback)
# print('After sub')
rospy.spin()
if __name__ == '__main__':
objDetector = RosObjDetector(save_path='objectFound')
objDetector.listen()
# print('After listen')