導航:首頁 > 編程語言 > java搜索圖片

java搜索圖片

發布時間:2025-06-12 03:12:52

❶ 如何使用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中以圖搜圖技術的詳細解答:

  1. 技術基礎

    • 圖像識別:以圖搜圖技術首先需要對圖像進行識別,這通常依賴於深度學習模型,特別是卷積神經網路,它們能夠提取圖像中的關鍵特徵,如邊緣、紋理等。
    • 相似度匹配:在特徵提取之後,系統需要計算這些特徵之間的相似度,以找到與查詢圖像最相似的圖像。這通常涉及到特徵向量之間的距離計算,如歐氏距離或餘弦相似度等。
  2. 功能流程

    • 圖片入庫:用戶可以將圖片上傳到系統,系統會對這些圖片進行特徵提取,並將特徵值存入向量資料庫中。這個過程包括特徵提取和特徵入庫兩個步驟。
    • 圖片檢索:當用戶上傳一張查詢圖片時,系統會再次進行特徵提取,並在向量資料庫中檢索與查詢圖片特徵最相似的圖片。檢索結果會按照相似度進行排序,並返回給用戶。
  3. 應用場景

    • 電子商務:在電商平台上,用戶可以通過上傳一張圖片來搜索與之相似的商品。
    • 社交媒體:在社交媒體上,用戶可以利用以圖搜圖功能來查找包含相同或相似圖像的內容。
    • 設計領域:設計師可以使用以圖搜圖來尋找靈感或相似的設計元素。
  4. 技術優勢

    • 高效性:深度學習模型在特徵提取和相似度計算方面的高效性,使得以圖搜圖技術能夠快速返回搜索結果。
    • 准確性:通過提取圖像的高維特徵並進行精細的相似度計算,以圖搜圖技術能夠提供准確的搜索結果。
  5. 實現方式

    • 在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(); } %>

閱讀全文

與java搜索圖片相關的資料

熱點內容
八卦匯總421頁pdf 瀏覽:286
android應用自動升級 瀏覽:747
遠程屏幕監控源碼 瀏覽:569
雲伺服器的ip怎麼查詢 瀏覽:155
大學c語言搜題app在哪裡下載 瀏覽:109
pdf文檔被保護 瀏覽:345
有沒有電腦公司網站源碼下載 瀏覽:230
智能電視哪個app看電影好用 瀏覽:224
微信頁面源碼下載 瀏覽:957
怎麼看5代噴頭加密 瀏覽:359
linux查找文件並刪除文件 瀏覽:872
單片機里的編程軟體 瀏覽:164
鑽石投票網站源碼 瀏覽:973
cidrphp 瀏覽:882
android測試用例文檔 瀏覽:820
單片機素數 瀏覽:838
怎麼在桌面上發送文件夾 瀏覽:759
海外貸款源碼 瀏覽:717
北航單片機實驗 瀏覽:799
私有雲伺服器在哪裡 瀏覽:939