【问题标题】:add watermark small image to large image opencv4android将水印小图像添加到大图像opencv 4 android
【发布时间】:2012-09-25 03:57:35
【问题描述】:

我一直在尝试将图像添加到所需位置的大图像中。我找到了一种通过 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);

但我不明白该怎么做??

谢谢..

更新

     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*)"

【问题讨论】:

    标签: android image opencv image-processing watermark


    【解决方案1】:

    这样的事情应该可以工作:

    Mat waterMark = new Mat(width, height); //assumed as a smaller image than your source mat, with size (width, height).
    
    Rect ROI = new Rect(x, y, width, height); // Position and size of your watermark;
    
    Core.addWeighted(source.submat(ROI), alpha, waterMark, beta, gamma, source.submat(ROI));
    

    【讨论】:

    • 我已经应用了你的方法并更新了我的问题,请看一下。无论如何感谢您的快速响应。
    【解决方案2】:

    我找到了正确的方法。

    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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-01
      • 1970-01-01
      相关资源
      最近更新 更多