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

📄 imagepanel.java

📁 JAVA 实现虹膜识别(完整)
💻 JAVA
字号:
package IrisRecog;/** * ImagePanel.java *  * Extends the functionality of the JPanel swing component to be able to draw * pnt_Centered images in the panel. This class overrides the paintComponent method * and handles its own drawing. * * @owner Michael Huffman * @author Team 6: A. Bare, I. Chaugule,M. Huffman, M. Pearson, C. Schell * @version 0.0.1 * * 	CSC 480 Section 2 * 	Fall 2005 * 	10/8/05 * * Edit History: *  10/8/05 - created *  10/9/05 - documented and commented */ import java.awt.*;import javax.swing.*;import javax.swing.border.*;import java.util.*;public class ImagePanel extends JPanel {	/*	 * The grayscale version of the image being show in the panel.	 */	protected Image img_Image;			/*	 * Value indicating if the the pupil pnt_Center should be drawn	 */	protected boolean bln_DrawCenter;		/*	 * Value indicating if the iris should be drawn	 */	protected boolean bln_DrawIris;		/*	 * Value indicating if the pupil should be drawn	 */	protected boolean bln_DrawPupil;		/* 	 * Value indicating if the pupil localization should be drawn	 */	protected boolean bln_DrawLocalization;		/* 	 * The pupil pnt_Center point of the eye image.	 */	protected Point pnt_Center;		/*	 * The radius of the pupil to draw	 */	protected double dbl_PupilRadius;		/*	 * The radius of the iris to draw	 */	protected double dbl_IrisRadius;	/**	 * Creates an image panel with lowered bevel and white background.	 */	public ImagePanel()	{				this.img_Image = null;		this.dbl_PupilRadius = 0.0;		this.dbl_IrisRadius = 0.0;		this.pnt_Center = new Point(0,0);		this.bln_DrawCenter = false;		this.bln_DrawIris = false;		this.bln_DrawPupil = false;		this.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));		this.setBackground(Constants.CLR_DEFAULT_BACKGROUND);	}		/**	 * Sets the image to be shown in the panel and whether to show the original	 * or the grayscale version.	 *	 * @param i The grayscale image object	 * @param vOriginal True to view the original color image, or false to 	 *                  view the grayscale version	 */	public void setImage(Image i)	{		this.img_Image = i;		this.pnt_Center = new Point(0,0);		this.dbl_PupilRadius = 0.0;		this.dbl_IrisRadius = 0.0;		this.bln_DrawCenter = false;		this.bln_DrawIris = false;		this.bln_DrawPupil = false;		this.repaint();	}	/**	 * Sets whether the pupil pnt_Center point is drawn and its value	 *	 * @param p The pupil pnt_Center point	 */	public void drawCenter(Point p)	{		this.pnt_Center = p;		this.bln_DrawCenter = true;	}		/**	 * Sets the radius of the iris to be drawn on the image.	 * 	 * @param irisR The iris radius	 */	public void drawIrisRadius(double irisR)	{		this.bln_DrawIris = true;		this.dbl_IrisRadius = irisR;		}		/**	 * Sets the radius of the pupil to be drawn on the image.	 * 	 * @param pupilR The pupil radius	 */	public void drawPupilRadius(double pupilR)	{		this.bln_DrawPupil = true;		this.dbl_PupilRadius = pupilR;	}		/**	 * Sets the radius of the pupil to be drawn on the image.	 * 	 * @param pupilR The pupil radius	 */	public void drawLocalization()	{		this.bln_DrawLocalization = true;	}		/**	 * Overrides the default paintComponent method and draws the image	 * that is to be shown in the panel in the pnt_Center (in eithe grayscale 	 * or color and with or without the pupil pnt_Center drawn).	 *	 * @param g The graphics object of this panel	 */	public void paintComponent(Graphics g) 	{ 		//Clear the contents of the panel		g.clearRect(0, 0, this.getWidth(), this.getHeight());				//If the image of the panel has been set		if(img_Image!=null)  		{			ImageIcon icn_ScaledImage; //the image icon used to scale			double dbl_Scale;	   //the percentage amount of scaling exhbited to fit in the panel			int int_VertOffset;		   //the amount the image is shifted down to be pnt_Centered vertically			icn_ScaledImage = new ImageIcon(this.img_Image.getScaledInstance(this.getWidth(), -1, Image.SCALE_DEFAULT));			//Calculate the distance the image needs to be shifted down			int_VertOffset = (this.getHeight() / 2) - (icn_ScaledImage.getIconHeight() / 2);			//Calculate the amount that the image is scaled			dbl_Scale = (this.getWidth() * 1.0) / img_Image.getWidth(null);			//Scale the image and paint it using the graphics object of this panel component			icn_ScaledImage.paintIcon(this, g, 0, int_VertOffset);						//If the pupil pnt_Center is to be drawn			if(bln_DrawCenter)			{				g.setColor(Color.red);								g.drawLine((int)((pnt_Center.getX()*dbl_Scale-8)), (int)(pnt_Center.getY()*dbl_Scale) + int_VertOffset, (int)((pnt_Center.getX()*dbl_Scale+8)), (int)(pnt_Center.getY()*dbl_Scale) + int_VertOffset );				g.drawLine((int)(pnt_Center.getX()*dbl_Scale), (int)((pnt_Center.getY()*dbl_Scale-8)) + int_VertOffset, (int)(pnt_Center.getX()*dbl_Scale), (int)((pnt_Center.getY()*dbl_Scale+8)) + int_VertOffset);			}						if(bln_DrawLocalization)			{				g.setColor(Color.orange);								g.drawOval( (int)((pnt_Center.getX() - dbl_PupilRadius) * dbl_Scale), (int)((pnt_Center.getY() - dbl_PupilRadius) * dbl_Scale) + int_VertOffset, (int)(2 * dbl_PupilRadius * dbl_Scale),  (int)(2 * dbl_PupilRadius * dbl_Scale));				g.drawOval( (int)((pnt_Center.getX() - dbl_IrisRadius) * dbl_Scale), (int)((pnt_Center.getY() - dbl_IrisRadius) * dbl_Scale) + int_VertOffset, (int)(2 * dbl_IrisRadius * dbl_Scale),  (int)(2 * dbl_IrisRadius * dbl_Scale));			}			else			{				double dbl_PupilTrueRadius = (dbl_PupilRadius * Globals.LOCALIZATION_PERCENTAGE);				double dbl_IrisTrueRadius = (dbl_IrisRadius * (1/Globals.LOCALIZATION_PERCENTAGE));								//If the radii are to be drawn				if(bln_DrawPupil)				{					g.setColor(Color.magenta);											g.drawOval( (int)((pnt_Center.getX() - dbl_PupilTrueRadius) * dbl_Scale), (int)((pnt_Center.getY() - dbl_PupilTrueRadius) * dbl_Scale) + int_VertOffset, (int)(2 * dbl_PupilTrueRadius * dbl_Scale),  (int)(2 * dbl_PupilTrueRadius * dbl_Scale));				}								if(bln_DrawIris)				{					g.setColor(Color.blue);											g.drawOval( (int)((pnt_Center.getX() - dbl_IrisTrueRadius) * dbl_Scale), (int)((pnt_Center.getY() - dbl_IrisTrueRadius) * dbl_Scale) + int_VertOffset, (int)(2 * dbl_IrisTrueRadius * dbl_Scale),  (int)(2 * dbl_IrisTrueRadius * dbl_Scale));				}			}		}  	} }

⌨️ 快捷键说明

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