-
Notifications
You must be signed in to change notification settings - Fork 4
/
uav_camera.py
44 lines (30 loc) · 1014 Bytes
/
uav_camera.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
# Tutorial link: https://dhanuzch.medium.com/using-opencv-with-gazebo-in-robot-operating-system-ros-part-1-display-real-time-video-feed-a98c078c708b
import rospy
import cv2
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
class camera_1:
def __init__(self):
self.image_sub = rospy.Subscriber("/uav1/camera1/image_raw", Image, self.callback)
def callback(self,data):
bridge = CvBridge()
try:
cv_image = bridge.imgmsg_to_cv2(data, desired_encoding="bgr8")
except CvBridgeError as e:
rospy.logerr(e)
image = cv_image
resized_image = cv2.resize(image, (640, 640))
#cv2.imshow("Camera output normal", image)
cv2.imshow("Camera output resized", resized_image)
cv2.waitKey(3)
def main():
camera_1()
try:
rospy.spin()
except KeyboardInterrupt:
rospy.loginfo("Shutting down")
cv2.destroyAllWindows()
if __name__ == '__main__':
rospy.init_node('camera_read', anonymous=False)
main()