use opencv for image taking and writing
This commit is contained in:
@@ -3,24 +3,27 @@ from rclpy.node import Node
|
||||
|
||||
from drone_services.srv import TakePicture
|
||||
|
||||
from picamera2 import Picamera2
|
||||
from cv2 import *
|
||||
|
||||
|
||||
class CameraController(Node):
|
||||
def __init__(self):
|
||||
super().__init__('camera_controller')
|
||||
self.picam2 = Picamera2()
|
||||
self.cam = VideoCapture(0)
|
||||
|
||||
self.srv = self.create_service(TakePicture, 'drone/picture', self.take_picture_callback)
|
||||
|
||||
def take_picture_callback(self, request, response):
|
||||
if (request.input_name == "default"):
|
||||
self.get_logger().info("Taking picture with default filename")
|
||||
self.picam2.start_and_capture_file("/home/ubuntu/image.jpg")
|
||||
response.filename = "/home/ubuntu/image.jpg"
|
||||
else:
|
||||
self.picam2.start_and_capture_file(request.input_name)
|
||||
response.filename = request.input_name
|
||||
return response
|
||||
result, image = self.cam.read()
|
||||
if (result):
|
||||
if (request.input_name == "default"):
|
||||
self.get_logger().info("Taking picture with default filename")
|
||||
imwrite("/home/ubuntu/image.jpg", image)
|
||||
response.filename = "/home/ubuntu/image.jpg"
|
||||
else:
|
||||
imwrite(request.input_name, image)
|
||||
response.filename = request.input_name
|
||||
return response
|
||||
|
||||
def main(args=None):
|
||||
rclpy.init(args=args)
|
||||
|
||||
Reference in New Issue
Block a user