Kha*_*war 5 android opencv watermark image image-processing
我一直在尝试将图像添加到所需位置的大图像.我找到了一种通过addWeighted(src,alpha,water, - ,dst, - )在opencv中添加水印的方法,但问题是水印和表面图像应该是我不想要的相同尺寸.
发现另一种方式(我猜)
Mat srcMat = cvCanvasImage.submat(top/2, (top + height)/2, left/2, (left + width)/2);
Imgproc.cvtColor(mat, srcMat, Imgproc.COLOR_GRAY2BGR,4);
Run Code Online (Sandbox Code Playgroud)
但我不明白怎么做?
谢谢..
UPDATE
Mat cvCanvasImage = Highgui.imread(Environment.getExternalStorageDirectory() + "/wallpapers/castle.jpg");
// Small watermark image
Mat cvWaterImage = Highgui.imread(Environment.getExternalStorageDirectory() +"/square.png");
Size canvasSize = cvWaterImage.size();
int rows = (int) canvasSize.height;
int cols = (int) canvasSize.width;
int left = 0;
int top = 0;
int width = rows;
int height = cols;
Rect ROI = new Rect(left, top, width, height);
Core.addWeighted(cvCanvasImage.submat(ROI), alpha, cvWaterImage, beta, 0, cvCanvasImage.submat(ROI));
//now it throws me this error
"error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function void cv::arithm_op(const cv::_InputArray&, const cv::_InputArray&, const cv::_OutputArray&, const cv::_InputArray&, int, void (**)(const uchar*, size_t, const uchar*, size_t, uchar*, size_t, cv::Size, void*), bool, void*)"
Run Code Online (Sandbox Code Playgroud)
我找到了一种正确的方法.
Mat b = Highgui.imread(Environment.getExternalStorageDirectory() + "/castle.jpg");
// Small watermark image
Mat a = Highgui.imread(Environment.getExternalStorageDirectory() +"/square.png");
Mat bSubmat = b.submat(a.rows(), a.rows()*2, a.cols(), a.cols()*2);
a.copyTo(bSubmat);
Highgui.imwrite("mnt/sdcard/SubmatCopyToTest.png", b);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4645 次 |
| 最近记录: |