Example #1
0
 def test_find_aerocube_markers_none(self):
     # get hard-coded results
     aerocube_markers = []
     # get ImP results
     imp = ImageProcessor(self.TEST_NO_MARKER.img_path)
     test_markers = imp._find_aerocube_markers()
     self.assertTrue(np.array_equal(aerocube_markers, test_markers))
Example #2
0
 def scan_image(self, img_event):
     """
     Handler for ImageEventSignal.IDENTIFY_AEROCUBES.
     :param img_event:
     :return:
     """
     # Initialize variables
     file_path = img_event.payload.strings(ImageEvent.FILE_PATH)
     try:
         logger.debug(
             self.__class__.__name__,
             func_name='scan_image',
             msg='Instantiating ImP at {}'.format(file_path),
             id=img_event.payload.strings(job_id_bundle_key))
         imp = ImageProcessor(file_path)
         logger.debug(
             self.__class__.__name__,
             func_name='scan_image',
             msg='Finding fiducial markers',
             id=img_event.payload.strings(job_id_bundle_key))
         aerocubes_as_json, markers_as_json = imp.identify_markers_for_storage()
         logger.success(
             self.__class__.__name__,
             func_name='scan_image',
             msg='Done with Scan!',
             id=img_event.payload.strings(job_id_bundle_key))
         # Set result signal to OK
         result_signal = ResultEventSignal.OK
         # Prepare bundle from original
         result_bundle = img_event.payload
         result_bundle.insert_string(ImageEvent.SCAN_ID, str(img_event.created_at).split('.')[0])
         result_bundle.insert_raw(AeroCube.STR_KEY_CUBE_IDS, aerocubes_as_json[AeroCube.STR_KEY_CUBE_IDS])
         result_bundle.insert_raw(AeroCube.STR_KEY_QUATERNIONS, aerocubes_as_json[AeroCube.STR_KEY_QUATERNIONS])
         result_bundle.insert_raw(AeroCube.STR_KEY_TVECS, aerocubes_as_json[AeroCube.STR_KEY_TVECS])
         result_bundle.insert_raw(AeroCube.STR_KEY_DISTANCES, aerocubes_as_json[AeroCube.STR_KEY_DISTANCES])
         result_bundle.insert_raw(AeroCube.STR_KEY_MARKERS_DETECTED, aerocubes_as_json[AeroCube.STR_KEY_MARKERS_DETECTED])
         result_bundle.insert_raw(ImageEvent.SCAN_MARKERS, markers_as_json)
         store_image("ImP/output_files/" + os.path.split(file_path)[-1], imp.draw_aerocubes())
         logger.success(
             self.__class__.__name__,
             func_name='scan_image',
             msg='Controller.scan_image: Done with setting bundle : {}'.format(str(result_bundle)),
             id=img_event.payload.strings(job_id_bundle_key))
         
     except Exception as ex:
         logger.err(
             self.__class__.__name__,
             func_name='scan_image',
             msg='ImP Failed',
             id=img_event.payload.strings(job_id_bundle_key))
         template = "An exception of type {0} occured. Arguments:\n{1!r}"
         message = template.format(type(ex).__name__, ex.args)
         logger.err(
             self.__class__.__name__,
             func_name='scan_image',
             msg=message,
             id=img_event.payload.strings(job_id_bundle_key))
         result_signal = ResultEventSignal.ERROR
         result_bundle = img_event.payload
     return result_signal, result_bundle
Example #3
0
 def test_find_distance(self):
     imp = ImageProcessor(self.TEST_JETSON_SINGLE_MARKER.img_path)
     corners, ids = imp._find_fiducial_markers()
     dist = imp._find_distance(corners)
     print(dist)
     self.assertGreater(dist[0], 0.8)
     self.assertLess(dist[0], 1.0)
Example #4
0
 def test_find_fiducial_marker_none(self):
     imp = ImageProcessor(self.TEST_NO_MARKER.img_path)
     corners, ids = imp._simplify_fiducial_arrays(
         self.TEST_NO_MARKER.corners, self.TEST_NO_MARKER.IDs)
     test_corners, test_ids = imp._find_fiducial_markers()
     np.testing.assert_allclose(corners, test_corners)
     np.testing.assert_array_equal(ids, test_ids)
