Commit dfc47feb authored by Mikhail Karpenko's avatar Mikhail Karpenko
Browse files

Add extra sensors processing to lens center measurement

parent 63e87e10
Loading
Loading
Loading
Loading
+77 −70
Original line number Original line Diff line number Diff line
@@ -3761,24 +3761,30 @@ if (MORE_BUTTONS) {
			POWER_CONTROL.lightsOnWithDelay();
			POWER_CONTROL.lightsOnWithDelay();
			long 	  startTime=System.nanoTime();
			long 	  startTime=System.nanoTime();
			FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel);
			FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature=CAMERAS.getSensorTemperature(0,FOCUS_MEASUREMENT_PARAMETERS.EEPROM_channel);
			imp_sel= CAMERAS.acquireSingleImage (
			ImagePlus [] imp_set_ref = CAMERAS.acquireSeveralImages (
					true, //boolean useLasers,
					true, //boolean useLasers,
					UPDATE_STATUS);
					UPDATE_STATUS);
			if (imp_sel==null){
			if (imp_set_ref==null){
				IJ.showMessage("Error","Failed to get camera image\nProcess canceled");
				IJ.showMessage("Error","Failed to get camera image\nProcess canceled");
				return;
				return;
			}
			}
			if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages){
			ImagePlus [] imp_set = new ImagePlus[imp_set_ref.length];
				imp_sel.show();
			imp_set = imp_set_ref.clone();
				imp_sel.updateAndDraw();
			}
			if (LENS_DISTORTION_PARAMETERS==null){
			if (LENS_DISTORTION_PARAMETERS==null){
				IJ.showMessage("LENS_DISTORTION_PARAMETERS is not set");
				IJ.showMessage("LENS_DISTORTION_PARAMETERS is not set");
				return;
				return;
			}
			}
			MatchSimulatedPattern [] matchSimulatedPatternSet = new MatchSimulatedPattern[imp_set.length];
			ImagePlus [] imp_calibrated = new ImagePlus[imp_set.length];
			double headPointersTilt=Double.NaN;
			double headPointersTilt=Double.NaN;
			// measure rotation from the optical head lasers
			for (int imgCounter = 0; imgCounter < imp_set.length; imgCounter++) {
			if (findCenter &&FOCUS_MEASUREMENT_PARAMETERS.useHeadLasers){
				if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages){
					imp_set[imgCounter].show();
					imp_set[imgCounter].updateAndDraw();
				}
				
				// measure rotation from the optical head lasers for the first image only
				if (imgCounter == 0 && findCenter &&FOCUS_MEASUREMENT_PARAMETERS.useHeadLasers){
					ImagePlus imp_headLasers= CAMERAS.acquireSingleImage (
					ImagePlus imp_headLasers= CAMERAS.acquireSingleImage (
							UV_LED_LASERS,
							UV_LED_LASERS,
							UPDATE_STATUS);
							UPDATE_STATUS);
@@ -3811,23 +3817,23 @@ if (MORE_BUTTONS) {
	
	
				if (DEBUG_LEVEL>0) System.out.println("Image acquisition (@"+FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature+"C) done at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
				if (DEBUG_LEVEL>0) System.out.println("Image acquisition (@"+FOCUS_MEASUREMENT_PARAMETERS.sensorTemperature+"C) done at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
				// reset matchSimulatedPattern, so it will start from scratch
				// reset matchSimulatedPattern, so it will start from scratch
			matchSimulatedPattern= new MatchSimulatedPattern(DISTORTION.FFTSize); // new instance, all reset
				matchSimulatedPatternSet[imgCounter] = new MatchSimulatedPattern(DISTORTION.FFTSize); // new instance, all reset
				// next 2 lines are not needed for the new instance, but can be used alternatively if keeipg it
				// next 2 lines are not needed for the new instance, but can be used alternatively if keeipg it
			   matchSimulatedPattern.invalidateFlatFieldForGrid(); //Reset Flat Field calibration - different image. 
				   matchSimulatedPatternSet[imgCounter].invalidateFlatFieldForGrid(); //Reset Flat Field calibration - different image. 
			   matchSimulatedPattern.invalidateFocusMask();
				   matchSimulatedPatternSet[imgCounter].invalidateFocusMask();
	
	
				
				
			if (matchSimulatedPattern.getPointersXY(imp_sel,LASER_POINTERS.laserUVMap.length)==null) { // no pointers in this image
				if (matchSimulatedPatternSet[imgCounter].getPointersXY(imp_set[imgCounter],LASER_POINTERS.laserUVMap.length)==null) { // no pointers in this image
				IJ.showMessage("Error","No laser pointers detected - they are needed for absolute grid positioning\nProcess canceled");
					IJ.showMessage("Error","No laser pointers detected for image #" + imgCounter + " - they are needed for absolute grid positioning\nProcess canceled");
					return;
					return;
				}
				}
	
	
			matchSimulatedPattern.debugLevel=DEBUG_LEVEL;
				matchSimulatedPatternSet[imgCounter].debugLevel=DEBUG_LEVEL;
				int numAbsolutePoints=LENS_ADJUSTMENT.updateFocusGrid(
				int numAbsolutePoints=LENS_ADJUSTMENT.updateFocusGrid(
						LENS_DISTORTION_PARAMETERS.px0, // pixel coordinate of the the optical center
						LENS_DISTORTION_PARAMETERS.px0, // pixel coordinate of the the optical center
						LENS_DISTORTION_PARAMETERS.py0, // pixel coordinate of the the optical center
						LENS_DISTORTION_PARAMETERS.py0, // pixel coordinate of the the optical center
					imp_sel,
						imp_set[imgCounter],
					matchSimulatedPattern,
						matchSimulatedPatternSet[imgCounter],
						DISTORTION,
						DISTORTION,
						FOCUS_MEASUREMENT_PARAMETERS,
						FOCUS_MEASUREMENT_PARAMETERS,
						PATTERN_DETECT,
						PATTERN_DETECT,
@@ -3846,7 +3852,8 @@ if (MORE_BUTTONS) {
					return;
					return;
				}
				}
				if (DEBUG_LEVEL>0) System.out.println("Matched "+numAbsolutePoints+" laser pointers, grid generated at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
				if (DEBUG_LEVEL>0) System.out.println("Matched "+numAbsolutePoints+" laser pointers, grid generated at "+ IJ.d2s(0.000000001*(System.nanoTime()-startTime),3));
			ImagePlus [] imp_calibrated={matchSimulatedPattern.getCalibratedPatternAsImage(imp_sel,"grid-",numAbsolutePoints)};
				imp_calibrated[imgCounter] = matchSimulatedPatternSet[imgCounter].getCalibratedPatternAsImage(imp_set[imgCounter],"grid-",numAbsolutePoints);
			}
			if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages) imp_calibrated[0].show(); // DISTORTION_PROCESS_CONFIGURATION.showGridImages
			if (FOCUS_MEASUREMENT_PARAMETERS.showAcquiredImages) imp_calibrated[0].show(); // DISTORTION_PROCESS_CONFIGURATION.showGridImages
			if (findCenter){
			if (findCenter){
				// Read required calibration files
				// Read required calibration files
+10 −0
Original line number Original line Diff line number Diff line
@@ -1761,6 +1761,16 @@ public class CalibrationHardwareInterface {
	    	this.lastTimestamp=(String) this.images[0].getProperty("timestamp");
	    	this.lastTimestamp=(String) this.images[0].getProperty("timestamp");
	    	return this.images[0];
	    	return this.images[0];
	    }
	    }
	    public ImagePlus [] acquireSeveralImages (boolean useLasers, boolean updateStatus){
			getImages(
	   				null, // UVLEDLasers
					selectAllSubcameras(),
					(useLasers?selectAllSubcameras():null),
					true, 
					this.debugLevel>1); // reset and trigger
	    	this.lastTimestamp=(String) this.images[0].getProperty("timestamp");
	    	return this.images;
	    }


	    public ImagePlus acquireSingleImage (UVLEDandLasers uvLEDLasers, boolean updateStatus){
	    public ImagePlus acquireSingleImage (UVLEDandLasers uvLEDLasers, boolean updateStatus){
			getImages(
			getImages(