当前位置:网站首页>One: OpenCV image reading and writing file help documentation
One: OpenCV image reading and writing file help documentation
2022-08-05 12:00: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”is that the resulting image is a grayscale image.取“1”A three-channel color image is obtained.
python code
import cv2
#Read the grayscale image of the specified image
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)
{
//Read image file based on image file path and file name
Mat src = imread("e:/TestImage/bike.jpg",1);
//Create an image display window
namedWindow("src", 0);
//显示图像
imshow("src", src);
//等待用户按键触发,如果没有该语句,The window automatically closes after displaying the image.
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:表示为特定格式保存的参数编码,Usually the default value is used directly.
作用:保存图像.
python code:
#save image to file
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;
}
If the save file path has Chinese, you can use the following method to save:
cv2.imencode('.jpg', image)[1].tofile(save_img_path)
文章来源>>【一:OpenCVImage reading and writing file help documentation】欢迎Star
边栏推荐
- 申请百度地图API Key进行百度地图开发,获取经纬度对应地点
- 【无标题】
- 解决 cuDNN launch failure 错误
- Keras 分割网络自定义评估函数 - mean iou
- [Supply Chain·Case] What did the top ten retailers in the world do under the influence of the epidemic?
- CC2530实现按键中断
- isn't it?Is there anyone who can't locate the slow query problem of MySQL online?
- WingIDE 7.2.0 远程调试
- 2022.08.01_每日一题
- Zhihu asks: Can China still achieve great national rejuvenation?
猜你喜欢

2022.08.01_每日一题

Go compilation principle series 9 (function inlining)

CC2530之ADC采集

C语言例题-计算常量e的值

sentinel介绍和使用

STM32H743IIT6学习笔记01——CubeMX新建工程文件

Small household appliance industry supply chain collaborative management system: help enterprises break through market competition and strengthen the rapid response capability of the supply chain

STM32H743IIT6学习笔记02——USART

stm32项目之SPI通信2.4G模块(NF2401L)

STM32H743IIT6学习笔记03——使用第三方组件FreeRTOS
随机推荐
常用的免费Api接口网址
2022.08.03_每日一题
Go Quick Start Guide: Basic Types
Exploration and practice of transaction link under multi-service mode
2022.08.03_每日一题
Visit GOPS Long Zhi booth, Forrester's latest report: "the Forrester Wave: the fourth quarter of 2021 enterprise service management report
The training set Loss converges, but the test set Loss oscillates violently?
PMP每日一练 | 考试不迷路-8.5(包含敏捷+多选)
treeselect common function record (with a callback function for clearing options)
Cesium.js 三维土壤地质剖面分割挖掘
796. 子矩阵的和
Zhihu asks: Can China still achieve great national rejuvenation?
2022.08.02_Daily question
Cesium.js点线面绘制
CC2530之ADC采集
Version Control | Longzhi invites you to go to the GOPS Global Operation and Maintenance Conference to explore the road of large-scale, agile, high-quality and open software development and operation
2022.08.01_每日一题
Learning Deep Compact Image Representations for Visual Tracking
小家电行业供应链协同管理系统:助力企业突围市场竞争,加强供应链快速响应能力
798. 差分矩阵