首页 > 代码库 > qt+opencv对两幅图片进行融合
qt+opencv对两幅图片进行融合
本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.
源代码:
[cpp] view plain copy
- #include "widget.h"
- #include "ui_widget.h"
- #include "public.h"
- Widget::Widget(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::Widget)
- {
- ui->setupUi(this);
- cvNamedWindow("jdh1",1);
- cvNamedWindow("jdh2",1);
- cvNamedWindow("jdh3",1);
- src1 = cvLoadImage("test.jpg");
- src2 = cvLoadImage("lena.jpg");
- dst = cvLoadImage("test.jpg");
- QString str;
- str.setNum(src1->width);
- ui->lineEdit->setText(str);
- str.setNum(src1->height);
- ui->lineEdit_2->setText(str);
- str.setNum(src2->width);
- ui->lineEdit_3->setText(str);
- str.setNum(src2->height);
- ui->lineEdit_4->setText(str);
- }
- Widget::~Widget()
- {
- delete ui;
- cvReleaseImage(&src1);
- cvReleaseImage(&src2);
- cvReleaseImage(&dst);
- cvDestroyAllWindows();
- }
- void Widget::on_pushButton_clicked()
- {
- bool ok;
- double alpha,beta,temp;
- int x,y,width,height;
- temp = ui->lineEdit_7->text().toDouble(&ok);
- if (ok)
- {
- alpha = temp;
- }
- else
- {
- alpha = 0.4;
- }
- cout << alpha << endl;
- temp = ui->lineEdit_8->text().toDouble(&ok);
- if (ok)
- {
- beta = temp;
- }
- else
- {
- beta = 0.6;
- }
- cout << beta << endl;
- x= ui->lineEdit_5->text().toInt(&ok,10);
- cout << x << endl;
- y = ui->lineEdit_6->text().toInt(&ok,10);
- cout << y << endl;
- width = ui->lineEdit_9->text().toInt(&ok,10);
- cout << width << endl;
- height = ui->lineEdit_10->text().toInt(&ok,10);
- cout << height << endl;
- cvSetImageROI(src1,cvRect(x,y,width,height));
- cvSetImageROI(src2,cvRect(x,y,width,height));
- cvSetImageROI(dst,cvRect(x,y,width,height));
- cvAddWeighted(src1,alpha,src2,beta,0.0,dst);
- cvResetImageROI(src1);
- cvResetImageROI(src2);
- cvResetImageROI(dst);
- cvShowImage("jdh1",src1);
- cvShowImage("jdh2",src2);
- cvShowImage("jdh3",dst);
- }
效果图:
http://blog.csdn.net/jdh99/article/details/6401000
qt+opencv对两幅图片进行融合
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。