打工日志10.23

今天在使用opencv进行图像提取操作的时候,又发现了一个怪事,使用imwrite方法进行图像保存的时候,发现图像会自动进行压缩,导致画质损失。
查询资料后得知.jpg格式的图像是有损的,会自动地进行图像的压缩操作;.png格式的图像是无损的。因此,在imwrite方法当中,进行图片保存之后,只需要保存为.png格式即可。

下面贴上python中cv2.imwrite()的定义:

def imwrite(filename, img, params=None): # real signature unknown; restored from __doc__
    """
    imwrite(filename, img[, params]) -> retval
    .   @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).
    .   - Multiple images (vector of Mat) can be saved in TIFF format (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, how to set custom compression parameters and save it to a PNG file.
    .   It also demonstrates how to save multiple images in a TIFF file:
    .   @include snippets/imgcodecs_imwrite.cpp
    .   @param filename Name of the file.
    .   @param img (Mat or vector of Mat) Image or Images to be saved.
    .   @param params Format-specific parameters encoded as pairs (paramId_1, paramValue_1, paramId_2, paramValue_2, ... .) see cv::ImwriteFlags
    """
    pass
  • 注释清晰地表明了,不同图像数据可以存储的图像格式
  • 最后一个参数params对于不同的存储格式有着不同的含义,具体见链接cv::ImwriteFlags。在我需要进行的任务当中,主要是要对输出的图像质量进行控制,因此,可以选择控制.jpg格式文件质量的枚举器cv2.IMWRITE_JPEG_QUALITY进行控制即可。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值