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);//转换为灰度图像

  • 相关阅读:
    mq和kafaka架构方面对比高可用性
    一 mq简介
    gtibook 写api文档
    StackExchang.Redis 不稳定
    Log4Net 帮助类
    Android学习之Recyclerview
    《程序员修炼之道--从小工到专家》读书小计
    Xcode7 使用WebView loadRequest发送HTTP请求的问题
    ashx中应用HttpContext.Current.Session ,呈现未将对象引用设置到实例(转)
    Oracle 删除重复数据只留一条【转】
  • 原文地址:https://www.cnblogs.com/lbyj/p/12262947.html
Copyright © 2011-2022 走看看