opencv是一个C++语言库,对于java程序员来说,貌似不是很友好;不过java程序员可以利用jni调用的方式来处理
for example:
1 | public static void main1(String[] args) throws Exception { |
1 | /** |
图像掩模1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24static Scalar WHITE = new Scalar(255,255,255);
/**
* 图像掩模
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
NativeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Mat kittens = imread("images/tools.jpg");
Imgproc.cvtColor(kittens, kittens, Imgproc.COLOR_RGB2GRAY);
Imgproc.Canny(kittens, kittens, 100.0, 300.0, 3, true);
bitwise_not(kittens, kittens);
// System.out.println(kittens.dump());
Mat target = new Mat(kittens.height(), kittens.width(), CvType.CV_8UC3, WHITE);
Mat bg = imread("images/light-blue-gradient.jpg");
Imgproc.resize(bg, bg, target.size());
bg.copyTo(target, kittens);
imwrite("output/kittens-03.png", target);
}