- 载入函数
Mat imread( const String& filename, int flags = IMREAD_COLOR );
IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image.
IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.
Mat img = imread("D:/learn/dota.jpg");
- 显示函数
imshow("dota", img);
- 输出函数
bool imwrite( const String& filename, InputArray img,
const std::vector<int>& params = std::vector<int>());
imwrite("D:/new_dota.jpg", img);
实例
#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> using namespace cv; int main() { //图像显示 Mat logo = imread("D:/learn/logo.jpg"); imshow("logo", logo); //图像混合 Mat img = imread("D:/learn/dota.jpg"); imshow("img", img); Mat imgROI; imgROI = img(Rect(800, 350, logo.cols, logo.rows)); //logo加载到背景图 addWeighted(imgROI,0.5,logo,0.3,0,imgROI); imshow("dota_logo", img); //保存混合的图像 imwrite("D:/learn/dota_logo.jpg",img); waitKey(0); }
读取视频文件 调用摄像头 写入视频文件
#include <iostream> #include <opencv2/opencv.hpp> using namespace std; using namespace cv; int main() { namedWindow("cap", cv::WINDOW_AUTOSIZE); VideoCapture cap; Mat frame; cap.open(0); //视频流写出 Size size = Size(cap.get(CV_CAP_PROP_FRAME_WIDTH), cap.get(CV_CAP_PROP_FRAME_HEIGHT)); VideoWriter writer; writer.open("test.avi", -1, 10, size); // for (;;){ cap >> frame; imshow("out", frame); writer << frame; if (waitKey(33) >= 0) break; } cap.release(); //waitKey(0); return 0; }
版权声明:原创,转载请注明来源,否则律师函警告
本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!