zoukankan      html  css  js  c++  java
  • OpenCV 线性混合(4)

     

    带滚动条的线性混合示例:

     

    #include "stdafx.h"

    #include<iostream>

    #include<thread>

    #include<vector>

    #include <opencv2/core/core.hpp>

    #include <opencv2/contrib/contrib.hpp>

    #include <opencv2/highgui/highgui.hpp>

    #include <opencv2/imgproc/imgproc.hpp>

    #include <opencv2/objdetect/objdetect.hpp>

     

    using namespace cv;

    using namespace std;

     

    int g_slider_position = 0;

    double alpha = 0.5;

    double beta;

    Mat src1, src2, dst;

     

    void onTrackingbarSlide(int pos)

    {

        alpha = (double)pos / 100;

        beta = (1.0 - alpha);

        addWeighted(src1, alpha, src2, beta, 0.0, dst);

        imshow("Linear Blend", dst);

    }

     

    int _tmain(int argc, _TCHAR* argv[])

    {

        double input;

     

        /// Ask the user enter alpha

        std::cout << " Simple Linear Blender " << std::endl;

        std::cout << "-----------------------" << std::endl;

        std::cout << "* Enter alpha [0-1]: ";

        std::cin >> input;

     

        /// We use the alpha provided by the user iff it is between 0 and 1

        if (alpha >= 0 && alpha <= 1)

        {

            alpha = input;

        }

     

        /// Read image ( same size, same type )

        src1 = imread("E:\myImage\sql.png");

        src2 = imread("E:\myImage\network26.png");

     

        if (!src1.data) { printf("Error loading src1 "); return -1; }

        if (!src2.data) { printf("Error loading src2 "); return -1; }

     

        /// Create Windows

        namedWindow("Linear Blend", 1);

     

        cvCreateTrackbar("Linear Blend", "Linear Blend", &g_slider_position, 100, onTrackingbarSlide);

     

        beta = (1.0 - alpha);

        addWeighted(src1, alpha, src2, beta, 0.5, dst);

     

        imshow("Linear Blend", dst);

     

        waitKey(0);

        return 0;

    }

     

     

    原文:http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutorials/core/adding_images/adding_images.html#adding-images

  • 相关阅读:
    libevent 源码学习四 —— 源代码文件组织
    c++上待解决的内容
    常用网址
    tin mission 2021 11 14
    问题--c++
    小思维--c++
    thin mission 2021 11 13
    physics--lecture--Centre of Gravity & Inertia and conservation of angular momentum
    physics--lecture--torque--static equilibrium
    physics—lecture ——torque
  • 原文地址:https://www.cnblogs.com/pengzhen/p/4953907.html
Copyright © 2011-2022 走看看