質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -77,3 +77,65 @@
|
|
77
77
|
参考にしたサイトはhttps://qiita.com/livlea/items/a853c374d6d91b33f5fe
|
78
78
|
|
79
79
|
です。
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
##追記
|
84
|
+
|
85
|
+
回答者の方が仰るように変更したソースがこちらです。
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
package test;
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
import org.opencv.core.Core;
|
94
|
+
|
95
|
+
import org.opencv.core.Mat;
|
96
|
+
|
97
|
+
import org.opencv.imgcodecs.Imgcodecs;
|
98
|
+
|
99
|
+
import org.opencv.imgproc.Imgproc;
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
public class imgConv {
|
104
|
+
|
105
|
+
static{
|
106
|
+
|
107
|
+
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
public static void main(String[] args) {
|
114
|
+
|
115
|
+
String path_in = "C:/7f585617.jpg";
|
116
|
+
|
117
|
+
String path_out = "C:/7f585617_gray.jpg";
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
Mat mat_src = new Mat();
|
122
|
+
|
123
|
+
Mat mat_dst = new Mat();
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
mat_src = Imgcodecs.imread(path_in); // 入力画像の読み込み
|
128
|
+
|
129
|
+
Imgproc.cvtColor(mat_src, mat_dst, Imgproc.COLOR_BGR2GRAY); // カラー画像をグレー画像に変換
|
130
|
+
|
131
|
+
Imgcodecs.imwrite(path_out, mat_dst); // 出力画像を保存
|
132
|
+
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
補足情報にのせたURLのようにグレー画像が出力されませんでした。しかしエラーは何も出ませんでした。これはjpgなのが悪いのかOpenCVが上手く使えていないからなのか、それとも他に理由があるのかわかりません。
|