码迷,mamicode.com
首页 > 其他好文 > 详细

qt+opencv对两幅图片进行融合

时间:2016-12-10 00:51:27      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:include   cout   proc   boa   href   jpg   bar   detail   技术   

本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明.

源代码:

 

[cpp] view plain copy
 
  1. #include "widget.h"  
  2. #include "ui_widget.h"  
  3.   
  4. #include "public.h"  
  5. Widget::Widget(QWidget *parent) :  
  6.     QWidget(parent),  
  7.     ui(new Ui::Widget)  
  8. {  
  9.     ui->setupUi(this);  
  10.     cvNamedWindow("jdh1",1);  
  11.     cvNamedWindow("jdh2",1);  
  12.     cvNamedWindow("jdh3",1);  
  13.     src1 = cvLoadImage("test.jpg");  
  14.     src2 = cvLoadImage("lena.jpg");  
  15.     dst = cvLoadImage("test.jpg");  
  16.     QString str;  
  17.     str.setNum(src1->width);  
  18.     ui->lineEdit->setText(str);  
  19.     str.setNum(src1->height);  
  20.     ui->lineEdit_2->setText(str);  
  21.     str.setNum(src2->width);  
  22.     ui->lineEdit_3->setText(str);  
  23.     str.setNum(src2->height);  
  24.     ui->lineEdit_4->setText(str);  
  25. }  
  26. Widget::~Widget()  
  27. {  
  28.     delete ui;  
  29.     cvReleaseImage(&src1);  
  30.     cvReleaseImage(&src2);  
  31.     cvReleaseImage(&dst);  
  32.     cvDestroyAllWindows();  
  33. }  
  34. void Widget::on_pushButton_clicked()  
  35. {  
  36.     bool ok;  
  37.     double alpha,beta,temp;  
  38.     int x,y,width,height;  
  39.     temp = ui->lineEdit_7->text().toDouble(&ok);  
  40.     if (ok)  
  41.     {  
  42.         alpha = temp;  
  43.     }  
  44.     else  
  45.     {  
  46.         alpha = 0.4;  
  47.     }  
  48.     cout << alpha << endl;  
  49.     temp = ui->lineEdit_8->text().toDouble(&ok);  
  50.     if (ok)  
  51.     {  
  52.         beta = temp;  
  53.     }  
  54.     else  
  55.     {  
  56.         beta = 0.6;  
  57.     }  
  58.     cout << beta << endl;  
  59.     x= ui->lineEdit_5->text().toInt(&ok,10);  
  60.     cout << x << endl;  
  61.     y = ui->lineEdit_6->text().toInt(&ok,10);  
  62.     cout << y << endl;  
  63.     width = ui->lineEdit_9->text().toInt(&ok,10);  
  64.     cout << width << endl;  
  65.     height = ui->lineEdit_10->text().toInt(&ok,10);  
  66.     cout << height << endl;  
  67.     cvSetImageROI(src1,cvRect(x,y,width,height));  
  68.     cvSetImageROI(src2,cvRect(x,y,width,height));  
  69.     cvSetImageROI(dst,cvRect(x,y,width,height));  
  70.     cvAddWeighted(src1,alpha,src2,beta,0.0,dst);  
  71.     cvResetImageROI(src1);  
  72.     cvResetImageROI(src2);  
  73.     cvResetImageROI(dst);  
  74.     cvShowImage("jdh1",src1);  
  75.     cvShowImage("jdh2",src2);  
  76.     cvShowImage("jdh3",dst);  
  77. }  

 

 

 

效果图:

技术分享

 

http://blog.csdn.net/jdh99/article/details/6401000

qt+opencv对两幅图片进行融合

标签:include   cout   proc   boa   href   jpg   bar   detail   技术   

原文地址:http://www.cnblogs.com/findumars/p/6152835.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!