示例#1
0
def sensor_calibration():
    """
    Method for getting and setting the sensor cal file.
    """
    success = True
    message = ""
    if request.method == "POST":
        cal_file = request.json
        try:
            sensor_cal = json.loads(cal_file,
                                    JSONDecoder=decode_sensor_settings)
            sensor_cal.write_file(SENSOR_CAL_FILE)
        except:
            success = False
            message = "Failed to parse passed sensor calibration."
        return jsonify({"success": success, "message": message})
    else:
        try:
            sensor_cal = Undistort.read_json_file(SENSOR_CAL_FILE)
        except:
            sensor_cal = None
            success = False
            message = "Failed to load sensor xml file."
        return jsonify({
            "sensor_cal_file": sensor_cal,
            "success": success,
            "message": message
        })
示例#2
0
def test_file_saving_loading():
    """
    Test the file saving and loading.
    """
    undistort = Undistort(camera_matrix=np.identity(3),
                          distortion=[0, 0, 0, 1, 2])
    with tempfile.NamedTemporaryFile() as fid:
        undistort.write_file(fid.name)
        new_object = Undistort.read_json_file(fid.name)
        assert isinstance(new_object, Undistort)
        assert np.identity(3) == pytest.approx(new_object.camera_matrix)
        assert [0, 0, 0, 1, 2] == pytest.approx(new_object.distortion)
示例#3
0
            file_stem = Path(an_image).stem
            pos = float(re.findall(r'(\d+(?:\.\d+)?)', file_stem)[1])
            image = cv2.imread(an_image)
            image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
            print("Loaded {} at height {}".format(an_image, pos))
            current_points_total = finder.process(image_gray)
            current_points_filtered = reject_outlier(
                np.asarray(current_points_total))
            if args.preview:
                overlayed_image = point_overlay(image, current_points_filtered)
                resized_image = cv2.resize(overlayed_image, (750, 750))
                cv2.imshow('image', resized_image)
                cv2.waitKey(0)
                cv2.destroyAllWindows()
            data_points_list.append(current_points_filtered)
            distance_list.append(pos / 1000.0)  #Convert mm to m.

    undistort = Undistort.read_json_file(args.input_intrinsics_file)
    if not undistort:
        print("Could not load camera parameters from " +
              args.input_intrinsics_file + ". Exiting...")
        sys.exit()

    fitter = LaserFitter(undistort, data_points_list, distance_list)
    res, laser_plane = fitter.process()

    print(res)
    print(laser_plane)

    laser_plane.write_file(args.output_file)
示例#4
0
import argparse
import sys
from volteracamera.analysis.undistort import Undistort
from volteracamera.analysis.plane import Plane
from volteracamera.analysis.laser_line_finder import LaserProcessingServer

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("camera_parameters", type=str, help="json file containing undistortion class.")
    parser.add_argument("laser_plane", type=str, help="json file containing laser plane class.")
    parser.add_argument("-o", "--output_file", type=str, help="optional output file for the laser data, saved in csv format.")

    args = parser.parse_args()

    #load in the calibration files
    cam_params = Undistort.read_json_file(args.camera_parameters)
    laser_plane = Plane.read_json_file(args.laser_plane)

    output_file = args.output_file

    if cam_params is None:
        print ("Failed to load camera parameters. Exiting...")
        sys.exit()
    if laser_plane is None:
        print ("Failed to load laser plane parameters. Exiting...")
        sys.exit()

    laser_processor = LaserProcessingServer (cam_params, laser_plane)

    if output_file:
        laser_processor.save_data (output_file)