当前位置:网站首页>Four functions of opencv

Four functions of opencv

2022-07-07 12:46:00 When will we get ashore?

  The official start of the opencv Of learning !

1.imshow

2.imread

3.cvtcolor

4.imwrite

imshow(" Displays the name of the window ", Image name );// display picture 
img=imread(" Picture path ");// Read in the picture 
cvtcolor( Name of the image to be converted , The name of the image stored after conversion , Conversion effect );// Transform picture , E.g. grayscale image 
imwrite(" route ", Picture name );// Save pictures 

Sample code :

 Source file 1
#include<tupian.h>

void demo::color_demo(Mat &image)
{
	Mat hsv, gray;
	cvtColor(image, hsv, COLOR_BGR2HSV);
	cvtColor(image, gray, COLOR_BGR2GRAY);
	imshow(" Grayscale ", gray);
	imshow("HSV", hsv);
	imwrite("D:/hsv.png", hsv);
	imwrite("D:/gray.png", gray);
}

Source file 2

#include <iostream>
#include<tupian.h>
#include<opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc,char** argv)
{
    Mat img;
    img = imread("C:/Users/guoyongbin123/Desktop/C++/opencv4/opencv4/Lena.png");// Picture path
    if (img.empty())
    {
        cout << " Please confirm that the image file name is correct " << endl;
        return -1;
    }
    //Mat img1;
    namedWindow("test", WINDOW_FREERATIO);
    imshow("test", img);
    demo me;
    me.color_demo(img);
    waitKey(0);
    return 0;
}

The header file

#pragma once
#include<opencv2/opencv.hpp>

using namespace cv;

class demo
{
public:
    void color_demo(Mat &image);
};

Be careful :

1. Put the image to be imported in C Files in the same directory .

2. Add the file path to the containing directory , That is, find this file in Solution Explorer , Right click , Find the attribute ,VC++ Catalog , Find the directory containing , Add the file path shown above .

  give the result as follows :

 over!!!

原网站

版权声明
本文为[When will we get ashore?]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/188/202207071032235115.html