def test_load_calib_imgs_paths(): """ Test load_calib_imgs path creation/checking. All `calib_imgs_paths` tests are basically the same """ global p, o if not os_exists(testdir+'/raw'): raise RuntimeError('test \'raw\' directory could not be found') # Setup calib = CalibratePSEye() calib.init_chessboard(p, o) try: calib.load_calib_imgs(testdir+'/raw') # Make sure everything was created properly for p in ('/raw', '/corners'): if not isdir(calib.calibpath + p): raise RuntimeError('path \'%s\' wasn\'t created') # Make sure raw images were copied correctly for fn in listdir(testdir + '/raw'): f1 = calib.calibpath + '/raw/' + fn f2 = testdir + '/raw/' + fn g1 = cv_imread(f1) i2 = cv_imread(f2) g2 = cvtColor(cvtColor(i2, COLOR_RGB2GRAY), COLOR_GRAY2RGB) if not array_equal(g1, g2): raise RuntimeError('frame \'%s\' did not match' % fn) debug('\'%s\' matched' % fn) finally: calib.removepath()
def test_load_calib_imgs_asserts(): """ Test load_calibs_imgs asserts. Assert testing Tests elements that are supposed to pass b/c as long as `init_chessboard` hasn't been called, a Runtime (not Assertion) error will be raised. """ calib = CalibratePSEye() # do NOT init_chessboard yet for t in (int, float, complex, list, tuple, range, dict, set, frozenset, bool, bytes, bytearray, memoryview): try: calib.load_calib_imgs(t) except TypeError: debug('\'%s\' calibrations' % t.__name__) else: raise RuntimeError('Failed to catch %s calibrations' % t.__name__) try: calib.load_calib_imgs('asdf', 1.5) except TypeError: pass else: raise RuntimeError('Failed to catch bad clean param') # check for elements that do pass # this works b/c it fails another test w/RuntimeError (not Assertion) # in the next line for elem in (True, False, 0, 1): try: calib.load_calib_imgs('asdf', elem) except RuntimeError: pass else: raise RuntimeError('Failed to catch bad img_path')
def test_compute_calibrations(): """ Test computation to the 4th decimal place on known calibration data. """ # Test Asserts calib = CalibratePSEye() calib.corners_arr = [1, 2] calib.objpoints = [1, 2] calib.w = 320 calib.h = 240 calib.corners_arr = [] try: calib.compute_calibrations() except RuntimeError: pass else: raise RuntimeError('Failed to catch len(corners_arr)==0') calib.corners_arr = [1, 2] calib.objpoints = [] try: calib.compute_calibrations() except RuntimeError: pass else: raise RuntimeError('Failed to catch len(objpoints)==0') calib.objpoints = [1, 2] calib.w = None try: calib.compute_calibrations() except RuntimeError: pass else: raise RuntimeError('Failed to catch _w is None') calib.h = None calib.w = 320 try: calib.compute_calibrations() except RuntimeError: pass else: raise RuntimeError('Failed to catch h is None') # Test Math global cpdict imgpath = testdir + '/raw' if not os_exists(imgpath): raise RuntimeError('Could not find imgpath') calib = CalibratePSEye() calib.init_chessboard(p, o) calib.load_calib_imgs(imgpath) try: calib.compute_calibrations() calib.save_calibrations() for k in cpdict.keys(): k1 = cpdict[k] # already rounded b/c loaded from file k2 = around(getattr(calib, k), decimals=4) if not array_equal(k1, k2): raise RuntimeError('\'%s\' did not match' % k) debug('\'%s\' matched' % k) # print(getattr(calib, k)) finally: calib.removepath()