日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

OpenCV C++ 03 - Save an Image to a File

發(fā)布時(shí)間:2024/7/5 c/c++ 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenCV C++ 03 - Save an Image to a File 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Code

/* 作者:鄭大峰 時(shí)間:2019年09月20日 環(huán)境:OpenCV 4.1.1 + VS2017 內(nèi)容:Save an Image to a File */#include "pch.h" #include <iostream> #include <opencv2/opencv.hpp>using namespace std; using namespace cv;int main() {Mat image = imread("claudia.png");if (image.empty()){cout << "Could not open or find the image" << endl;cin.get();return -1;}/*Make changes to the image as necessarye.g.1. Change brightness/contrast of the image2. Smooth/Blur image3. Crop the image4. Rotate the image5. Draw shapes on the image*///bool isSuccess = imwrite("claudia_changed.jpg", image); //write the image to a file as JPEG bool isSuccess = imwrite("claudia_changed.png", image); //write the image to a file as PNGif (isSuccess == false){cout << "Failed to save the image" << endl;cin.get();return -1;}cout << "Image is succusfully saved to a file" << endl;cin.get();return 0; }

Result

Explanation

bool imwrite( const String& filename, InputArray img, const std::vector& params = std::vector())

@brief Saves an image to a specified file.

The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see cv::imread for the list of extensions). In general, only 8-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function, with these exceptions:

  • 16-bit unsigned (CV_16U) images can be saved in the case of PNG, JPEG 2000, and TIFF formats
  • 32-bit float (CV_32F) images can be saved in PFM, TIFF, OpenEXR, and Radiance HDR formats; 3-channel (CV_32FC3) TIFF images will be saved using the LogLuv high dynamic range encoding (4 bytes per pixel)
  • PNG images with an alpha channel can be saved using this function. To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last. Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255/65535 (see the code sample below).

If the format, depth or channel order is different, use Mat::convertTo and cv::cvtColor to convert it before saving. Or, use the universal FileStorage I/O functions to save the image to XML or YAML format.

The sample below shows how to create a BGRA image and save it to a PNG file. It also demonstrates how to set custom compression parameters:
@include snippets/imgcodecs_imwrite.cpp
@param filename Name of the file.
@param img Image to be saved.
@param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags

轉(zhuǎn)載于:https://www.cnblogs.com/zdfffg/p/11557920.html

總結(jié)

以上是生活随笔為你收集整理的OpenCV C++ 03 - Save an Image to a File的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。