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

  • 相关阅读:
    Android特色开发(3):Google Map
    Android特色开发(4):桌面组件
    Android用户界面开发(19):ProgressBar
    每日英语:Fewer Foreigners Eye US Graduate Science Programs
    每日英语:My Adventures With Liquid Chicken
    每日英语:Hard Math: Adding Up Just How Little We Actually Move
    每日英语:Thousands of Thumbs Down for Chinese Red Cross
    每日英语:Rescuers Struggle to Reach Quake Victims
    每日英语:When Simplicity Is The Solution
    【转】Matlab图像处理函数:regionprops
  • 原文地址:https://www.cnblogs.com/lbyj/p/12262947.html
Copyright © 2020-2023  润新知