def calibration(calibration_data, calibration_settings, images, interactive=True): tot_deviation = 0.0 for laser in settings.get_laser_range(): selected_planes = [] ranges = [] for fn in images: num = int(fn.rsplit('/')[-1].split('_')[1].split('.')[0]) if laser == 0: if num > 80: continue else: if num < 20: continue ranges.append(num) selected_planes.append(fn) im = [calibration_settings[x] for x in selected_planes] assert len(ranges) == len(im) slices = cloudify(calibration_data, settings.CALIBDIR, [laser], ranges, method='straighttralala', camera=im, interactive=interactive, undistort=True) obj = meshify(calibration_data, slices, camera=im, cylinder=(1000, 1000)) dist, normal, std = find_laser_plane(np.array(obj.vertices)) tot_deviation += std print("\nLaser %d deviation: %.2f" % (laser + 1, std)) calibration_data.laser_planes[laser].normal = normal calibration_data.laser_planes[laser].distance = dist obj.save("laser%d.ply" % laser) tot_deviation /= 2 if tot_deviation < 0.01: txt = ("Perfect !!") elif tot_deviation < 0.05: txt = ("Excellent !") elif tot_deviation < 0.1: txt = ("Good :)") elif tot_deviation < 0.3: txt = ("Expect shift between lasers :(") else: txt = ("Consider recalibrating, result is very bad") print("\nDeviation is %.2f. %s" % (tot_deviation, txt))
def recognize(): " Compute mesh from images (pure mode aware)" view_stop() calibration_data = settings.load_data(CalibrationData()) r = settings.get_laser_range() slices, colors = cloudify(calibration_data, settings.WORKDIR, r, range(360), method=settings.SEGMENTATION_METHOD) meshify(calibration_data, slices, colors=colors, cylinder=settings.ROI).save("model.ply") gui.clear()
def scan_object(): """ Scan object """ calibration_data = settings.load_data(CalibrationData()) r = settings.get_laser_range() cloudifier = iter_cloudify(calibration_data, settings.WORKDIR, r, range(360), method=settings.SEGMENTATION_METHOD) iterator = partial(next, cloudifier) capture(on_step=iterator, display=False, ftw=settings.SYNC_FRAME_FAST) slices, colors = iterator() meshify(calibration_data, slices, colors=colors).save("model.ply") gui.clear()
def __init__(self): self.width = 0 self.height = 0 self._camera_matrix = None self._distortion_vector = None self._roi = None self._dist_camera_matrix = None self._weight_matrix = None self._md5_hash = None self.laser_planes = [ settings.Attribute() for _ in settings.get_laser_range() ] self.platform_rotation = None self.platform_translation = None
def lasers_on(self): for i in settings.get_laser_range(): self.laser_on(i)