Example #5
0
 def test_identify_aerocubes(self):
     aerocube_ID = 0
     aerocube_face = AeroCubeFace.ZENITH
     corners, _ = ImageProcessor._simplify_fiducial_arrays(
         self.TEST_SINGLE_MARKER.corners, [[aerocube_ID]])
     marker_list = [AeroCubeMarker(aerocube_ID, aerocube_face, corners[0])]
     aerocube_list = [AeroCube(marker_list)]
     imp = ImageProcessor(self.TEST_SINGLE_MARKER.img_path)
     self.assertEqual(imp._identify_aerocubes(), aerocube_list)
Example #6
0
 def test_find_fiducial_marker_multiple(self):
     # get results from ImP
     imp = ImageProcessor(self.TEST_MULT_AEROCUBES.img_path)
     corners, ids = imp._simplify_fiducial_arrays(
         self.TEST_MULT_AEROCUBES.corners, self.TEST_MULT_AEROCUBES.IDs)
     test_corners, test_ids = imp._find_fiducial_markers()
     # assert hard-coded results equal ImP results
     np.testing.assert_allclose(corners, test_corners)
     np.testing.assert_array_equal(ids, test_ids)
Example #7
0
 def test_rodrigues_to_quaternion(self):
     imp = ImageProcessor(self.TEST_JETSON_SINGLE_MARKER.img_path)
     rvecs, _ = imp._find_pose(imp._find_fiducial_markers()[0])
     # test value
     test_quat = imp.rodrigues_to_quaternion(rvecs[0])
     # true value
     true_quat = pyquaternion.Quaternion(w=-0.060,
                                         x=0.746,
                                         y=-0.648,
                                         z=-0.140)
     # assert that the str representations are equal (components identical up to 3 decimal places)
     self.assertEqual(str(test_quat), str(true_quat))
Example #8
0
 def test_identify_markers_for_storage(self):
     # TODO: needs to be rewritten for new method
     self.fail()
     # get hard-coded results
     corners, _ = ImageProcessor._simplify_fiducial_arrays(
         self.TEST_SINGLE_MARKER.corners, [[0]])
     marker_list = [AeroCubeMarker(0, AeroCubeFace.ZENITH, corners[0])]
     aerocube_list = [AeroCube(marker_list)]
     # get ImP results
     imp = ImageProcessor(self.TEST_SINGLE_MARKER.img_path)
     scan_results = imp.identify_markers_for_storage()
     # assert equality
     np.testing.assert_array_equal(aerocube_list, scan_results)
Example #9
0
 def test_find_fiducial_marker(self):
     # hard code results of operation
     corners, ids = ImageProcessor._simplify_fiducial_arrays(
         self.TEST_SINGLE_MARKER.corners, self.TEST_SINGLE_MARKER.IDs)
     # get results of function
     imp = ImageProcessor(self.TEST_SINGLE_MARKER.img_path)
     test_corners, test_ids = imp._find_fiducial_markers()
     # assert hard-coded results equal results of function
     self.assertTrue(np.array_equal(corners, test_corners))
     self.assertTrue(np.array_equal(ids, test_ids))
     self.assertEqual(type(test_ids).__module__, np.__name__)
     # save output image for visual confirmation
     output_img = imp.draw_fiducial_markers(test_corners, test_ids)
     cv2.imwrite(self.test_output_path, output_img)
Example #10
0
 def test_detect_markers_parallel_on_capstone_photos(self):
     img_paths = [
         os.path.join(self._CAPSTONE_PHOTO_DIR, f)
         for f in os.listdir(self._CAPSTONE_PHOTO_DIR)
         if os.path.isfile(os.path.join(self._CAPSTONE_PHOTO_DIR, f))
     ]
     for img_path in img_paths:
         imp = ImageProcessor(img_path)
         actual_corners, actual_ids = MarkerDetectPar.detect_markers_parallel(
             imp._img_mat)
         expected_corners, expected_ids = imp._find_fiducial_markers(
             parallel=False)
         np.testing.assert_allclose(actual_corners, expected_corners)
         np.testing.assert_array_equal(actual_ids, expected_ids)
         print("PASSED: {}".format(img_path))
Example #11
0
 def test_identify_aerocubes_multiple(self):
     # get hard-coded results
     corners, _ = ImageProcessor._simplify_fiducial_arrays(
         self.TEST_MULT_AEROCUBES.corners, [[2], [0]])
     aerocube_2_markers = [
         AeroCubeMarker(2, AeroCubeFace.ZENITH, corners[0])
     ]
     aerocube_0_markers = [AeroCubeMarker(0, AeroCubeFace.BACK, corners[1])]
     aerocubes = [
         AeroCube(aerocube_2_markers),
         AeroCube(aerocube_0_markers)
     ]
     # get ImP results
     imp = ImageProcessor(self.TEST_MULT_AEROCUBES.img_path)
     test_aerocubes = imp._identify_aerocubes()
     # assert equality
     self.assertTrue(np.array_equal(aerocubes, test_aerocubes))
