Closedown
This commit is contained in:
@@ -31,6 +31,7 @@ import ch.psi.pshell.imaging.Pen;
|
||||
import ch.psi.pshell.imaging.Renderer;
|
||||
import ch.psi.pshell.imaging.Renderer.Profile;
|
||||
import ch.psi.pshell.imaging.RendererListener;
|
||||
import ch.psi.pshell.imaging.Source;
|
||||
import ch.psi.pshell.imaging.Utils;
|
||||
import ch.psi.pshell.scripting.InterpreterResult;
|
||||
import ch.psi.pshell.scripting.ScriptManager;
|
||||
@@ -83,27 +84,50 @@ public class Cameras extends Panel {
|
||||
@Override
|
||||
public void onInitialize(int runCount) {
|
||||
comboCameras.setEnabled(false);
|
||||
cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"});
|
||||
Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b));
|
||||
DefaultComboBoxModel model = new DefaultComboBoxModel();
|
||||
for (File file : cameraConfigFiles) {
|
||||
String prefix = IO.getPrefix(file);
|
||||
if (!prefix.startsWith("#")) {
|
||||
model.addElement(prefix);
|
||||
}
|
||||
}
|
||||
comboCameras.setModel(model);
|
||||
comboCameras.setEnabled(true);
|
||||
comboCameras.setSelectedItem(-1);
|
||||
if (model.getSize() > 0) {
|
||||
try {
|
||||
//setCamera((String)comboCameras.getSelectedItem());
|
||||
if (App.hasArgument("cam")) {
|
||||
comboCameras.setSelectedItem(App.getArgumentValue("cam"));
|
||||
if (App.hasArgument("s")){
|
||||
renderer.setDevice((Source)getDevice("image"));
|
||||
renderer.setAutoScroll(true);
|
||||
((Source)getDevice("image")).addListener(new ImageListener() {
|
||||
@Override
|
||||
public void onImage(Object o, BufferedImage bi, Data data) {
|
||||
if (bi == null) {
|
||||
fitOv = null;
|
||||
} else {
|
||||
Overlay[] profile = renderer.getProfileOverlays();
|
||||
profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null;
|
||||
renderer.updateOverlays(profile, fitOv);
|
||||
fitOv = profile;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onError(Object o, Exception excptn) {
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
} else {
|
||||
cameraConfigFiles = IO.listFiles(configFolder, new String[]{"json"});
|
||||
Arrays.sort(cameraConfigFiles, (a, b) -> a.compareTo(b));
|
||||
DefaultComboBoxModel model = new DefaultComboBoxModel();
|
||||
for (File file : cameraConfigFiles) {
|
||||
String prefix = IO.getPrefix(file);
|
||||
if (!prefix.startsWith("#")) {
|
||||
model.addElement(prefix);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
comboCameras.setModel(model);
|
||||
comboCameras.setEnabled(true);
|
||||
comboCameras.setSelectedItem(-1);
|
||||
if (model.getSize() > 0) {
|
||||
try {
|
||||
//setCamera((String)comboCameras.getSelectedItem());
|
||||
if (App.hasArgument("cam")) {
|
||||
comboCameras.setSelectedItem(App.getArgumentValue("cam"));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
startTimer(2000);
|
||||
}
|
||||
@@ -284,9 +308,19 @@ public class Cameras extends Panel {
|
||||
protected void onTimer() {
|
||||
textState.setText((camera == null) ? "" : camera.getState().toString());
|
||||
buttonConfig.setEnabled(camera != null);
|
||||
if (App.hasArgument("s")){
|
||||
System.out.println("Refresh");
|
||||
try {
|
||||
((Source)getDevice("image")).initialize();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(Cameras.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Pen fitPen = new Pen(new Color(0, 192, 0));
|
||||
Pen fitPen = new Pen(new Color(0, 192, 0), 2);
|
||||
Overlay[] getFitOverlays(BufferedImage img){
|
||||
Overlays.Polyline hpoly = null;
|
||||
Overlays.Polyline vpoly = null;
|
||||
@@ -297,7 +331,7 @@ public class Cameras extends Panel {
|
||||
if (profile.hasVertical()) {
|
||||
try {
|
||||
int[] sum = Utils.integrateVertically(img);
|
||||
int[] x = Arr.indexesInt(sum.length);
|
||||
int[] x = Arr.indexesInt(sum.length);
|
||||
double[] gaussian = fitGaussian(sum, x);
|
||||
if (gaussian!=null){
|
||||
System.out.println("Norm: " + gaussian[0] + " Mean: " + gaussian[1] + " Sigma: " + gaussian[2]);
|
||||
@@ -305,12 +339,13 @@ public class Cameras extends Panel {
|
||||
double[] fit = getFitFunction(gaussian, x);
|
||||
int[] y = new int[x.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
y[i] = (int) (img.getHeight() - 1 - (((double) fit[i]) / 255 / factor)/2);
|
||||
System.out.println("x=" + x[i] , "y=" + y[i], "f=" + fit[i]);
|
||||
y[i] = (int) (img.getHeight() - 1 - (((double) fit[i]) / 255 / factor));
|
||||
}
|
||||
vpoly = new Overlays.Polyline(fitPen, x, y);
|
||||
} else {
|
||||
System.out.println("Fit failure");
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@@ -325,7 +360,7 @@ System.out.println("x=" + x[i] , "y=" + y[i], "f=" + fit[i]);
|
||||
|
||||
int[] y = new int[x.length];
|
||||
for (int i = 0; i < x.length; i++) {
|
||||
y[i] = (int) (((double) fit[i]) / 255 / factor)/2;
|
||||
y[i] = (int) (((double) fit[i]) / 255 / factor);
|
||||
}
|
||||
hpoly = new Overlays.Polyline(fitPen, y, x);
|
||||
}
|
||||
@@ -365,7 +400,6 @@ double[] fitGaussianScript(int[] y, int[] x){
|
||||
|
||||
double[]fitGaussian(int[] y, int[] x){
|
||||
try{
|
||||
ScriptManager sm = Controller.getInstance().getScriptManager();
|
||||
ArrayProperties pY = ArrayProperties.get(y);
|
||||
GaussianCurveFitter fitter = GaussianCurveFitter.create().withStartPoint(new double[]{(pY.max-pY.min)/2,x[pY.maxIndex],1.0}).withMaxIterations(1000);
|
||||
ArrayList<WeightedObservedPoint>values = new ArrayList<>();
|
||||
|
||||
Reference in New Issue
Block a user