zoukankan      html  css  js  c++  java
  • OpenCV之参数不匹配问题

    多通道图像混合实例

    代码如下:

    //多通道图像混合
    #include<opencv2/opencv.hpp>
    #include<iostream>
    using namespace std;
    using namespace cv;

    bool MultiChannelBlending();

    int main(int argc, char** argv)
    {
    system("color 9F");
    if (MultiChannelBlending())
    {
    cout << endl << " 运行成功,得出了需要的图像~!";
    }
    waitKey(0);
    return 0;
    }
    bool MultiChannelBlending()
    {
    Mat src, logo;
    vector<Mat>channels;
    //-----蓝色部分通道
    Mat imageBlueChannel;
    logo = imread("E:/image/logo.jpg");
    src = imread("E:/image/dota.jpg");
    if (logo.empty())
    {
    cout << "could not load the image..." << endl;
    return -1;
    }
    if (!src.data)
    {
    cout << "could not load the image..." << endl;
    return -1;
    }
    split(src, channels);
    imageBlueChannel = channels.at(0);

    addWeighted(imageBlueChannel(Rect(400, 250, logo.cols, logo.rows)), 1.0, logo, 0.5, 0, imageBlueChannel(Rect(400, 250, logo.cols, logo.rows)));
    merge(channels, src);
    imshow("1.游戏原画+logo蓝色通道", src);
    return true;
    }

    运行时出现了如下错误:Error: Sizes of input arguments do not match (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')中文意思是:输入参数大小不匹配(操作对象既不是'数组对数组的运算'(两个数组必须大小相同、通道数相同),又不是数组与标量的运算,也不是标量与数组的运算))

    经过求证,发现错误出现在两张图片的叠加操作,imageBlueChannel是经过通道分离后得到的一个单通道图像,而logo图像是一个彩色的三通道图像,故无法进行叠加操作,必须将logo图像也转换为单通道图像。

    解决方法如下:

    方法一:logo = imread("E:/image/logo.jpg",0);//以灰度图像的形式打开

    方法二:logo = imread("E:/image/logo.jpg");

               cvtColor(logo, logo, CV_BGR2GRAY);//转换为灰度图像

  • 相关阅读:
    CentOS7.0下Zabbix3.4至Zabbix4.0的升级步骤(Proxy)
    CentOS6.5下Zabbix3.0升级到4.0
    kubernetes相关概念
    更新OpenSSL
    fish 常用主题推荐
    [转] Adobe acrobat 破解教程
    [转]latex符号
    bank conflct 一句话总结
    Ubuntu 安装boost 库
    ubuntu 16.04安装nVidia显卡驱动和cuda/cudnn踩坑过程
  • 原文地址:https://www.cnblogs.com/lbyj/p/12262947.html
Copyright © 2011-2022 走看看