zoukankan      html  css  js  c++  java
  • qt+opencv对两幅图片进行融合

    本文博客链接: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

  • 相关阅读:
    linux 配置nginx+php-cgi
    有个故事
    2014短学期实习报告
    快速排序
    C++之共用体
    不能言传,等于不会
    java 动态绑定
    编程的理论深度
    Java 多客户端版 2048 源码
    热河看待苦难
  • 原文地址:https://www.cnblogs.com/findumars/p/6152835.html
Copyright © 2011-2022 走看看