Beispiel #1
0
    def show_image(self, image, robots_coordinates):
        image_panel = self.parent.image_panel

        CV.draw_robots(robots_coordinates, image)
        CV.convert_to_RGB(image)

        bitmap = wx.BitmapFromBuffer(image.width, image.height, image.tostring())
        image_panel.webcam_image.SetBitmap(bitmap)
        image_panel.Refresh()
Beispiel #2
0
    def get_robots_coordinates(self, image):
        '''Gets the robots position and rotation list.'''

        image_channels = CV.split_into_channels(image)

        left_points = CV.find_color_blobs(self.left_color, image_channels)
        right_points = CV.find_color_blobs(self.right_color, image_channels)
        pairs = self.combine_points(left_points, right_points)

        return self.calculate_coordinates(pairs)
Beispiel #3
0
    def detect_robots(self, event):
        image = CV.grab_frame(self.parent.capture)
        coordinates = self.parent.detector.get_robots_coordinates(image)

        self.show_image(image, coordinates)
        self.send_message(coordinates)
        self.log(coordinates)
    def setUp(self):
        self.num_timestamps = 10
        self.fov = math.pi / 2
        self.image_width = 1000
        self.object_universe = ObjectUniverse(
            num_timestamps=self.num_timestamps)
        self.camera = Camera()

        self.camera.set_actual_position((1,1)).\
                    set_fov_rad(self.fov).\
                    set_num_timestamps(self.num_timestamps).\
                    set_range(50000)

        for timestamp in range(self.camera.get_num_timestamps()):
            self.camera.set_state_of_pan_motor_angle_at_timestamp_rad(
                math.pi / 4, timestamp)

        self.cv = ComputerVision()
        self.image_generator = ImageGenerator(image_width=self.image_width)
        self.camera.set_computer_vision(self.cv).\
                    set_image_generator(self.image_generator)

        self.viewable_objects = [
            StationaryObject((2, 1 + math.tan(math.pi / 8))),
            StationaryObject((1 + math.tan(math.pi / 8), 2)),
            StationaryObject((10000, 1.1)),
            StationaryObject((1.1, 10000)),
        ]
        self.object_universe.add_viewable_objects(self.viewable_objects)
        self.object_universe.add_camera(self.camera)

        self.d = self.image_width / (2 * math.tan(self.fov / 2))
        self.theta = math.pi / 8
    def setUp(self):
        self.num_timestamps = 6
        self.object_universe = ObjectUniverse(num_timestamps=self.num_timestamps)
        self.camera = Camera(fov_deg=90, actual_position=(0,0))
        self.cv = ComputerVision()
        self.camera.set_computer_vision(self.cv)
        self.object_universe.add_camera(self.camera)

        for timestamp, _ in enumerate(self.camera.get_state_history()):
            self.camera.set_pan_angle_deg(0, timestamp)

        self.out_pos = (1,2)
        self.in_pos = (1,0)

        self.out_obj = ViewableObject()
        self.in_obj = ViewableObject()
        self.in_out_in_obj = ViewableObject()
        self.out_in_out_obj = ViewableObject()

        self.viewable_objects = [
            self.out_obj,
            self.in_obj,
            self.in_out_in_obj,
            self.out_in_out_obj,
        ]

        self.object_universe.add_viewable_objects(self.viewable_objects)

        for timestamp, _ in enumerate(self.out_obj.position_history):
            self.in_obj.set_position_at_timestamp(self.in_pos, timestamp)
            self.out_obj.set_position_at_timestamp(self.out_pos, timestamp)

        for timestamp in [0,1]:
            self.in_out_in_obj.set_position_at_timestamp(self.in_pos, timestamp)
            self.out_in_out_obj.set_position_at_timestamp(self.out_pos, timestamp)

        for timestamp in [2,3]:
            self.in_out_in_obj.set_position_at_timestamp(self.out_pos, timestamp)
            self.out_in_out_obj.set_position_at_timestamp(self.in_pos, timestamp)

        for timestamp in [4,5]:
            self.in_out_in_obj.set_position_at_timestamp(self.in_pos, timestamp)
            self.out_in_out_obj.set_position_at_timestamp(self.out_pos, timestamp)

        self.cv.set_cv_ids_for_all_camera_time()
Beispiel #6
0
class Demo:
    def __init__(self):

        # Setup physical environment
        self.num_timestamps = 100

        self.camera = Camera()
        self.camera.set_actual_position((100,300)).\
                    set_gps_position((100,290)).\
                    set_gps_max_error(10).\
                    set_fov_deg(70)
        for timestamp in range(self.num_timestamps):
            self.camera.set_pan_angle_deg(0, timestamp)

        self.cv = ComputerVision()
        self.camera.set_computer_vision(self.cv)

        self.boundary = Boundary([(150, 100), (150, 550), (300, 550),
                                  (300, 100)])

        self.viewable_objects = []
        for _ in range(20):
            self.viewable_objects.append(
                RandomlyMovingObject(boundary=self.boundary))

        self.object_universe = ObjectUniverse(
            num_timestamps=self.num_timestamps)
        self.object_universe.add_camera(self.camera).\
                             add_viewable_objects(self.viewable_objects)

        self.cv.set_cv_ids_for_all_camera_time()

        # Rendering
        renderable_objects = [
            self.boundary,
            self.object_universe,
        ]

        RenderOrchestrator(self.num_timestamps,
                           seconds_per_timestamp=0.2,
                           renderable_objects=renderable_objects).run()
