❶ 如何使用java實現屏幕找圖功能
測試代碼
[java] view plain
public static void main(String[] args) throws Exception {
findImage4FullScreen(ImageCognition.SIM_ACCURATE_VERY);
}
public static void findImage4FullScreen(int sim) throws Exception {
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int w = (int) screenSize.getWidth();
int h = 200;
Robot robot = new Robot();
BufferedImage screenImg = robot.createScreenCapture(new Rectangle(0, 0,
w, h));//對屏幕指定范圍進行截圖,保存到BufferedImage中
OutputStream out = new FileOutputStream("data/images/screen.png");
ImageIO.write(screenImg, "png", out);//將截到的BufferedImage寫到本地
InputStream in = new FileInputStream("data/images/search.png");
BufferedImage searchImg = ImageIO.read(in);//將要查找的本地圖讀到BufferedImage
//圖片識別工具類
ImageCognition ic = new ImageCognition();
List<CoordBean> list = ic.imageSearch(screenImg, searchImg, sim);
for (CoordBean coordBean : list) {
System.out.println("找到圖片,坐標是" + coordBean.getX() + ","
+ coordBean.getY());
//標注找到的圖的位置
Graphics g = screenImg.getGraphics();
g.setColor(Color.BLACK);
g.drawRect(coordBean.getX(), coordBean.getY(),
searchImg.getWidth(), searchImg.getHeight());
g.setFont(new Font(null, Font.BOLD, 20));
g.drawString("←找到的圖片在這里",
coordBean.getX() + searchImg.getWidth() + 5,
coordBean.getY() + 10 + searchImg.getHeight() / 2);
out = new FileOutputStream("data/images/result.png");
ImageIO.write(screenImg, "png", out);
}
}
額外的類
CoordBean
package cn.xt.imgCongnition;
public class CoordBean {
private int x;
private int y;
/**
* 獲取x坐標
*
* @return x坐標
*/
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
/**
* 獲取y坐標
*
* @return
*/
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
}
RgbImageComparerBean
package cn.xt.imgCongnition;
/**
* RGB 相關,圖片相似度計算時使用
*
*/
public class RgbImageComparerBean {
/****** 顏色值數組,第一緯度為x坐標,第二緯度為y坐標 ******/
private int colorArray[][];
/*** 是否忽略此點,若為true,則不納入比較的像素行列。 ***/
private boolean ignorePx[][];
/**** 圖片的寬高 ****/
private int imgWidth;
private int imgHeight;
// 圖片的像素總數
private int pxCount;
/**
* 獲取圖像的二維數組組成
*
* @return 圖像的二維數組
*/
public int[][] getColorArray() {
return colorArray;
}
/**
* 要對比的像素總數,會自動篩選掉不對比的顏色
*
* @param pxCount
*/
public void setPxCount(int pxCount) {
this.pxCount = pxCount;
}
/**
* 設置顏色二維數組
*
* @param colorArray
* 顏色二維數組,一維為x軸,二維為y軸
*/
public void setColorArray(int[][] colorArray) {
this.colorArray = colorArray;
this.imgWidth = this.colorArray.length;
this.imgHeight = this.colorArray[0].length;
this.pxCount = this.imgWidth * this.imgHeight;
}
/**
* 是否忽略此點,若為true,則不納入像素比較行列。
*
* @return 具體x,y坐標的那個像素點
*/
public boolean[][] getIgnorePx() {
return ignorePx;
}
/**
* 是否忽略此點,若為true,則不納入像素比較行列。
*
* @param ignorePx
* 具體x,y坐標的那個像素點
*/
public void setIgnorePx(boolean[][] ignorePx) {
this.ignorePx = ignorePx;
}
/**
* 獲取圖像的寬度
*
* @return 圖像寬度
*/
public int getImgWidth() {
return imgWidth;
}
/**
* 獲取圖像的高度
*
* @return 圖像高度
*/
public int getImgHeight() {
return imgHeight;
}
/**
* 獲取圖像里像素的總數
*
* @return
*/
public int getPxCount() {
return pxCount;
}
}
❷ 請教如何用Java語言讀取jpg圖片,並顯示
1、獲取文件夾的路徑 2、得到文件夾中的有圖片的名稱,可以存到數組或者集合中 3、你再到jsp頁面做顯示, 4、下面是獲取路徑和文件名的代碼,前台顯示的代碼自己寫 String path = 文件夾路徑; String names = ""; try { File f = new File(path)
❸ Java Web AI - 以圖搜圖
Java Web AI中的以圖搜圖技術,是一種基於圖像識別與相似度匹配的功能,允許用戶通過上傳圖片來搜索與之相似的圖片或信息。以下是關於Java Web AI中以圖搜圖技術的詳細解答:
技術基礎:
功能流程:
應用場景:
技術優勢:
實現方式:
❹ JAVA怎麼把圖片從資料庫中調用出來
1 一半圖片都是把路徑存放在資料庫的 到時候取出路徑就可以了
2 在資料庫有blob格式可以存放圖片 以二進制流的方式取出來
<% String zjbm = CheckParam(request.getParameter("zjbm"),""); String zpSql = "select zp from tjjryxxx where sfzh = '"+zjbm+"'"; out.clear(); response.setContentType("image/jpeg"); response.setHeader("Content-Transfer-Encoding","base64"); Connection connection = null; PreparedStatement ps = null; ResultSet rs = null; Blob blob =null; byte[] data = null; try{ connection =getConn(); ps = connection.prepareStatement(zpSql); rs = ps.executeQuery(); while(rs.next()){ blob = (Blob)rs.getBlob("zp"); long nlen = blob.length(); int nsize = (int) nlen; data = blob.getBytes(1,nsize); OutputStream out1 = response.getOutputStream(); BufferedOutputStream bos =null; bos = new BufferedOutputStream(out1); bos.write(data,0,data.length); bos.close(); rs.close(); } }catch(Exception e){ e.printStackTrace(); } %>