def test_record_calib_imgs_member_data(): """ Test member data assignment inside of `record_calib_imgs` `record_calib_imgs` is called with a negative countdown to force immediate chessboard logging. The test calibration images provided should all have valid chessboards for the provided params. """ # Setup h, w, _ = cv_imread(testdir+'/raw/f00001.jpg').shape nf = len([ f for f in listdir(testdir+'/raw') if f[-4:].lower() == '.jpg' ]) # Tests calib = CalibratePSEye() calib.init_chessboard(p, o) try: calib.record_calib_imgs( cam=testdir+'/raw/f%05d.jpg', nframes=nf, countdown=-1 ) if calib.w != w: raise RuntimeError('\'w\' wasn\'t set properly') if calib.h != h: raise RuntimeError('\'h\' wasn\'t set properly') if calib.img_arr.shape != (h,w,1,nf): raise RuntimeError('\'img_arr.shape\' wasn\'t set properly') if calib.img_arr.dtype != uint8: raise RuntimeError('\'img_arr.dtype\' wasn\'t set properly') finally: calib.removepath()
def test_record_calib_imgs_paths(): """ Test record_calib_imgs path creation/checking. `record_calib_imgs` is called with a negative countdown to force immediate chessboard logging. The test calibration images provided should all have valid chessboards for the provided params. """ global p, o nf = len([ f for f in listdir(testdir+'/raw') if f[-4:].lower() == '.jpg' ]) calib = CalibratePSEye() calib.init_chessboard(p, o) try: calib.record_calib_imgs( cam=testdir+'/raw/f%05d.jpg', nframes=nf, countdown=-1 ) # Make sure everything was created properly for p in ('/raw', '/corners'): if not isdir(calib.calibpath + p): raise RuntimeError('\'%s\' wasn\'t created') # Make sure raw images were handled correctly # never actually checks for frame equality - keep running into # jpgs quality loss issues that honestly weren't worth the time # I spent trying to fix them fns1 = sorted(listdir(testdir + '/raw')) fns2 = sorted(listdir(calib.calibpath + '/raw')) if len(fns1) != len(fns2): raise RuntimeError('Failed to save all valid calibration images') finally: calib.removepath()
def test_record_calib_imgs_asserts(): """ Test record_calibs_imgs asserts. Basically just for initialization """ calib = CalibratePSEye() # calib.calibpath is None try: calib.record_calib_imgs() except RuntimeError: pass else: raise RuntimeError('Failed to catch absence of _calib_path') # calib.img_arr is not None calib.img_arr = (1,2,3,4) try: calib.record_calib_imgs() except RuntimeError: pass else: raise RuntimeError('Failed to catch not-None img_arr') calib.clear() for t in (str, float, complex, list, tuple, range, dict, set, frozenset, bool, bytes, bytearray, memoryview): try: calib.record_calib_imgs(nframes=t, countdown=15) except TypeError: pass else: raise RuntimeError('Failed to catch %s nframes' % t.__name__) calib.clear() for t in (str, float, complex, list, tuple, range, dict, set, frozenset, bool, bytes, bytearray, memoryview): try: calib.record_calib_imgs(nframes=15, countdown=t) except TypeError: pass else: raise RuntimeError('Failed to catch %s countdown' % t.__name__)