【OpenCV_05】把图像&视频写入文件Write Image & Video to File

今天,聊聊怎么吧图像以及视频写入到文件里。

Write Image to File 把图片写入到文件

下面的例子是创建一个黄色的图像并且写到文件里,下面就是采用OpenCV来实现.

///
// Write Image & Video to File

#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, const char** argv )
{
  Mat img(650, 600, CV_16UC3, Scalar(0,50000, 50000)); //create an image ( 3 channels, 16 bit image depth, 650 high, 600 wide, (0, 50000, 50000) assigned for Blue, Green and Red plane respectively. )

if (img.empty()) //check whether the image is loaded or not
{
cout << "ERROR : Image cannot be loaded..!!" << endl;
          //system("pause"); //wait for a key press
return -1;
}

     vector<int> compression_params; //vector that stores the compression parameters of the image

     compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); //specify the compression technique

     compression_params.push_back(98); //specify the compression quality



     bool bSuccess = imwrite("D:/TestImage.jpg", img, compression_params); //write the image to file



     if ( !bSuccess )

    {

cout << "ERROR : Failed to save the image" << endl;

         //system("pause"); //wait for a key press

    }

namedWindow("MyWindow", CV_WINDOW_AUTOSIZE); //create a window with the name "MyWindow"
imshow("MyWindow", img); //display the image which is stored in the 'img' in the "MyWindow" window

waitKey(0);  //wait for a keypress

     destroyWindow("MyWindow"); //destroy the window with the name, "MyWindow"

return 0;
}
///


新出现的OpenCV函数
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值