else: qcam0_from_map = \ nps.transpose( nps.cat( interp_rectification_map0x(*nps.transpose(qrect0), grid=False), interp_rectification_map0y(*nps.transpose(qrect0), grid=False) ) ) qcam1_from_map = \ nps.transpose( nps.cat( interp_rectification_map1x(*nps.transpose(qrect1), grid=False), interp_rectification_map1y(*nps.transpose(qrect1), grid=False) ) ) testutils.confirm_equal( qcam0_from_map, qcam0, eps=1e-1, msg=f'rectification map for camera 0 points ({lensmodel})') testutils.confirm_equal( qcam1_from_map, qcam1, eps=1e-1, msg=f'rectification map for camera 1 points ({lensmodel})') # same point, so we should have the same el testutils.confirm_equal( qrect0[:,1], qrect1[:,1], msg=f'elevations of the same observed point match ({lensmodel})') disparity = qrect0[:,0] - qrect1[:,0] r = mrcal.stereo_range( disparity, models_rectified, qrect0 = qrect0, ) testutils.confirm_equal( r, nps.mag(pcam0), msg=f'stereo_range reports the right thing ({lensmodel})') testutils.finish()
for i in range(2) ] cv2.imwrite(f'/tmp/rectified0-{kind}.jpg', images_rectified[0]) cv2.imwrite(f'/tmp/rectified1-{kind}.jpg', images_rectified[1]) # Perform stereo-matching with OpenCV to produce a disparity map, which we write # to disk block_size = 5 max_disp = 400 max_disp = 16 * round(max_disp / 16) # round to nearest multiple of 16 stereo = \ cv2.StereoSGBM_create( minDisparity = 0, numDisparities = max_disp, blockSize = block_size, P1 = 8 *3*block_size*block_size, P2 = 32*3*block_size*block_size, uniquenessRatio = 5, disp12MaxDiff = 1, speckleWindowSize = 200, speckleRange = 2 ) disparity = stereo.compute(*images_rectified) cv2.imwrite(f'/tmp/disparity-{kind}.png', mrcal.apply_color_map(disparity, 0, max_disp * 16.)) if models[0] is not None and models[1] is not None: # Convert the disparity image to ranges, and write to disk r = mrcal.stereo_range( disparity.astype(np.float32) / 16., models_rectified) cv2.imwrite(f'/tmp/range-{kind}.png', mrcal.apply_color_map(r, 5, 1000))
testutils.confirm_equal(qrect0, qcam0, eps=1e-1, msg='rectification map for camera 0 points') testutils.confirm_equal(qrect1, qcam1, eps=1e-1, msg='rectification map for camera 1 points') # same point, so we should have the same el testutils.confirm_equal(el0, el1, msg='elevations of the same observed point match') r = mrcal.stereo_range(disparity * 180. / np.pi * cookie['pixels_per_deg_az'], az=az0, **cookie) testutils.confirm_equal(r, nps.mag(pcam0), msg=f'stereo_range reports the right thing') v0 = mrcal.stereo_unproject(az0, el0) testutils.confirm_equal(v0, pstereo0 / nps.dummy(nps.mag(pstereo0), -1), msg=f'stereo_unproject reports the right vector') v0, dv_dazel = mrcal.stereo_unproject(az0, el0, get_gradients=True) testutils.confirm_equal( v0, pstereo0 / nps.dummy(nps.mag(pstereo0), -1),
for i in range(2) ] cv2.imwrite(f'/tmp/rectified0-{kind}.jpg', images_rectified[0]) cv2.imwrite(f'/tmp/rectified1-{kind}.jpg', images_rectified[1]) # Perform stereo-matching with OpenCV to produce a disparity map, which we write # to disk block_size = 5 max_disp = 400 max_disp = 16 * round(max_disp / 16) # round to nearest multiple of 16 stereo = \ cv2.StereoSGBM_create( minDisparity = 0, numDisparities = max_disp, blockSize = block_size, P1 = 8 *3*block_size*block_size, P2 = 32*3*block_size*block_size, uniquenessRatio = 5, disp12MaxDiff = 1, speckleWindowSize = 200, speckleRange = 2 ) disparity = stereo.compute(*images_rectified) cv2.imwrite(f'/tmp/disparity-{kind}.png', mrcal.apply_color_map(disparity, 0, max_disp * 16.)) if models[0] is not None and models[1] is not None: # Convert the disparity image to ranges, and write to disk r = mrcal.stereo_range(disparity_pixels=disparity.astype(np.float32) / 16., **cookie) cv2.imwrite(f'/tmp/range-{kind}.png', mrcal.apply_color_map(r, 5, 1000))
scipy.interpolate.RectBivariateSpline(az_row, el_col, nps.transpose(rectification_maps[1][...,1])) qcam0_from_map = \ nps.transpose( nps.cat( interp_rectification_map0x(az0,el0, grid=False), interp_rectification_map0y(az0,el0, grid=False) ) ) qcam1_from_map = \ nps.transpose( nps.cat( interp_rectification_map1x(az1,el1, grid=False), interp_rectification_map1y(az1,el1, grid=False) ) ) testutils.confirm_equal( qcam0_from_map, qcam0, eps=1e-1, msg='rectification map for camera 0 points') testutils.confirm_equal( qcam1_from_map, qcam1, eps=1e-1, msg='rectification map for camera 1 points') # same point, so we should have the same el testutils.confirm_equal( el0, el1, msg='elevations of the same observed point match') disparity = az0 - az1 r = mrcal.stereo_range( disparity * fxycxy[0], models_rectified, az_deg = az0 * 180./np.pi ) testutils.confirm_equal( r, nps.mag(pcam0), msg=f'stereo_range reports the right thing') testutils.finish()