第一个程序很简单,图像显示。
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<iostream>
using namespace cv;
using namespace std;
int main()
{
Mat image;
image = imread("F:\\1.jpg");
imwrite("1.jpg", image);
namedWindow("显示图像");
imshow("显示图像", image);
waitKey(0);
return 0;
}
图像混合代码
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
int main()
{
//显示图像代码
Mat girl;
girl = imread("girl.jpg");
namedWindow("女孩图");
imshow("显示图像", girl);
//图像混合代码
Mat logo=imread("dota.jpg");
Mat image = imread("dota_logo.jpg");
namedWindow("logo图");
imshow("显示logo", logo);
namedWindow("dota图");
imshow("显示dota", image);
//图像混合
Mat imagerol;
imagerol = image(Rect(800, 350, image.cols, image.rows));
addWeighted(imagerol, 0.5, logo, 0.3, 0., imagerol);
namedWindow("混合图");
imshow("显示混合图", image);
//图像存入工程中
imwrite("混合图.jpg", image);
waitKey(0);
return 0;
}
#include<iostream>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
using namespace cv;
using namespace std;
#define WINDOW_NAME "显示图像"
const int g_maxvalue = 100;
int g_nowvalue;
double g_rate1;
double g_rate2;
Mat image1;
Mat image2;
Mat dstimage;
void trackbar(int, void*)
{
g_rate1 = (double)g_nowvalue / g_maxvalue;
g_rate2 = 1 - g_rate2;
namedWindow(WINDOW_NAME,1);
addWeighted(image1, g_rate1, image2, g_rate2, 0.0, dstimage);
imshow(WINDOW_NAME, dstimage);
}
int main()
{
image1 = imread("3.jpg");
image2 = imread("4.jpg");
g_nowvalue = 70;
namedWindow(WINDOW_NAME, 1);
createTrackbar("透明度", WINDOW_NAME, &g_nowvalue, g_maxvalue, trackbar);
trackbar(g_nowvalue,0);
waitKey(0);
return 0;
}
创建滑动条的图像混合的代码