blobFromImage() 函数详解

本文详细介绍OpenCV中的blobFromImage函数,该函数用于从图像创建四维blob,可选地调整图像大小并从中裁剪,减去平均值,按比例缩放像素值,交换蓝红通道。参数包括输入图像、输出图像大小、平均值、缩放因子、是否交换蓝红通道、是否裁剪以及输出blob的深度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

blobFromImage()
Mat cv::dnn::blobFromImage ( InputArray image,
double scalefactor = 1.0,
const Size & size = Size(),
const Scalar & mean = Scalar(),
bool swapRB = false,
bool crop = false,
int ddepth = CV_32F
)
Python:
retval = cv.dnn.blobFromImage( image[, scalefactor[, size[, mean[, swapRB[, crop[, ddepth]]]]]] )

Creates 4-dimensional blob from image. Optionally resizes and crops image from center, subtract mean values, scales values by scalefactor, swap Blue and Red channels.

Parameters
image input image (with 1-, 3- or 4-channels).
size spatial size for output image
mean scalar with mean values which are subtracted from channels. Values are intended to be in (mean-R, mean-G, mean-B) order if image has BGR ordering and swapRB is true.
scalefactor multiplier for image values.
swapRB flag which indicates that swap first and last channels in 3-channel image is necessary.
crop flag which indicates whether image will be cropped after resize or not
ddepth Depth of output blob. Choose CV_32F or CV_8U.

if crop is true, input image is resized so one side after resize is equal to corresponding dimension in size and another one is equal or larger. Then, crop from the center is performed. If crop is false, direct resize without cropping and preserving aspect ratio is performed.

Returns
4-dimensional Mat with NCHW dimensions order.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值