① java將印章圖片轉換成矢量圖形的方法
1、使用Java內置的圖像處理庫,如JavaAdvancedImaging(JAI)API導入所需的庫和工具。
2、使用Java的ImageIO類來讀取圖像文件。
3、對圖像進行預處理,包括調整圖像大小、平滑處理、邊緣檢測等,從而幫助後續的矢量化過程。
4、使用Java的JAIAPI或第三方庫來進行圖像矢量化。如果提供了現成的演算法將點陣圖轉換為矢量圖形就可以,如果沒有需要手動進行邊緣檢測和路徑創建。
5、使用Java的Graphics2D類或其他繪圖庫來創建矢量圖形對象。
6、以將矢量圖形保存為常見的矢量圖形格式,如SVG或PDF即可。
② 用java編寫一個圖像處理,光線補償 、
寫了很多篇關於圖像處理的文章,沒有一篇介紹Java 2D的圖像處理API,文章討論和提及的
API都是基於JDK6的,首先來看Java中如何組織一個圖像對象BufferedImage的,如圖:
③ 除了python之外,你還應該來了解一下java的圖像處理和人臉識別庫:javacv
javacv技術棧究竟有何作用?
大家對於javacv充滿好奇,恰巧博主對javacv有所研究,以下就來為各位介紹javacv的功能及其在各個領域的優勢。
javacv不僅能處理圖像,其強大的跨平台性和快速開發能力使其在Windows、Mac、Linux、樹莓派嵌入式等多種平台上都能輕松應對圖像處理、人臉檢測識別、字元識別、音視頻流媒體、樹莓派(嵌入式)和深度學習等領域。
圖像處理與識別
在圖像處理與識別方面,javacv通過jni技術實現了opencv圖像檢測識別和tesseract字元識別的跨平台使用,無需再次封裝。
其他方面,如矩陣計算和深度學習,了解不多,不再贅述。
音視頻處理(ffmpeg)
在音視頻處理方面,javacv支持ffmpeg的編解碼、裝封裝等功能,兩者並無太大差異。
嵌入式開發(樹莓派等):
許多人在樹莓派等基於arm晶元的板子上使用javacv,通過外接攝像頭或音頻設備即可實現音視頻上傳、圖像處理、圖像識別等功能。
應用場景廣泛,包括各種圖像採集設備、機器人視覺、人臉打卡和小區門禁等領域。
音視頻流媒體:
利用javacv的流媒體優勢,可實現音視頻採集、推流、編解碼、裝封裝等操作。
深度學習:
deeplearn4j為主的java深度學習框架,在深度學習領域具有一定知名度。
人臉檢測識別:
關於人臉檢測識別的文章在網路上頗為常見,javacv官網的首頁demo也展示了人臉檢測的實例,其功能與opencv相當。
文字識別:
通過Tesseract-OCR可輕松實現字元庫訓練、字元識別。同時,javacv的流媒體屬性和嵌入式開發特性也支持攝像頭的字元識別和視頻圖像的字元識別等場景。
javacv技術棧的應用場景
很多人好奇,javacv在哪些應用場景下得到廣泛應用?
javacv具備跨平台特性,可在Windows、Linux、macOS等伺服器或客戶端機器上運行,並在各種嵌入式板上也能良好工作。
④ java圖像處理 - 圖片上的數字字母圓滑處理方法
抗鋸齒的代碼我倒是有一個,你試一下,輸出圖片第一行是不抗鋸齒的,第二行是抗鋸齒的。
public static void main(String[] args) throws IOException {
BufferedImage image = new BufferedImage(400, 200, BufferedImage.TYPE_4BYTE_ABGR_PRE);
Graphics2D g2d = image.createGraphics();
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, 400, 200);
g2d.setColor(Color.BLACK);
g2d.setFont(new Font("Arial", Font.PLAIN, 37));
g2d.drawString("[email protected]", 10f, 40f);
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);// 設置抗鋸齒效果
g2d.drawString("[email protected]", 10f, 80f);
File outputfile = new File("D:\\TestGraphics.png");
ImageIO.write(image, "PNG", outputfile);
}
⑤ 新手學習使用Java,嘗試著做一個項目使用Java做一個視頻圖像的處理。
Java圖像處理技巧四則
下面代碼中用到的sourceImage是一個已經存在的Image對象
圖像剪切
對於一個已經存在的Image對象,要得到它的一個局部圖像,可以使用下面的步驟:
//import java.awt.*;
//import java.awt.image.*;
Image croppedImage;
ImageFilter cropFilter;
CropFilter =new CropImageFilter(25,30,75,75); //四個參數分別為圖像起點坐標和寬高,即CropImageFilter(int x,int y,int width,int height),詳細情況請參考API
CroppedImage= Toolkit.getDefaultToolkit().createImage(new FilteredImageSource(sourceImage.getSource(),cropFilter));
如果是在Component的子類中使用,可以將上面的Toolkit.getDefaultToolkit().去掉。FilteredImageSource是一個ImageProcer對象。
圖像縮放
對於一個已經存在的Image對象,得到它的一個縮放的Image對象可以使用Image的getScaledInstance方法:
Image scaledImage=sourceImage. getScaledInstance(100,100, Image.SCALE_DEFAULT); //得到一個100X100的圖像
Image doubledImage=sourceImage. getScaledInstance(sourceImage.getWidth(this)*2,sourceImage.getHeight(this)*2, Image.SCALE_DEFAULT); //得到一個放大兩倍的圖像,這個程序一般在一個swing的組件中使用,而類Jcomponent實現了圖像觀察者介面ImageObserver,所有可以使用this。
//其它情況請參考API
灰度變換
下面的程序使用三種方法對一個彩色圖像進行灰度變換,變換的效果都不一樣。一般而言,灰度變換的演算法是將象素的三個顏色分量使用R*0.3+G*0.59+ B*0.11得到灰度值,然後將之賦值給紅綠藍,這樣顏色取得的效果就是灰度的。另一種就是取紅綠藍三色中的最大值作為灰度值。java核心包也有一種演算法,但是沒有看源代碼,不知道具體演算法是什麼樣的,效果和上述不同。
/* GrayFilter.java*/
/*@author:cherami */
/*email:[email protected]*/
import java.awt.image.*;
public class GrayFilter extends RGBImageFilter {
int modelStyle;
public GrayFilter() {
modelStyle=GrayModel.CS_MAX;
canFilterIndexColorModel=true;
}
public GrayFilter(int style) {
modelStyle=style;
canFilterIndexColorModel=true;
}
public void setColorModel(ColorModel cm) {
if (modelStyle==GrayModel
else if (modelStyle==GrayModel
}
public int filterRGB(int x,int y,int pixel) {
return pixel;
}
}
/* GrayModel.java*/
/*@author:cherami */
/*email:[email protected]*/
import java.awt.image.*;
public class GrayModel extends ColorModel {
public static final int CS_MAX=0;
public static final int CS_FLOAT=1;
ColorModel sourceModel;
int modelStyle;
public GrayModel(ColorModel sourceModel) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
modelStyle=0;
}
public GrayModel(ColorModel sourceModel,int style) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
modelStyle=style;
}
public void setGrayStyle(int style) {
modelStyle=style;
}
protected int getGrayLevel(int pixel) {
if (modelStyle==CS_MAX) {
return Math.max(sourceModel.getRed(pixel),Math.max(sourceModel.getGreen(pixel),sourceModel.getBlue(pixel)));
}
else if (modelStyle==CS_FLOAT){
return (int)(sourceModel.getRed(pixel)*0.3+sourceModel.getGreen(pixel)*0.59+sourceModel.getBlue(pixel)*0.11);
}
else {
return 0;
}
}
public int getAlpha(int pixel) {
return sourceModel.getAlpha(pixel);
}
public int getRed(int pixel) {
return getGrayLevel(pixel);
}
public int getGreen(int pixel) {
return getGrayLevel(pixel);
}
public int getBlue(int pixel) {
return getGrayLevel(pixel);
}
public int getRGB(int pixel) {
int gray=getGrayLevel(pixel);
return (getAlpha(pixel)<<24)+(gray<<16)+(gray<<8)+gray;
}
}
如果你有自己的演算法或者想取得特殊的效果,你可以修改類GrayModel的方法getGrayLevel()。
色彩變換
根據上面的原理,我們也可以實現色彩變換,這樣的效果就很多了。下面是一個反轉變換的例子:
/* ReverseColorModel.java*/
/*@author:cherami */
/*email:[email protected]*/
import java.awt.image.*;
public class ReverseColorModel extends ColorModel {
ColorModel sourceModel;
public ReverseColorModel(ColorModel sourceModel) {
super(sourceModel.getPixelSize());
this.sourceModel=sourceModel;
}
public int getAlpha(int pixel) {
return sourceModel.getAlpha(pixel);
}
public int getRed(int pixel) {
return ~sourceModel.getRed(pixel);
}
public int getGreen(int pixel) {
return ~sourceModel.getGreen(pixel);
}
public int getBlue(int pixel) {
return ~sourceModel.getBlue(pixel);
}
public int getRGB(int pixel) {
return (getAlpha(pixel)<<24)+(getRed(pixel)<<16)+(getGreen(pixel)<<8)+getBlue(pixel);
}
}
/* ReverseColorModel.java*/
/*@author:cherami */
/*email:[email protected]*/
import java.awt.image.*;
public class ReverseFilter extends RGBImageFilter {
public ReverseFilter() {
canFilterIndexColorModel=true;
}
public void setColorModel(ColorModel cm) {
substituteColorModel(cm,new ReverseColorModel(cm));
}
public int filterRGB(int x,int y,int pixel) {
return pixel;
}
}
要想取得自己的效果,需要修改ReverseColorModel.java中的三個方法,getRed、getGreen、getBlue。
下面是上面的效果的一個總的演示程序。
/*GrayImage.java*/
/*@author:cherami */
/*email:[email protected]*/
import java.awt.*;
import java.awt.image.*;
import javax.swing.*;
import java.awt.color.*;
public class GrayImage extends JFrame{
Image source,gray,gray3,clip,bigimg;
BufferedImage bimg,gray2;
GrayFilter filter,filter2;
ImageIcon ii;
ImageFilter cropFilter;
int iw,ih;
public GrayImage() {
ii=new ImageIcon(\"images/11.gif\");
source=ii.getImage();
iw=source.getWidth(this);
ih=source.getHeight(this);
filter=new GrayFilter();
filter2=new GrayFilter(GrayModel.CS_FLOAT);
gray=createImage(new FilteredImageSource(source.getSource(),filter));
gray3=createImage(new FilteredImageSource(source.getSource(),filter2));
cropFilter=new CropImageFilter(5,5,iw-5,ih-5);
clip=createImage(new FilteredImageSource(source.getSource(),cropFilter));
bigimg=source.getScaledInstance(iw*2,ih*2,Image.SCALE_DEFAULT);
MediaTracker mt=new MediaTracker(this);
mt.addImage(gray,0);
try {
mt.waitForAll();
} catch (Exception e) {
}