1.样例1-图像读取与显示
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
//Mat src = imread("./1.png", IMREAD_GRAYSCALE);
Mat src = imread("./1.png");
if (src.empty())
{
cout << "Did not find the image" << endl;
return 0;
}
namedWindow("hello", WINDOW_FREERATIO);
imshow("hello", src);
waitKey(0);
return 0;
}
2.样例2-图像对象的创建与赋值
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
class QuickDemo
{
public:
void colorSpaceDemo(Mat &image);
};
void QuickDemo::colorSpaceDemo(Mat &image)
{
Mat gray, hsv;
cvtColor(image, hsv, COLOR_BGR2HSV);
cvtColor(image, gray, COLOR_BGR2GRAY);
imshow("HSV", hsv);
imshow("灰度", gray);
imwrite("./hsv.png", hsv);
imwrite("./gray.png", gray);
}
int main()
{
//Mat src = imread("./1.png", IMREAD_GRAYSCALE);
Mat src = imread("./1.png");
if (src.empty())
{
cout << "Did not find the image" << endl;
return 0;
}
namedWindow("hello", WINDOW_FREERATIO);
imshow("hello", src);
QuickDemo qd;
qd.colorSpaceDemo(src);
waitKey(0);
return 0;
}
|