当前位置:网站首页>一:OpenCV图片读取与写入文件帮助文档
一:OpenCV图片读取与写入文件帮助文档
2022-08-05 11:55:00 【fplei】
1.函数名:imread
定义:
Mat imread( const String& filename, int flags = IMREAD_COLOR );
def imread(filename, flags=None)
参数:
filename:文件名
flags:读取标识,枚举类型,
可以取以下值
enum ImreadModes {
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 (codec internal conversion).
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.
IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image.
IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.
};
作用:读取图像,flags参数取“0”或“1”比较常见,取“0”是得到的图像是灰度图像。取“1”得到三通道彩色图像。
python code
import cv2
#读取指定图片灰度图片
gray_image=cv2.imread(img_path,0)
#读取指定图片3通道
org_image=cv2.imread(img_path,1)
#-------------------------------------
#C code
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
//根据图像文件路径和文件名读取图像文件
Mat src = imread("e:/TestImage/bike.jpg",1);
//创建一个图像显示窗口
namedWindow("src", 0);
//显示图像
imshow("src", src);
//等待用户按键触发,如果没有该语句,窗口显示图像之后就自动关闭。
waitKey(0);
return 0;
}
2.函数名:imwrite
定义:
bool imwrite( const String& filename, InputArray img, const std::vector& params = std::vector());
def imwrite(filename, img, params=None)
参数:
filename:文件名
img:要保存的图像
params:表示为特定格式保存的参数编码,通常直接采用默认值。
作用:保存图像。
python code:
#保存图片至文件
cv2.imwrite("xxx", image)
#---------------------------
C code:
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Mat src = imread("e:/TestImage/bike.jpg", 1);
namedWindow("src", 0);
imshow("src", src);
imwrite("e:/TestImage/bike_write.bmp", src);
waitKey(0);
return 0;
}
如果保存文件路径有中文可以使用一下方法来保存:
cv2.imencode('.jpg', image)[1].tofile(save_img_path)
文章来源>>【一:OpenCV图片读取与写入文件帮助文档】欢迎Star
边栏推荐
- Face the summary - club resort - 6 years
- 789. 数的范围
- Cesium.js 三维土壤地质剖面分割挖掘
- 【HMS core】【FAQ】Health Kit, Ads kit, Push Kit Typical Questions Collection 5
- 163_技巧_Power BI 一键批量建立自定义字段参数
- 碘乙酰胺在Desthiobiotin-Iodoacetamide试剂中的作用?
- The principle and application scenario of mysql master-slave synchronization
- Security Issues and Prevention in Web3
- Shang Silicon Valley-JUC
- Cesium.js 地形挖洞
猜你喜欢

2022.08.01_每日一题

Go 语言快速入门指南: 基本类型

C语言经典例题-求一串数中的最大数

Memory problems difficult to locate, it is because you do not use ASAN

2021 RoboCom World Robot Developers Competition - Higher Vocational Group (Final)

Gray value and thermal imaging understanding

Cesium.js 地形挖洞

尚硅谷-JUC篇

Apache APISIX Ingress v1.5-rc1 released

学习用于视觉跟踪的深度紧凑图像表示
随机推荐
KVM虚拟化技术的-NUMA技术和应用
Go Quick Start Guide: Basic Types
【7.29-8.5】写作社区精彩技术博文回顾
有多一只“手”的机器狗出没?就在昇腾AI开发者创享日·南京站
Mysql8基础知识
食品饮料行业B2B商城系统:加速行业数字化转型,提升B2B平台交易效率
软件设计七大原则之开闭原则(Open-Closed Principle, OCP)
2022年6月互联网医疗领域月度观察
STM32H743IIT6学习笔记03——使用第三方组件FreeRTOS
163_Tricks_Power BI one-click batch creation of custom field parameters
treeselect common function record (with a callback function for clearing options)
学习用于视觉跟踪的深度紧凑图像表示
关注微信公众号,自动登陆网站
795. 前缀和
798. 差分矩阵
ORACLE ASM提供的三种冗余方式
灰度值与热成像理解
2021 RoboCom 世界机器人开发者大赛-高职组(决赛)
Shang Silicon Valley-JUC
2022.08.02_每日一题