` public void encode(String image, String watermark, String output) {
// Mat src = Utils.read(image, CV_8S);
//
// List channel = new ArrayList<>(3);
// List newChannel = new ArrayList<>(3);
// split(src, channel);
//
// for (int i = 0; i < 3; i++) {
// Mat com = this.converter.start(channel.get(i)).clone();
// this.addWatermark(com, watermark);
// this.converter.inverse(com);
// newChannel.add(i, com);
// }
//
// Mat res = new Mat();
// merge(newChannel, res);
//
// if (res.rows() != src.rows() || res.cols() != src.cols()) {
// res = new Mat(res, new Rect(0, 0, src.width(), src.height()));
// }
//
// imwrite(output, res);
Mat src = Utils.read(image, CV_8S);
Mat res = new Mat();
Mat padded = splitSrc(src);
planes.add(padded);
planes.add(1, Mat.zeros(padded.size(), CV_32F));
merge(planes, res);
dft(res, res);
Scalar s = new Scalar(0, 0, 0, 0);
Point p = new Point(res.cols() / 3, res.rows() / 3);
putText(res, watermark, p, FONT_HERSHEY_COMPLEX, 1.0, s, 3,
8, false);
flip(res, res, -1);
putText(res, watermark, p, FONT_HERSHEY_COMPLEX, 1.0, s, 3,
8, false);
flip(res, res, -1);
Mat invDFT = new Mat();
idft(res, invDFT, Core.DFT_SCALE | Core.DFT_REAL_OUTPUT, 0);
Mat restoredImage = new Mat();
invDFT.convertTo(restoredImage, 0);
if (allPlanes.size() == 0) {
allPlanes.add(restoredImage);
} else {
allPlanes.add(0, restoredImage);
}
Mat lastImage = new Mat();
merge(allPlanes, lastImage);
imwrite(output, lastImage);
}`
2、运行的时候报错
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.1.2) /Users/travis/build/bytedeco/javacpp-presets/opencv/cppbuild/macosx-x86_64/opencv-4.1.2/modules/core/src/merge.dispatch.cpp:129: error: (-215:Assertion failed) mv[i].size == mv[0].size && mv[i].depth() == depth in function 'merge' ] at org.opencv.core.Core.merge_0(Native Method) at org.opencv.core.Core.merge(Core.java:4067) at com.example.demo.converter.DftConverter.merge11(DftConverter.java:109) at com.example.demo.dencoder.Encoder.encode(Encoder.java:83) at com.example.demo.BlindWatermark.main(BlindWatermark.java:53)
1、首先我改encode的代码 是因为你的代码dft的文字盲水印耗时需要3s 以上,我加了些优化的代码
` public void encode(String image, String watermark, String output) { // Mat src = Utils.read(image, CV_8S); // // List channel = new ArrayList<>(3);
// List newChannel = new ArrayList<>(3);
// split(src, channel);
//
// for (int i = 0; i < 3; i++) {
// Mat com = this.converter.start(channel.get(i)).clone();
// this.addWatermark(com, watermark);
// this.converter.inverse(com);
// newChannel.add(i, com);
// }
//
// Mat res = new Mat();
// merge(newChannel, res);
//
// if (res.rows() != src.rows() || res.cols() != src.cols()) {
// res = new Mat(res, new Rect(0, 0, src.width(), src.height()));
// }
//
// imwrite(output, res);
2、运行的时候报错
Exception in thread "main" CvException [org.opencv.core.CvException: cv::Exception: OpenCV(4.1.2) /Users/travis/build/bytedeco/javacpp-presets/opencv/cppbuild/macosx-x86_64/opencv-4.1.2/modules/core/src/merge.dispatch.cpp:129: error: (-215:Assertion failed) mv[i].size == mv[0].size && mv[i].depth() == depth in function 'merge' ] at org.opencv.core.Core.merge_0(Native Method) at org.opencv.core.Core.merge(Core.java:4067) at com.example.demo.converter.DftConverter.merge11(DftConverter.java:109) at com.example.demo.dencoder.Encoder.encode(Encoder.java:83) at com.example.demo.BlindWatermark.main(BlindWatermark.java:53)
3、如果我还原成你的就可以正常执行 ,所以我想问下 ,为什么我基于你的类库改的 ,为什么我运行不起来呢 ?