Beispiel #7
0
 def add_computer_vision_if_none(self):
     if self.computer_vision is None:
         self.set_computer_vision(ComputerVision())
     return self
Beispiel #8
0
 def update_capture(self, event=None):
     camera_index = self.webcam_panel.spn_camera_index.GetValue()
     self.capture = CV.get_capture(camera_index)
class TestComputerVision(unittest.TestCase):

    def setUp(self):
        self.num_timestamps = 6
        self.object_universe = ObjectUniverse(num_timestamps=self.num_timestamps)
        self.camera = Camera(fov_deg=90, actual_position=(0,0))
        self.cv = ComputerVision()
        self.camera.set_computer_vision(self.cv)
        self.object_universe.add_camera(self.camera)

        for timestamp, _ in enumerate(self.camera.get_state_history()):
            self.camera.set_pan_angle_deg(0, timestamp)

        self.out_pos = (1,2)
        self.in_pos = (1,0)

        self.out_obj = ViewableObject()
        self.in_obj = ViewableObject()
        self.in_out_in_obj = ViewableObject()
        self.out_in_out_obj = ViewableObject()

        self.viewable_objects = [
            self.out_obj,
            self.in_obj,
            self.in_out_in_obj,
            self.out_in_out_obj,
        ]

        self.object_universe.add_viewable_objects(self.viewable_objects)

        for timestamp, _ in enumerate(self.out_obj.position_history):
            self.in_obj.set_position_at_timestamp(self.in_pos, timestamp)
            self.out_obj.set_position_at_timestamp(self.out_pos, timestamp)

        for timestamp in [0,1]:
            self.in_out_in_obj.set_position_at_timestamp(self.in_pos, timestamp)
            self.out_in_out_obj.set_position_at_timestamp(self.out_pos, timestamp)

        for timestamp in [2,3]:
            self.in_out_in_obj.set_position_at_timestamp(self.out_pos, timestamp)
            self.out_in_out_obj.set_position_at_timestamp(self.in_pos, timestamp)

        for timestamp in [4,5]:
            self.in_out_in_obj.set_position_at_timestamp(self.in_pos, timestamp)
            self.out_in_out_obj.set_position_at_timestamp(self.out_pos, timestamp)

        self.cv.set_cv_ids_for_all_camera_time()

    def test_camera_has_correct_number_of_timestamps(self):
        self.assertEqual(self.camera.get_num_timestamps(), self.num_timestamps)
        self.assertEqual(self.camera.get_state_history_len(), self.num_timestamps)

    def test_viewable_objects_have_correct_number_of_timestamps(self):
        for vo in self.viewable_objects:
            self.assertEqual(vo.get_position_history_len(), self.num_timestamps)
            self.assertEqual(vo.get_num_timestamps(), self.num_timestamps)

    def test_objects_that_never_are_in_view_never_get_id(self):
        for timestamp, _ in enumerate(self.out_obj.get_position_history()):
            self.assertIsNone(self.cv.get_cv_id_for_obj_at_timestamp(self.out_obj, timestamp))

    def test_it_ids_objects_that_come_into_view(self):
        for timestamp in [0,1]:
            self.assertIsNone(self.cv.get_cv_id_for_obj_at_timestamp(self.out_in_out_obj, timestamp))
            self.assertIsNotNone(self.cv.get_cv_id_for_obj_at_timestamp(self.in_out_in_obj, timestamp))

        self.assertEqual(self.cv.get_cv_id_for_obj_at_timestamp(self.in_out_in_obj, 0),
                         self.cv.get_cv_id_for_obj_at_timestamp(self.in_out_in_obj, 1))

    def that_it_prefixes_the_ids_with_cv(self):
        self.assertEqual(self.cv.get_cv_id_for_obj_at_timestamp(self.in_obj,0)[0:2], 'cv')

    def test_it_retains_ids_of_objects_that_remain_in_view(self):
        self.assertEqual(self.cv.get_cv_id_for_obj_at_timestamp(self.out_in_out_obj, 2),
                         self.cv.get_cv_id_for_obj_at_timestamp(self.out_in_out_obj, 3))


    def test_it_removes_ids_of_objects_that_leave_view(self):
        self.assertIsNone(self.cv.get_cv_id_for_obj_at_timestamp(self.out_in_out_obj, 4))
        self.assertIsNone(self.cv.get_cv_id_for_obj_at_timestamp(self.out_in_out_obj, 5))

    def test_it_re_ids_objects_that_come_back_in_view(self):
        in_first = self.cv.get_cv_id_for_obj_at_timestamp(self.in_out_in_obj, 1)
        in_again = self.cv.get_cv_id_for_obj_at_timestamp(self.in_out_in_obj, 4)
        self.assertIsNotNone(in_first)
        self.assertIsNotNone(in_again)
        self.assertNotEqual(in_first, in_again)
Beispiel #10
0
import cv2
import serial
import time
from computer_vision import ComputerVision


SER = serial.Serial("/dev/cu.usbmodem14301",9600)
# COMP_VIS = ComputerVision(src='images/weed_demo.mov')
# COMP_VIS = ComputerVision('images/weed_demo.mov')
COMP_VIS = ComputerVision(0)

while cv2.waitKey(1) != ord('q'):
    # time.sleep(0.25)
    cv2.imshow("Frame", COMP_VIS.frame)
    # print(COMP_VIS.find_line())
    # SER.write(COMP_VIS.find_line().encode())
    SER.write(str(COMP_VIS.find_weed()).encode())
    # time.sleep(.01)


COMP_VIS.cleanup()