安裝opencv
匯入jar包需要dll
剪輯圖片
package opencv;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Rect;
import org.opencv.imgcodecs.Imgcodecs;
public class Test5 {
static {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);//加載庫,否則會出錯
}
public static void main(String[] args) {
int x = 10;//剪輯的x坐標
int y = 10;//剪輯的y坐標
int w = 110;//剪輯的寬度
int h = 90;//剪輯的高度
Mat mat = Imgcodecs.imread("D:\\1.png");//原始圖片
Mat m = new Mat(mat, new Rect(x, y, w, h));//剪輯之后的圖片
Imgcodecs.imwrite("D:\\2.png", m);//寫入圖片
}
}
結果
原始圖片(D:\1.png)

剪輯之后的圖片(D:\2.png)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/290193.html
標籤:其他
下一篇:一篇文章學會輪廓檢測
