Startup
This commit is contained in:
@@ -38,6 +38,7 @@ import ch.psi.pshell.scripting.ScriptManager;
|
||||
import ch.psi.utils.Arr;
|
||||
import ch.psi.utils.ArrayProperties;
|
||||
import ch.psi.utils.Convert;
|
||||
import ch.psi.utils.Str;
|
||||
import ch.psi.utils.swing.Editor.EditorDialog;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
@@ -100,6 +101,7 @@ public class Cameras extends Panel {
|
||||
String cameraConfigJson;
|
||||
CameraConfig config;
|
||||
int polling = 1000;
|
||||
Overlay marker = null;
|
||||
|
||||
//Overridable callbacks
|
||||
@Override
|
||||
@@ -183,20 +185,27 @@ public class Cameras extends Panel {
|
||||
|
||||
public double getCalOffsetX(){
|
||||
ArrayList<Integer> calibration = getCalibration();
|
||||
return - (calibration.get(0) + calibration.get(2))/2;
|
||||
double ret = - (calibration.get(0) + calibration.get(2))/2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public double getCalOffsetY(){
|
||||
ArrayList<Integer> calibration = getCalibration();
|
||||
return - (calibration.get(1) + calibration.get(2))/3;
|
||||
double ret = - (calibration.get(1) + calibration.get(3))/2;
|
||||
return ret;
|
||||
}
|
||||
|
||||
public double getScaleX(){
|
||||
return getCalibrationHeight()/1000;
|
||||
ArrayList<Integer> calibration = getCalibration();
|
||||
double width = Math.abs( calibration.get(2) - calibration.get(0));
|
||||
return getCalibrationWidth()/width;
|
||||
//return getCalibrationWidth()/1000;
|
||||
}
|
||||
|
||||
public double getScaleY(){
|
||||
return getCalibrationHeight()/1000;
|
||||
ArrayList<Integer> calibration = getCalibration();
|
||||
double height = Math.abs( calibration.get(3) - calibration.get(1));
|
||||
return getCalibrationHeight()/height;
|
||||
}
|
||||
|
||||
|
||||
@@ -261,7 +270,7 @@ public class Cameras extends Panel {
|
||||
camera = null;
|
||||
renderer.setDevice(null);
|
||||
renderer.setShowReticle(false);
|
||||
renderer.clearOverlays();
|
||||
renderer.removeOverlays(fitOv);
|
||||
renderer.clear();
|
||||
renderer.resetZoom();
|
||||
}
|
||||
@@ -330,7 +339,7 @@ public class Cameras extends Panel {
|
||||
*/
|
||||
}
|
||||
buttonReticle.setEnabled(camera.getConfig().isCalibrated());
|
||||
buttonBackground.setEnabled(camera instanceof Camtool);
|
||||
buttonGrabBackground.setEnabled(camera instanceof Camtool);
|
||||
camera.getConfig().save();
|
||||
|
||||
if (polling<=0){
|
||||
@@ -340,17 +349,16 @@ public class Cameras extends Panel {
|
||||
}
|
||||
renderer.setDevice(camera);
|
||||
renderer.setAutoScroll(true);
|
||||
renderer.setMarker(marker);
|
||||
|
||||
camera.addListener(new ImageListener() {
|
||||
@Override
|
||||
public void onImage(Object o, BufferedImage bi, Data data) {
|
||||
if (bi!=null){
|
||||
System.out.println(bi.getWidth() + " - " + bi.getHeight());
|
||||
}
|
||||
if (bi == null) {
|
||||
renderer.removeOverlays(fitOv);
|
||||
fitOv = null;
|
||||
} else {
|
||||
//System.out.println(bi.getWidth() + " - " + bi.getHeight());
|
||||
if (!renderer.isPaused() && buttonFit.isSelected()){
|
||||
Overlay[] profile = renderer.getProfileOverlays();
|
||||
profile = ((profile != null) && (profile.length==4)) ? getFitOverlays(bi) : null;
|
||||
@@ -371,7 +379,7 @@ public class Cameras extends Panel {
|
||||
}
|
||||
} finally {
|
||||
checkReticle();
|
||||
onTimer();
|
||||
onTimer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -644,16 +652,12 @@ public class Camtool extends ArraySource {
|
||||
|
||||
if (roiEnabled.read()>0){
|
||||
int[] s = roiShape.read();
|
||||
for (int x : s){
|
||||
System.out.println(x);
|
||||
}
|
||||
//for (int x : s) System.out.println(x);
|
||||
getConfig().imageHeight = s[3];
|
||||
getConfig().imageWidth = s[2];
|
||||
} else {
|
||||
int[] s = shape.read();
|
||||
for (int x : s){
|
||||
System.out.println(x);
|
||||
}
|
||||
//for (int x : s){ System.out.println(x);}
|
||||
getConfig().imageHeight = s[0];
|
||||
getConfig().imageWidth = s[1];
|
||||
}
|
||||
@@ -661,7 +665,7 @@ public class Camtool extends ArraySource {
|
||||
getConfig().save();
|
||||
getDevice().setSize(getConfig().imageHeight * getConfig().imageWidth);
|
||||
super.doInitialize();
|
||||
System.out.println(((int[])(getDevice().read())).length);
|
||||
//System.out.println(((int[])(getDevice().read())).length);
|
||||
} catch (InterruptedException ex) {
|
||||
throw ex;
|
||||
} catch (Exception ex) {
|
||||
@@ -769,8 +773,8 @@ public class Camtool extends ArraySource {
|
||||
buttonPause = new javax.swing.JToggleButton();
|
||||
buttonMarker = new javax.swing.JToggleButton();
|
||||
buttonSave = new javax.swing.JToggleButton();
|
||||
buttonBackground = new javax.swing.JToggleButton();
|
||||
buttonReticle = new javax.swing.JToggleButton();
|
||||
buttonGrabBackground = new javax.swing.JButton();
|
||||
|
||||
jLabel1.setText("Camera:");
|
||||
|
||||
@@ -834,13 +838,6 @@ public class Camtool extends ArraySource {
|
||||
}
|
||||
});
|
||||
|
||||
buttonBackground.setText("Grab Background");
|
||||
buttonBackground.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonBackgroundActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
buttonReticle.setSelected(true);
|
||||
buttonReticle.setText("Reticle");
|
||||
buttonReticle.addActionListener(new java.awt.event.ActionListener() {
|
||||
@@ -849,6 +846,13 @@ public class Camtool extends ArraySource {
|
||||
}
|
||||
});
|
||||
|
||||
buttonGrabBackground.setText("Grab Background");
|
||||
buttonGrabBackground.addActionListener(new java.awt.event.ActionListener() {
|
||||
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||
buttonGrabBackgroundActionPerformed(evt);
|
||||
}
|
||||
});
|
||||
|
||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
|
||||
this.setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
@@ -879,8 +883,8 @@ public class Camtool extends ArraySource {
|
||||
.addComponent(buttonFit)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonReticle)
|
||||
.addGap(18, 18, Short.MAX_VALUE)
|
||||
.addComponent(buttonBackground)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||
.addComponent(buttonGrabBackground)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(buttonSave)))
|
||||
.addContainerGap())
|
||||
@@ -888,10 +892,10 @@ public class Camtool extends ArraySource {
|
||||
|
||||
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonConfig, buttonSetup});
|
||||
|
||||
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonBackground, buttonSave});
|
||||
|
||||
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonFit, buttonMarker, buttonPause, buttonReticle});
|
||||
|
||||
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {buttonGrabBackground, buttonSave});
|
||||
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
@@ -912,8 +916,8 @@ public class Camtool extends ArraySource {
|
||||
.addComponent(buttonFit)
|
||||
.addComponent(buttonMarker)
|
||||
.addComponent(buttonSave)
|
||||
.addComponent(buttonBackground)
|
||||
.addComponent(buttonReticle))
|
||||
.addComponent(buttonReticle)
|
||||
.addComponent(buttonGrabBackground))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
@@ -989,12 +993,12 @@ public class Camtool extends ArraySource {
|
||||
Dimension d = renderer.getImageSize();
|
||||
Point p = (d == null) ? new Point(renderer.getWidth() / 2, renderer.getHeight() / 2) : new Point(d.width / 2, d.height / 2);
|
||||
Overlay ov = null;
|
||||
ov = new Overlays.Crosshairs(PEN_MARKER, p, new Dimension(100, 100));
|
||||
ov.setMovable(true);
|
||||
renderer.setMarker(ov);
|
||||
marker = new Overlays.Crosshairs(PEN_MARKER, p, new Dimension(100, 100));
|
||||
marker.setMovable(true);
|
||||
} else {
|
||||
renderer.setMarker(null);
|
||||
marker = null;
|
||||
}
|
||||
renderer.setMarker(marker);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
@@ -1021,16 +1025,6 @@ public class Camtool extends ArraySource {
|
||||
}
|
||||
}//GEN-LAST:event_buttonReticleActionPerformed
|
||||
|
||||
private void buttonBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonBackgroundActionPerformed
|
||||
try {
|
||||
if (camera instanceof Camtool){
|
||||
((Camtool)camera).captureBackground(5);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonBackgroundActionPerformed
|
||||
|
||||
private void buttonSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonSaveActionPerformed
|
||||
try {
|
||||
renderer.setSnapshotDialogVisible(buttonSave.isSelected());
|
||||
@@ -1039,10 +1033,20 @@ public class Camtool extends ArraySource {
|
||||
}
|
||||
}//GEN-LAST:event_buttonSaveActionPerformed
|
||||
|
||||
private void buttonGrabBackgroundActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonGrabBackgroundActionPerformed
|
||||
try {
|
||||
if (camera instanceof Camtool){
|
||||
((Camtool)camera).captureBackground(5);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
showException(ex);
|
||||
}
|
||||
}//GEN-LAST:event_buttonGrabBackgroundActionPerformed
|
||||
|
||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JToggleButton buttonBackground;
|
||||
private javax.swing.JButton buttonConfig;
|
||||
private javax.swing.JToggleButton buttonFit;
|
||||
private javax.swing.JButton buttonGrabBackground;
|
||||
private javax.swing.JToggleButton buttonMarker;
|
||||
private javax.swing.JToggleButton buttonPause;
|
||||
private javax.swing.JToggleButton buttonReticle;
|
||||
|
||||
Reference in New Issue
Block a user