Example #12
0
 def test_rodrigues_to_quaternion_has_identical_rotation(self):
     """
     Confirms the following case:
     http://stackoverflow.com/questions/12933284/rodrigues-into-eulerangles-and-vice-versa
     """
     imp = ImageProcessor(self.TEST_JETSON_SINGLE_MARKER.img_path)
     rvecs, _ = imp._find_pose(imp._find_fiducial_markers()[0])
     test_quat = imp.rodrigues_to_quaternion(rvecs[0])
     # get rotation matrices
     rot_mat_orig = cv2.Rodrigues(rvecs[0])[0]
     rot_mat_quat = test_quat.rotation_matrix
     rot_mat = cv2.multiply(rot_mat_orig, cv2.transpose(rot_mat_quat))
     # test not working for some reason; just test equality of rotation matrices
     # self.assertTrue(np.allclose(rot_mat,
     #                             np.identity(3),
     #                             rtol=1e-02))
     self.assertTrue(np.allclose(rot_mat_orig, rot_mat_quat, rtol=1e-02))
Example #13
0
    def test_time_serial_vs_par(self):
        img_path = os.path.join(self._CAPSTONE_PHOTO_PATH, 'AC_0_1_FRONT_TOP.JPG')

        imp = ImageProcessor(img_path)
        pr = cProfile.Profile()
        pr.enable()
        actual_corners, actual_ids = imp._find_fiducial_markers()
        pr.disable()
        s = io.StringIO()
        ps = pstats.Stats(pr, stream=s).sort_stats('cumulative')
        ps.print_stats()
        print(s.getvalue())

        pr = cProfile.Profile()
        pr.enable()
        test_corners, test_ids = imp._find_fiducial_markers(gpu=True)
        pr.disable()
        s = io.StringIO()
        ps = pstats.Stats(pr, stream=s).sort_stats('cumulative')
        ps.print_stats()
        print(s.getvalue())

        np.testing.assert_allclose(actual_corners, test_corners)
        np.testing.assert_array_equal(actual_ids, test_ids)
from ImP.imageProcessing.imageProcessingInterface import ImageProcessor

# this file can be called from the python3 shell as such:
# exec(open("ImP/startImP.py").read())

img_path = "ImP/imageProcessing/test_files/2_ZENITH_0_BACK.jpg"
imp = ImageProcessor(img_path)
rvecs, tvecs = imp._find_pose()
Example #15
0
 def test_draw_fiducial_markers(self):
     imp = ImageProcessor(self.TEST_SINGLE_MARKER.img_path)
     corners, IDs = imp._find_fiducial_markers()
     img = imp.draw_fiducial_markers(corners, IDs)
     self.assertEqual(img.shape, imp._img_mat.shape)
Example #16
0
 def test_find_aerocube_marker(self):
     imp = ImageProcessor(self.AC_0_FACES_125_PATH)
     aerocube_markers = imp._find_aerocube_markers()
     [self.assertIsInstance(m, AeroCubeMarker) for m in aerocube_markers]
Example #17
0
 def test_identify_aerocubes_none(self):
     imp = ImageProcessor(self.TEST_NO_MARKER.img_path)
     self.assertEqual([], imp._identify_aerocubes())
Example #18
0
 def test_positive_load_image(self):
     imp = ImageProcessor(self.TEST_SINGLE_MARKER.img_path)
     self.assertIsNotNone(
         ImageProcessor._load_image(self.TEST_SINGLE_MARKER.img_path))
Example #19
0
 def test_init(self):
     imp = ImageProcessor(self.TEST_SINGLE_MARKER.img_path)
     self.assertIsNotNone(imp._img_mat)
Example #20
0
 def test_draw_axis(self):
     imp = ImageProcessor(self.TEST_JETSON_SINGLE_MARKER.img_path)
     rvecs, tvecs = imp._find_pose(imp._find_fiducial_markers()[0])
     img = imp.draw_axis(imp.rodrigues_to_quaternion(rvecs[0]), tvecs[0])
     self.assertIsNotNone(img)