OpenCV - highGUI preliminary graphical user interface

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_39504764/article/details/100179861

Image depth: is the number of bits used for each pixel is stored, is also a measure for the color resolution of the image.

1. Image loading: imread () function

For reading files into the picture the OpenCV.

#include <opencv2/opencv.hpp>  //头文件
using namespace cv;  //包含cv命名空间

int main( )
{
    // 【1】读入一张图片,载入图像
    Mat srcImage = imread("1.jpg");
    // 【2】显示载入的图片
    imshow("【原始图】",srcImage);
    // 【3】等待任意按键按下
    waitKey(0);
    return 0;
}

2. The image display: imshow () function

For displaying an image in the specified window.

3. Create window: namedWindow () function

namedWindow function: By specifying the name, you can create an image as a container window and progress bar.

#include <opencv2/opencv.hpp>

using namespace cv;

int main()
{
    Mat img;
    img = imread("1.jpg",1);//参数1:图片路径。参数2:显示原图
    
    namedWindow("window1",CV_WINDOW_AUTOSIZE);
   
    /*注释
     参数1:窗口的名字
     参数2:窗口类型,CV_WINDOW_AUTOSIZE 时表明窗口大小等于图片大小。不可以被拖动改变大小。
     CV_WINDOW_NORMAL 时,表明窗口可以被随意拖动改变大小。
     */
    
    imshow("window1",img);//在“window1”这个窗口输出图片。
    waitKey(5000);//等待5秒,程序自动退出。改为0,不自动退出。
    return 0;
    
}

4. The output image to a file: imwrite () function

5. addWeighted () function

Function is a function of two sheets of the same size, the same type of picture integration.

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main()
{
    Mat image = imread("dota.jpg");//载入图片,"dota.jpg"为工程目录下的文件
    Mat logo = imread("dota_logo.jpg");
    
    Mat imageROI;// 定义一个Mat类型,用于存放,图像的ROI,即图像的感兴趣区域
    
    imageROI = image(Rect(800,350,logo.cols,logo.rows));
    //指定图像的感兴趣区域,imageROI的数据与源图像image共享存储区,所以此后在imageROI上的操作也会作用在源图像image上
    //imageROI= image(Range(350,350+logo.rows),Range(800,800+logo.cols));//亦可这么写
    
    // 将logo加到原图上
    
    addWeighted(imageROI,0.8,logo,0.2,0,imageROI);
  //数组相加函数,imageROI为原数组,0.8为该数组权值,logo为另一个原数组,
  //0.2为该数组权重,0为添加常数项,imageROI为输出目标数组,函数输出结果为:imageROI=imageROI*0.8+logo*0.2+0
    
    namedWindow("原画+logo图");//显示结果
    imshow("原画+logo图",image);
    imwrite("由imwrite生成的图片.jpg",image);//输出一张jpg图片到工程目录下
    waitKey();//等待用户输入任意键,在win32环境下可防止程序运行后一闪就退出
}

Guess you like

Origin blog.csdn.net/qq_39504764/article/details/100179861