本文介绍了添加水印的小图片大图opencv4android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在试图将图像添加到大的图像,在需要的位置。我找到了一种方法做addWeighted添加水印的OpenCV(SRC,阿尔法,水, - ,DST, - ),但问题是,这两个水印和表面形象应该是,我不希望同样的尺寸。
找到另一种方式(我猜)
垫srcMat = cvCanvasImage.submat(前/ 2,(上+高)/ 2,左/ 2,(左+宽)/ 2);
Imgproc.cvtColor(垫,srcMat,Imgproc.COLOR_GRAY2BGR,4);
但我不知道如何做到这一点?
谢谢..
更新
垫cvCanvasImage = Highgui.imread(Environment.getExternalStorageDirectory()+/wallpapers/castle.jpg);
//小水印图像
垫cvWaterImage = Highgui.imread(Environment.getExternalStorageDirectory()+/ square.png);
大小canvasSize = cvWaterImage.size();
INT行数=(INT)canvasSize.height;
INT COLS =(INT)canvasSize.width;
INT左= 0;
INT顶端= 0;
INT宽度=行;
INT高= COLS;
矩形的投资回报率=新的矩形(左,上,宽,高);
Core.addWeighted(cvCanvasImage.submat(ROI),α,cvWaterImage,β,0,cvCanvasImage.submat(ROI));
//现在它抛出我这个错误
错误:(-209)的动作既不是'数组运算数组'(其中阵列具有相同的尺寸和通道的数量相同),也不是'数组运算标量,也不能在函数void品种'的标量运算阵列':: arithm_op(常量CV :: _ InputArray和放大器;,常量CV :: _ InputArray和放大器;,常量CV :: _ OutputArray和放大器;,常量CV :: _ InputArray和放大器;,INT,无效(**)(常量UCHAR *,为size_t,常量UCHAR *,为size_t, UCHAR *,为size_t,CV ::大小,无效*),布尔,无效*)
解决方案
我找到了一种方法做是正确的。
板坯B = Highgui.imread(Environment.getExternalStorageDirectory()+/castle.jpg);
//小水印图像
垫上= Highgui.imread(Environment.getExternalStorageDirectory()+/ square.png);
垫bSubmat = b.submat(a.rows(),a.rows()* 2,a.cols(),a.cols()* 2);
a.copyTo(bSubmat);
Highgui.imwrite(MNT / SD卡/ SubmatCopyToTest.png,B);
I've been trying to add an image to large image at desired position. I found a way to add watermark in opencv by doing addWeighted(src, alpha, water,--,dst,--), but the problem is that both watermark and surface image should be of same sizes which I don't want.
Found another way (I guess)
Mat srcMat = cvCanvasImage.submat(top/2, (top + height)/2, left/2, (left + width)/2);
Imgproc.cvtColor(mat, srcMat, Imgproc.COLOR_GRAY2BGR,4);
But I don't understand how to do this??
Thanks..
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*)"
解决方案
I found a way to do it right.
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);
这篇关于添加水印的小图片大图opencv4android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!