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

📄 jcamcalib.java

📁 camra calibration and you will enjoy it!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        jPanel37.setLayout(new javax.swing.BoxLayout(jPanel37, javax.swing.BoxLayout.X_AXIS));        jPanel37.setMaximumSize(new java.awt.Dimension(32767, 16));        jPanel36.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));        jLabel6.setFont(new java.awt.Font("Dialog", 0, 10));        jLabel6.setText("Origin:");        jPanel36.add(jLabel6);        cbxHMImgProjectionOrigin.setFont(new java.awt.Font("Dialog", 0, 10));        cbxHMImgProjectionOrigin.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "L-U", "R-U", "R-B", "L-B" }));        cbxHMImgProjectionOrigin.setSelectedIndex(3);        cbxHMImgProjectionOrigin.setToolTipText("[Left|Rigth]-[Top-Bottom]");        jPanel36.add(cbxHMImgProjectionOrigin);        jLabel3.setFont(new java.awt.Font("Dialog", 0, 10));        jLabel3.setText("Scale: 1px =");        jPanel36.add(jLabel3);        eHMImageProjectionScale.setHorizontalAlignment(javax.swing.JTextField.RIGHT);        eHMImageProjectionScale.setText("0.01");        eHMImageProjectionScale.setPreferredSize(new java.awt.Dimension(60, 20));        jPanel36.add(eHMImageProjectionScale);        jLabel5.setFont(new java.awt.Font("Dialog", 0, 10));        jLabel5.setText("Coordinates:");        jPanel36.add(jLabel5);        eHMImgProjectorX1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);        eHMImgProjectorX1.setText("0");        eHMImgProjectorX1.setToolTipText("x1");        eHMImgProjectorX1.setPreferredSize(new java.awt.Dimension(45, 20));        jPanel36.add(eHMImgProjectorX1);        eHMImgProjectorY1.setHorizontalAlignment(javax.swing.JTextField.RIGHT);        eHMImgProjectorY1.setText("0");        eHMImgProjectorY1.setToolTipText("y1");        eHMImgProjectorY1.setPreferredSize(new java.awt.Dimension(45, 20));        jPanel36.add(eHMImgProjectorY1);        eHMImgProjectorX2.setHorizontalAlignment(javax.swing.JTextField.RIGHT);        eHMImgProjectorX2.setToolTipText("x2");        eHMImgProjectorX2.setPreferredSize(new java.awt.Dimension(45, 20));        jPanel36.add(eHMImgProjectorX2);        eHMImgProjectorY2.setHorizontalAlignment(javax.swing.JTextField.RIGHT);        eHMImgProjectorY2.setToolTipText("y2");        eHMImgProjectorY2.setPreferredSize(new java.awt.Dimension(45, 20));        jPanel36.add(eHMImgProjectorY2);        btnHMImageProjScaleGenerate.setFont(new java.awt.Font("Dialog", 0, 10));        btnHMImageProjScaleGenerate.setText("Generate");        btnHMImageProjScaleGenerate.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                btnHMImageProjScaleGenerateActionPerformed(evt);            }        });        jPanel36.add(btnHMImageProjScaleGenerate);        jPanel37.add(jPanel36);        jPanel38.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));        btnHMImageProjScaleApply1.setFont(new java.awt.Font("Dialog", 0, 10));        btnHMImageProjScaleApply1.setText("Save image...");        btnHMImageProjScaleApply1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                btnHMImageProjScaleApply1ActionPerformed(evt);            }        });        jPanel38.add(btnHMImageProjScaleApply1);        jPanel37.add(jPanel38);        jPanel34.add(jPanel37);        jtpHMOptions.addTab("Image projection", jPanel34);        jPanel19.add(jtpHMOptions);        jSplitPane2.setRightComponent(jPanel19);        jPanel3.add(jSplitPane2, java.awt.BorderLayout.CENTER);        jTabbedPane1.addTab("Homography matrix", jPanel3);        jTabbedPane1.addTab("Camera setup", jPanel4);        getContentPane().add(jTabbedPane1);        jPanel2.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));        jPanel2.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(3, 3, 3, 3)));        jButton1.setText("About...");        jButton1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton1ActionPerformed(evt);            }        });        jPanel2.add(jButton1);        jButton2.setText("Exit");        jButton2.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jButton2ActionPerformed(evt);            }        });        jPanel2.add(jButton2);        getContentPane().add(jPanel2);        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();        setBounds((screenSize.width-1000)/2, (screenSize.height-680)/2, 1000, 680);    }//GEN-END:initComponents	//----------------------------------------------------------------------------------	private void btnHMImageProjScaleApply1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHMImageProjScaleApply1ActionPerformed		// Add your handling code here:		String complete = "";		jfci.setDialogTitle("Save projected image as...");		if (jfci.showSaveDialog(this) == JFileChooser.APPROVE_OPTION){			complete = jfci.getSelectedFile().getParent() + File.separatorChar + jfci.getSelectedFile().getName();			JPEGFileManager.saveFile(this.ips.getImage(), complete, 100);		}	}//GEN-LAST:event_btnHMImageProjScaleApply1ActionPerformed	//----------------------------------------------------------------------------------	private void btnHMImageProjScaleGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHMImageProjScaleGenerateActionPerformed		// Add your handling code here:		double[] values = new double[5];		javax.swing.JTextField fields[] = {this.eHMImageProjectionScale, this.eHMImgProjectorX1, this.eHMImgProjectorY1, this.eHMImgProjectorX2, this.eHMImgProjectorY2};		for (int i=0; i<5; i++){			if (fields[i].getText() == ""){				fields[i].grabFocus();				return;			}			try{				values[i] = new Double(fields[i].getText()).doubleValue();			}			catch(NumberFormatException e){				fields[i].grabFocus();				return;			}		}		this.hip = new HomographyImageProjection(this.homoI2W,  this.homoW2I, this.chomoip.getImage());		this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));		BufferedImage theres = this.hip.process(values[0], values[1], values[2], values[3], values[4], this.cbxHMImgProjectionOrigin.getSelectedIndex()+1);		this.setCursor(Cursor.getDefaultCursor());		if (theres != null){			this.ips.setImage(theres);		}		else{			JOptionPane.showMessageDialog(this, "Unable to create the projection image. Try to reduce the scale.", "ERROR", JOptionPane.ERROR_MESSAGE);			}	}//GEN-LAST:event_btnHMImageProjScaleGenerateActionPerformed	//----------------------------------------------------------------------------------	private void pnlHMTestModeMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlHMTestModeMouseMoved		// Add your handling code here:		Point mouse = new Point((int)evt.getX(), (int)evt.getY());		DecimalFormat fmt = new DecimalFormat("0.00000");		if (mouse.x < this.fw && mouse.y < this.fh){			this.lblHMTestImagePoint.setText("Image point = (" + mouse.x + ", " + mouse.y + ")");			PointDouble real = this.homoTrans.image2World(mouse.x, mouse.y);			this.lblHMTestWorldPoint.setText("World point = (" + fmt.format(real.x) + ", " + fmt.format(real.y) + ")");		}	}//GEN-LAST:event_pnlHMTestModeMouseMoved	//----------------------------------------------------------------------------------	private void lstHMPointsMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lstHMPointsMouseClicked		// Add your handling code here:		if (this.jtpHMOptions.getSelectedIndex() != 0) this.jtpHMOptions.setSelectedIndex(0);		if (evt.getClickCount() == 2){			this.btnHMPointEditActionPerformed(null);		}	}//GEN-LAST:event_lstHMPointsMouseClicked	//----------------------------------------------------------------------------------	private void btnHMSaveMatrixActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHMSaveMatrixActionPerformed		// 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.eHMConfigFmt.getText());				fw.close();			}			catch (Exception e){				System.out.println("btnHMSaveMatrixActionPerformed : Error saving the file: " + complete);				e.printStackTrace();			}		}	}//GEN-LAST:event_btnHMSaveMatrixActionPerformed	//----------------------------------------------------------------------------------	private void btnHMPointEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHMPointEditActionPerformed		// Add your handling code here:		if (this.lstHMPoints.getSelectedIndex() != -1){			int indx = this.lstHMPoints.getSelectedIndex();			PointImageWorld piw = (PointImageWorld)this.lstHomoPoints.get(indx);			Point2D imgPoint = piw.getImagePoint();			Rectangle sub = new Rectangle((int)imgPoint.getX()-this.subImageSize/2, 			                              (int)imgPoint.getY()-this.subImageSize/2, 			                              this.subImageSize , this.subImageSize);			BufferedImage subImg = ImageTools.getZoomedImage(this.chomoip.getImage(), sub, this.scaleHomoPoint);			HMWorldCoordinatesDialog wcd = new HMWorldCoordinatesDialog(this, true, piw.getImagePoint(), piw.getWorldPoint(), sub, this.scaleHomoPoint, subImg, this.chomoip.getImage().getWidth(), this.chomoip.getImage().getHeight());			Toolkit tk = Toolkit.getDefaultToolkit();			int scrWidth = (int)tk.getScreenSize().getWidth();			int scrHeigth = (int)tk.getScreenSize().getHeight();			int wcdx = (int)(piw.getImagePoint().getX() + this.chomoip.getLocationOnScreen().getX() + 5);			int wcdy = (int)(piw.getImagePoint().getY() + this.chomoip.getLocationOnScreen().getY() + 5);			wcdx = wcdx + wcd.getWidth() > scrWidth ? scrWidth - wcd.getWidth() : wcdx;			wcdy = wcdy + wcd.getHeight() > scrHeigth ? scrHeigth - wcd.getHeight() : wcdy;			wcd.setLocation(wcdx, wcdy);			wcd.show();			if (wcd.getResult()){				piw.setWorldPoint(wcd.getWorldX(),  wcd.getWorldY());				piw.setImagePoint(wcd.getImageX(),  wcd.getImageX());				this.lstHMPoints.repaint();			}		}	}//GEN-LAST:event_btnHMPointEditActionPerformed	//----------------------------------------------------------------------------------	private void btnHMPointDelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHMPointDelActionPerformed		// Add your handling code here:		if (this.lstHMPoints.getSelectedIndex() != -1){			int idx = this.lstHMPoints.getSelectedIndex();			this.lstHomoPoints.remove(idx);			this.chomoip.deletePoint(idx);		}	}//GEN-LAST:event_btnHMPointDelActionPerformed	//----------------------------------------------------------------------------------	private void lstHMPointsKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lstHMPointsKeyPressed		// Add your handling code here:		if (evt.getKeyCode() == evt.VK_DELETE){			this.btnHMPointDelActionPerformed(null);		}	}//GEN-LAST:event_lstHMPointsKeyPressed	//----------------------------------------------------------------------------------	private void btnHMGetMatrixActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnHMGetMatrixActionPerformed		// Add your handling code here:		if (this.lstHomoPoints.size() < 5){			JOptionPane.showMessageDialog(this, "You need at least 5 points to calculate the homography matrix.");		}		else{			int size = this.lstHomoPoints.size() * 2;			double imagePoints[] = new double[size];			double worldPoints[] = new double[size];			for (int i=0, j=0; i<size; i+=2, j++){				PointImageWorld pnt = (PointImageWorld)this.lstHomoPoints.get(j);				imagePoints[i]   = pnt.getImageX();				imagePoints[i+1] = pnt.getImageY();				worldPoints[i]   = pnt.getWorldX();				worldPoints[i+1] = pnt.getWorldY();			}			homoI2W = this.cocv.getHomographyMatrix(imagePoints, worldPoints, size/2, this.fw, this.fh);			this.eHM0.setText(Double.toString(homoI2W[0]));			this.eHM1.setText(Double.toString(homoI2W[1]));			this.eHM2.setText(Double.toString(homoI2W[2]));			this.eHM3.setText(Double.toString(homoI2W[3]));			this.eHM4.setText(Double.toString(homoI2W[4]));			this.eHM5.setText(Double.toString(homoI2W[5]));			this.eHM6.setText(Double.toString(homoI2W[6]));			this.eHM7.setText(Double.toString(homoI2W[7]));			this.eHM8.setText(Double.toString(homoI2W[8]));			this.eHMConfigFmt.setText("");			String txt = "WIP_HOMO_IMG2WRLD = ";			for(int i=0; i<9; i++) txt += homoI2W[i] + " ";						homoW2I = this.cocv.getHomographyMatrix(worldPoints, imagePoints, size/2, this.fw, this.fh);			this.eHM_w2i_0.setText(Double.toString(homoW2I[0]));			this.eHM_w2i_1.setText(Double.toString(homoW2I[1]));			this.eHM_w2i_2.setText(Double.toString(homoW2I[2]));			this.eHM_w2i_3.setText(Double.toString(homoW2I[3]));			this.eHM_w2i_4.setText(Double.toString(homoW2I[4]));			this.eHM_w2i_5.setText(Double.toString(homoW2I[5]));			this.eHM_w2i_6.setText(Double.toString(homoW2I[6]));			this.eHM_w2i_7.setText(Double.toString(homoW2I[7]));			this.eHM_w2i_8.setText(Double.toString(homoW2I[8]));			txt += "\nWIP_HOMO_WRLD2IMG = ";			for(int i=0; i<9; i++) txt += homoW2I[i] + " ";			this.eHMConfigFmt.setText(txt);			this.jtpHMOptions.setSelectedIndex(1);						this.homoTrans = new HomographyTransform(homoW2I, homoI2W);						this.chomoipTest.setImage(this.chomoip.getImage());			this.chomoipTest.setPoints(this.chomoip.getPoints());			this.chomoipTest.setSelectedPoint(-1);		}	}//GEN-LAST:event_btnHMGetMatrixActionPerformed	//----------------------------------------------------------------------------------	private void pnlHMImageReferenceMouseMoved(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlHMImageReferenceMouseMoved		// Add your handling code here:		Point mouse = new Point((int)evt.getX(), (int)evt.getY());		if (mouse.x < this.fw && mouse.y < this.fh){			this.lblHMImgCoordinates.setText("(" + mouse.x + ", " + mouse.y + ")");		}	}//GEN-LAST:event_pnlHMImageReferenceMouseMoved	//----------------------------------------------------------------------------------	private void pnlHMImageReferenceMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pnlHMImageReferenceMouseClicked		// Add your handling code here:		Point mouse = new Point((int)evt.getX(), (int)evt.getY());		if (mouse.x < this.fw && mouse.y < this.fh){			if (this.btnHMPointAddMode.isSelected()){				Rectangle sub = new Rectangle(mouse.x-this.subImageSize/2, mouse.y-this.subImageSize/2, this.subImageSize , this.subImageSize);				BufferedImage subImg = ImageTools.getZoomedImage(this.chomoip.getImage(), sub, this.scaleHomoPoint);				HMWorldCoordinatesDialog wcd = new HMWorldCoordinatesDialog(this, true, mouse, new Point2D.Double(), sub, this.scaleHomoPoint, subImg, this.chomoip.getImage().getWidth(), this.chomoip.getImage().getHeight());				Toolkit tk = Toolkit.getDefaultToolkit();				int scrWidth = (int)tk.getScreenSize().getWidth();				int scrHeigth = (int)tk.getScreenSize().getHeight();				int wcdx = (int)(mouse.x + this.chomoip.getLocationOnScreen().getX() + 5);				int wcdy = (int)(mouse.y + this.chomoip.getLocationOnScreen().getY() + 5);				wcdx = wcdx + wcd.getWidth() > scrWidth ? scrWidth - wcd.getWidth() : wcdx;				wcdy = wcdy + wcd.getHeight() > scrHeigth ? scrHeigth - wcd.getHeight() : wcdy;				wcd.setLocation(wcdx, wcdy);				wcd.show();				if (wcd.getResult()){					PointImageWorld piw = new PointImageWorld(wcd.getImageX(), wcd.getImageY(), wcd.getWorldX(), wcd.getWorldY());					this.lstHomoPoints.addElement(piw);					this.chomoip.addPoint(new Point((int)Math.round(wcd.getImageX()), (int)Math.round(wcd.getImageY())));				}			}			else{				this.chomoip.selectNearestPoint(mouse);				this.lstHMPoints.setSelectedIndex(this.chomoip.getSelectedPoint());			}		}	}//GEN-LAST:event_pnlHMImageReferenceMouseClicked	//----------------------------------------------------------------------------------

⌨️ 快捷键说明

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