[opencv_C++] 入门强推!!!【B站最全】
上一讲:【opencv4】opencv视频教程 C++(opencv教程)1、opencv介绍和环境搭建
加载、修改、保存图像
加载图像(用cv::imread)加载图像参数
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main(int argc, const char* argv[]) {
Mat src = imread("img.jpg");
Mat src = imread("img.jpg", IMREAD_GRAYSCALE);
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("test opencv setup", WINDOW_AUTOSIZE);
imshow("test opencv setup", src);
waitKey(0);
return 0;
}
显示图像 (cv::namedWindos 与cv::imshow)
修改图像 (cv::cvtColor)
保存图像(cv::imwrite)
图像加载、修改、保存的代码演示
(main.cpp)
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
int main(int argc, const char* argv[]) {
Mat src = imread("img.jpg");
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("test opencv setup");
imshow("test opencv setup", src);
Mat output_img;
cvtColor(src, output_img, COLOR_BGR2YUV);
namedWindow("test opencv setup2");
imshow("test opencv setup2", output_img);
imwrite("output_img1.jpg", output_img);
waitKey(0);
return 0;
}
VS编译运行结果:
|