⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcamcalib.java

📁 camra calibration and you will enjoy it!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	private void lstHMPointsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstHMPointsValueChanged		// Add your handling code here:		this.chomoip.setSelectedPoint(this.lstHMPoints.getSelectedIndex());	}//GEN-LAST:event_lstHMPointsValueChanged	//----------------------------------------------------------------------------------	private void btnHMLoadUndistortedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHMLoadUndistortedActionPerformed		// Add your handling code here:		String complete = "";		jfci.setDialogTitle("Select undistorted reference image...");		if (jfci.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){			complete = jfci.getSelectedFile().getParent() + File.separatorChar + jfci.getSelectedFile().getName();			BufferedImage magic = ImageTools.convertGrayScaletoRGB(JPEGFileManager.openFile(complete));			this.chomoip.setImage(magic);			this.fw = magic.getWidth();			this.fh = magic.getHeight();		}	}//GEN-LAST:event_btnHMLoadUndistortedActionPerformed	//----------------------------------------------------------------------------------	private void btnIPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPActionPerformed		// Add your handling code here:		JFileChooser jfc = new JFileChooser();		String complete = "";		jfc.setDialogTitle("Save parameters as...");		if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){			complete = jfc.getSelectedFile().getParent() + File.separatorChar + jfc.getSelectedFile().getName();			try{				FileWriter fw = new FileWriter(complete, false);				fw.write(this.eIPConfigFmt.getText());				fw.close();			}			catch (Exception e){				System.out.println("btnIPActionPerformed : Error saving the file: " + complete);				e.printStackTrace();			}		}	}//GEN-LAST:event_btnIPActionPerformed	//----------------------------------------------------------------------------------	private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed		// Add your handling code here:		JOptionPane.showMessageDialog(this, "This program is free software (GPL).\nUses Intel Open Computer Vision Library (OpenCV).\n\n(2004) Hugo Ortega H. hugorteg@yahoo.com\nUtility for my thesis: \"Visual Tracking of Multiple Objects \nwith Mobile Camera in Dynamic Environments\"", "JCamCalib v0.7: A camera Calibration Utility", JOptionPane.INFORMATION_MESSAGE);	}//GEN-LAST:event_jButton1ActionPerformed	//----------------------------------------------------------------------------------	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed		// Add your handling code here:		System.exit(0);	}//GEN-LAST:event_jButton2ActionPerformed	//----------------------------------------------------------------------------------	private void btnIPUndistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPUndistActionPerformed		// Add your handling code here:		if (this.btnIPUndist.isSelected()){			this.cipUndistored.setImage(this.undistorted);		}		else{			this.cipUndistored.setImage(this.distorted);		}	}//GEN-LAST:event_btnIPUndistActionPerformed	//----------------------------------------------------------------------------------	private void btnIPUndistortedSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPUndistortedSaveAsActionPerformed		// Add your handling code here:		String complete = "";		jfci.setDialogTitle("Save undistorted image as...");		if (jfci.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){			complete = jfci.getSelectedFile().getParent() + File.separatorChar + jfci.getSelectedFile().getName();			JPEGFileManager.saveFile(this.undistorted, complete, 100);		}	}//GEN-LAST:event_btnIPUndistortedSaveAsActionPerformed	//----------------------------------------------------------------------------------	private void btnIPUndistortedLoadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPUndistortedLoadActionPerformed		// Add your handling code here:		String complete = "";		jfci.setDialogTitle("Select distorted image...");		if (jfci.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){			complete = jfci.getSelectedFile().getParent() + File.separatorChar + jfci.getSelectedFile().getName();			BufferedImage magic = ImageTools.convertGrayScaletoRGB(JPEGFileManager.openFile(complete));			BufferedImage undist = ImageTools.getBufferedImage(this.cocv.getUndistortedImage(ImageTools.getImageDataRGB(magic), magic.getWidth(), magic.getHeight()), magic.getWidth(), magic.getHeight());			this.cipUndistored.setImage(undist);			this.btnIPUndist.setSelected(true);			this.undistorted = undist;			this.distorted = magic;		}	}//GEN-LAST:event_btnIPUndistortedLoadActionPerformed	//----------------------------------------------------------------------------------	private void btnIPComputeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPComputeActionPerformed		// Add your handling code here:		for(int i=0; i<this.imagesCalib.size(); i++){			BufferedImage magic = (BufferedImage)this.imagesCalib.get(i);			this.cocv.addCalibrationImage(ImageTools.getImageDataRGB(magic), magic.getWidth(), magic.getHeight());		}		if (!this.cocv.calibrate()){			JOptionPane.showMessageDialog(this, "Error in calibration. Try other images please.", "ERROR", JOptionPane.ERROR_MESSAGE);		}		else{			double res[] = this.cocv.getResults();			//for (int j=0; j<res.length; j++) System.out.println(res[j]);			this.eIPMatrix0.setText(Double.toString(res[0]));			this.eIPMatrix1.setText(Double.toString(res[1]));			this.eIPMatrix2.setText(Double.toString(res[2]));			this.eIPMatrix3.setText(Double.toString(res[3]));			this.eIPMatrix4.setText(Double.toString(res[4]));			this.eIPMatrix5.setText(Double.toString(res[5]));			this.eIPMatrix6.setText(Double.toString(res[6]));			this.eIPMatrix7.setText(Double.toString(res[7]));			this.eIPMatrix8.setText(Double.toString(res[8]));			this.eIPDistk1.setText(Double.toString(res[9]));			this.eIPDistk2.setText(Double.toString(res[10]));			this.eIPDistp1.setText(Double.toString(res[11]));			this.eIPDistp2.setText(Double.toString(res[12]));			this.jtpIntCalOptions.setSelectedIndex(1);			this.eIPConfigFmt.setText("");			String txt = "CAMERA_INTRINSICS = ";			for(int i=0; i<9; i++) txt += res[i] + " ";			txt += "\nCAMERA_LENS_DIST = ";			for(int i=9; i<13; i++) txt += res[i] + " ";						this.eIPConfigFmt.setText(txt);		}	}//GEN-LAST:event_btnIPComputeActionPerformed	//----------------------------------------------------------------------------------	private void btnIPDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPDelActionPerformed		// Add your handling code here:		if (this.lstImgsCalib.size() > 0){			int idx = this.lstImagesCalib.getSelectedIndex();			this.lstImgsCalib.remove(idx);			this.imagesCalib.remove(idx);			if (this.lstImgsCalib.size() > 0) this.lstImagesCalib.setSelectedIndex(this.lstImgsCalib.size()-1);		}	}//GEN-LAST:event_btnIPDelActionPerformed	//----------------------------------------------------------------------------------	private void lstImagesCalibValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lstImagesCalibValueChanged		// Add your handling code here:		if (this.lstImgsCalib.size() > 0 && this.lstImagesCalib.getSelectedIndex() >= 0){			if (this.jtpIntCalOptions.getSelectedIndex() != 0) this.jtpIntCalOptions.setSelectedIndex(0);			BufferedImage magic = (BufferedImage)this.imagesCalib.get(this.lstImagesCalib.getSelectedIndex());			this.cip.clearPoints();			this.cip.setImage(magic);			double pnts[] = this.cocv.findCorners(ImageTools.getImageDataRGB(magic), fw,  fh);			if (pnts == null){				JOptionPane.showMessageDialog(this, "Chessboard pattern was not detected in this image. Try increasing contrast of image and reduce the brightness.");				return;			}			else if (pnts.length != 96){				JOptionPane.showMessageDialog(this, "Not all points in the chessboard pattern were detected in this image. Try to use an image with better illumination or resolution please.", "ERROR", JOptionPane.ERROR_MESSAGE);			}			for (int i=0; i<pnts.length; i+=2){				this.cip.addPoint((int)Math.round(pnts[i]), (int)Math.round(pnts[i+1]));			}			this.cip.repaint();		}	}//GEN-LAST:event_lstImagesCalibValueChanged	//----------------------------------------------------------------------------------	private void btnIPAddFromCameraActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPAddFromCameraActionPerformed		// Add your handling code here:	}//GEN-LAST:event_btnIPAddFromCameraActionPerformed	//----------------------------------------------------------------------------------	private void btnIPAddFromFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnIPAddFromFileActionPerformed		// Add your handling code here:		String complete = "";		jfci.setDialogTitle("Select a calibration image...");		if (jfci.showOpenDialog(this) == JFileChooser.APPROVE_OPTION){			complete = jfci.getSelectedFile().getParent() + File.separatorChar + jfci.getSelectedFile().getName();			BufferedImage magic = ImageTools.convertGrayScaletoRGB(JPEGFileManager.openFile(complete));			//this.pnlIPCalibrationImage.setSize(magic.getWidth(), magic.getHeight());			if (this.imagesCalib.size() == 0){				this.fw = magic.getWidth();				this.fh = magic.getHeight();			}			if (magic.getWidth() != this.fw || magic.getHeight() != this.fh){				JOptionPane.showMessageDialog(this, "Image is not valid: should be same size of the first one (" + this.fw + "x" + this.fh + ")", "ERROR", JOptionPane.ERROR_MESSAGE);			}			else{				this.imagesCalib.add(magic);				this.lstImgsCalib.addElement(complete);				this.lstImagesCalib.setSelectedIndex(this.lstImgsCalib.size()-1);			}		}	}//GEN-LAST:event_btnIPAddFromFileActionPerformed		//----------------------------------------------------------------------------------	/** Exit the Application */	private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm		System.exit(0);	}//GEN-LAST:event_exitForm	//----------------------------------------------------------------------------------	/**	 * @param args the command line arguments	 */	public static void main(String args[]) {		try {			UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");		}		catch (Exception e){			System.out.println("Unable to load Look and Feel... using default Metal.");		}				new JCamCalib().show();	}		    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton btnHMGetMatrix;    private javax.swing.JButton btnHMImageProjScaleApply1;    private javax.swing.JButton btnHMImageProjScaleGenerate;    private javax.swing.JButton btnHMLoadUndistorted;    private javax.swing.JToggleButton btnHMPointAddMode;    private javax.swing.JButton btnHMPointDel;    private javax.swing.JButton btnHMPointEdit;    private javax.swing.JButton btnHMSaveMatrix;    private javax.swing.JButton btnIP;    private javax.swing.JButton btnIPAddFromCamera;    private javax.swing.JButton btnIPAddFromFile;    private javax.swing.JButton btnIPCompute;    private javax.swing.JButton btnIPDel;    private javax.swing.JToggleButton btnIPUndist;    private javax.swing.JButton btnIPUndistortedLoad;    private javax.swing.JButton btnIPUndistortedSaveAs;    private javax.swing.JComboBox cbxHMImgProjectionOrigin;    private javax.swing.JTextField eHM0;    private javax.swing.JTextField eHM1;    private javax.swing.JTextField eHM2;    private javax.swing.JTextField eHM3;    private javax.swing.JTextField eHM4;    private javax.swing.JTextField eHM5;    private javax.swing.JTextField eHM6;    private javax.swing.JTextField eHM7;    private javax.swing.JTextField eHM8;    private javax.swing.JTextArea eHMConfigFmt;    private javax.swing.JTextField eHMImageProjectionScale;    private javax.swing.JTextField eHMImgProjectorX1;    private javax.swing.JTextField eHMImgProjectorX2;    private javax.swing.JTextField eHMImgProjectorY1;    private javax.swing.JTextField eHMImgProjectorY2;    private javax.swing.JTextField eHM_w2i_0;    private javax.swing.JTextField eHM_w2i_1;    private javax.swing.JTextField eHM_w2i_2;    private javax.swing.JTextField eHM_w2i_3;    private javax.swing.JTextField eHM_w2i_4;    private javax.swing.JTextField eHM_w2i_5;    private javax.swing.JTextField eHM_w2i_6;    private javax.swing.JTextField eHM_w2i_7;    private javax.swing.JTextField eHM_w2i_8;    private javax.swing.JTextArea eIPConfigFmt;    private javax.swing.JTextField eIPDistk1;    private javax.swing.JTextField eIPDistk2;    private javax.swing.JTextField eIPDistp1;    private javax.swing.JTextField eIPDistp2;    private javax.swing.JTextField eIPMatrix0;    private javax.swing.JTextField eIPMatrix1;    private javax.swing.JTextField eIPMatrix2;    private javax.swing.JTextField eIPMatrix3;    private javax.swing.JTextField eIPMatrix4;    private javax.swing.JTextField eIPMatrix5;    private javax.swing.JTextField eIPMatrix6;    private javax.swing.JTextField eIPMatrix7;    private javax.swing.JTextField eIPMatrix8;    private javax.swing.JButton jButton1;    private javax.swing.JButton jButton2;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JLabel jLabel4;    private javax.swing.JLabel jLabel5;    private javax.swing.JLabel jLabel6;    private javax.swing.JPanel jPanel1;    private javax.swing.JPanel jPanel10;    private javax.swing.JPanel jPanel11;    private javax.swing.JPanel jPanel12;    private javax.swing.JPanel jPanel13;    private javax.swing.JPanel jPanel14;    private javax.swing.JPanel jPanel15;    private javax.swing.JPanel jPanel16;    private javax.swing.JPanel jPanel17;    private javax.swing.JPanel jPanel18;    private javax.swing.JPanel jPanel19;    private javax.swing.JPanel jPanel2;    private javax.swing.JPanel jPanel20;    private javax.swing.JPanel jPanel21;    private javax.swing.JPanel jPanel22;    private javax.swing.JPanel jPanel23;    private javax.swing.JPanel jPanel24;    private javax.swing.JPanel jPanel25;    private javax.swing.JPanel jPanel26;    private javax.swing.JPanel jPanel27;    private javax.swing.JPanel jPanel28;    private javax.swing.JPanel jPanel29;    private javax.swing.JPanel jPanel3;    private javax.swing.JPanel jPanel30;    private javax.swing.JPanel jPanel31;    private javax.swing.JPanel jPanel32;    private javax.swing.JPanel jPanel33;    private javax.swing.JPanel jPanel34;    private javax.swing.JPanel jPanel35;    private javax.swing.JPanel jPanel36;    private javax.swing.JPanel jPanel37;    private javax.swing.JPanel jPanel38;    private javax.swing.JPanel jPanel4;    private javax.swing.JPanel jPanel5;    private javax.swing.JPanel jPanel6;    private javax.swing.JPanel jPanel7;    private javax.swing.JPanel jPanel8;    private javax.swing.JPanel jPanel9;    private javax.swing.JScrollPane jScrollPane1;    private javax.swing.JScrollPane jScrollPane2;    private javax.swing.JSplitPane jSplitPane1;    private javax.swing.JSplitPane jSplitPane2;    private javax.swing.JTabbedPane jTabbedPane1;    private javax.swing.JTabbedPane jtpHMOptions;    private javax.swing.JTabbedPane jtpIntCalOptions;    private javax.swing.JLabel lblHMImgCoordinates;    private javax.swing.JLabel lblHMTestImagePoint;    private javax.swing.JLabel lblHMTestWorldPoint;    private javax.swing.JLabel lblIPDistk2;    private javax.swing.JLabel lblIPDistp1;    private javax.swing.JList lstHMPoints;    private javax.swing.JList lstImagesCalib;    private javax.swing.JPanel pnlHMImageProjection;    private javax.swing.JPanel pnlHMImageReference;    private javax.swing.JPanel pnlHMTestMode;    private javax.swing.JPanel pnlIPCalibrationImages;    private javax.swing.JPanel pnlIPResults;    private javax.swing.JPanel pnlIPUndistortedImage;    // End of variables declaration//GEN-END:variables	private DefaultListModel lstImgsCalib = new DefaultListModel();	private DefaultListModel lstHomoPoints = new DefaultListModel();	private FileChooserImage jfci = new FileChooserImage();	private CalibratorImagePanel cip = new CalibratorImagePanel();	private CalibratorImagePanel cipUndistored = new CalibratorImagePanel();	private CalibratorHomographyImagePanel chomoip = new CalibratorHomographyImagePanel();	private CalibratorHomographyImagePanel chomoipTest = new CalibratorHomographyImagePanel();	private ImagePanelScroller ips = new ImagePanelScroller();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -