为方便不同入门例子的说明,新增以下例子类:
class OpencvExample
{
public:
void Example_ColorSpace(Mat &image);
private:
};
#pragma once
#include <opencv2/opencv.hpp>
using namespace cv;
class OpencvExample
{
public:
void Example_ColorSpace(Mat &image);
private:
};
#include "example.h"
void OpencvExample::Example_ColorSpace(Mat &image)
{
Mat gray, hsv;
cvtColor(image,hsv,COLOR_BGR2HSV);
cvtColor(image,gray,COLOR_BGR2GRAY);
imshow("HSV", hsv);
imshow("灰度", gray);
imwrite("E:/test/opencvexample/tmp/hsv.png", hsv);
imwrite("E:/test/opencvexample/tmp/gray.png", gray);
}
#include <opencv2/opencv.hpp>
#include <iostream>
#include "example.h"
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("D:/images/gender.jpg");
OpencvExample classExample;
if (src.empty())
{
printf("Can't load image\n");
return -1;
}
namedWindow("InPut", WINDOW_FREERATIO);
imshow("InPut", src);
classExample.Example_ColorSpace(src);
waitKey(0);
destroyAllWindows();
}
|