日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Opencv第四讲:分离合并通道

發布時間:2024/3/24 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Opencv第四讲:分离合并通道 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

前言:

開發環境:win10 Visual Studio 2017

開發語言:C++

編譯器:Debug X64

Opencv版本:4.1.1

代碼實現:

#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp>using namespace cv; using namespace std;bool MultiChannelBlending();int main() {system("color 0F");if (MultiChannelBlending()){cout << endl << "OK! Please start your performance ! ";}while (1){if (waitKey(100) == 27)break;} }bool MultiChannelBlending() {Mat Background, Bull, Rocket, Celts, Toronto, NewYork, Pelicans;Mat BlueChannelsBackground, BlueChannelsBull, BlueChannelsSpur;Mat GreenChannelsBackground, GreenChannelsCelts, GreenChannelsToronto;Mat RedChannelsBackground,RedChannelsNewYork, RedChannelsPelicans;vector<Mat>ChannelsBackground, ChannelsBull, ChannelsSpur, ChannelsCelts, ChannelsToronto, ChannelsNewYork, ChannelsPelicans;//【1】讀入圖片Background = imread("D:\\vs2017_Project\\5th-Separate_and_combine_channels\\背景.png");Bull = imread("D:\\vs2017_Project\\5th-Separate_and_combine_channels\\bull.png");Rocket = imread("D:\\vs2017_Project\\5th-Separate_and_combine_channels\\火箭.png");Celts = imread("D:\\vs2017_Project\\5th-Separate_and_combine_channels\\凱爾特人.png");Toronto = imread("D:\\vs2017_Project\\5th-Separate_and_combine_channels\\猛龍.png");NewYork = imread("D:\\vs2017_Project\\5th-Separate_and_combine_channels\\NewYork.png");Pelicans = imread("D:\\vs2017_Project\\5th-Separate_and_combine_channels\\鵜鶘.png");//【2】把一個3通道圖像轉換成3個單通道圖像split(Background, ChannelsBackground);//分離色彩通道split(Bull, ChannelsBull);//分離色彩通道split(Rocket, ChannelsSpur);//分離色彩通道split(Celts, ChannelsCelts);//分離色彩通道split(Toronto, ChannelsToronto);//分離色彩通道split(NewYork, ChannelsNewYork);//分離色彩通道split(Pelicans, ChannelsPelicans);//分離色彩通道//【3】將原圖的某通道引用返回給imageBlueChannel,注意是引用,相當于兩者等價,修改其中一個另一個跟著變// 【3-1】藍色通道BlueChannelsBackground = ChannelsBackground.at(0);BlueChannelsBull = ChannelsBull.at(2);BlueChannelsSpur = ChannelsSpur.at(0);// 【3-2】綠色通道GreenChannelsBackground = ChannelsBackground.at(1);GreenChannelsCelts = ChannelsCelts.at(1);GreenChannelsToronto = ChannelsToronto.at(1);// 【3-3】紅色通道RedChannelsBackground = ChannelsBackground.at(2);RedChannelsNewYork = ChannelsNewYork.at(2);RedChannelsPelicans = ChannelsPelicans.at(2);//【4】將原圖的某通道的某坐標處下的一塊區域和logo圖進行加權操作,將得到的混合結果存到對應背景圖的通道中// 【4-1】藍色通道addWeighted(BlueChannelsBackground(Rect(0, 220, Bull.cols, Bull.rows)), 1.0, BlueChannelsBull, 0.5, 0,BlueChannelsBackground(Rect(0, 220, Bull.cols, Bull.rows)));addWeighted(BlueChannelsBackground(Rect(0, 0, Rocket.cols, Rocket.rows)), 1.0, BlueChannelsSpur, 0.5, 0,BlueChannelsBackground(Rect(0, 0, Rocket.cols, Rocket.rows)));// 【4-2】綠色通道addWeighted(GreenChannelsBackground(Rect(220, 0, Celts.cols, Celts.rows)), 1.0,GreenChannelsCelts, 0.5, 0, GreenChannelsBackground(Rect(220, 0, Celts.cols, Celts.rows)));addWeighted(GreenChannelsBackground(Rect(220, 220, Toronto.cols, Toronto.rows)), 1.0,GreenChannelsToronto, 0.5, 0, GreenChannelsBackground(Rect(220, 220, Toronto.cols, Toronto.rows)));// 【4-3】紅色通道addWeighted(RedChannelsBackground(Rect(440, 0, NewYork.cols, NewYork.rows)), 1.0, RedChannelsNewYork, 0.5, 0, RedChannelsBackground(Rect(440, 0, NewYork.cols, NewYork.rows)));addWeighted(RedChannelsBackground(Rect(440, 220, Pelicans.cols, Pelicans.rows)), 1.0, RedChannelsPelicans, 0.5, 0, RedChannelsBackground(Rect(440, 220, Pelicans.cols, Pelicans.rows)));//【5】將三個單通道重新合并成一個三通道merge(ChannelsBackground, Background); // 注意,這里是將三個合并后的單通道再次合并為一個三通道,只需要一步操作!//【6】顯示效果圖imshow("NBA", Background);return true; }

結果:

參考資料:

https://blog.csdn.net/poem_qianmo/article/details/21176257

https://blog.csdn.net/gdfsg/article/details/50927257

總結

以上是生活随笔為你收集整理的Opencv第四讲:分离合并通道的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。