python OpenCV的imread不能读取中文路径问题及解决

 更新时间:2022年07月14日 09:39:14   作者:Dragon水魅  
这篇文章主要介绍了python OpenCV的imread不能读取中文路径问题及解决方案,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

OpenCV的imread不能读取中文路径问题

import numpy as np
import cv2

cv_img = cv2.imdecode(np.fromfile(jpg_path, dtype=np.uint8), -1)  # 读取8位图像

OpenCV imread()函数 (从文件加载图像)

def imread(filename, flags=None): # real signature unknown; restored from __doc__
    """
    imread(filename[, flags]) -> retval
    .   @brief Loads an image from a file. 从文件加载图像。
    .   
    .   @anchor imread
    .   
    .   The function imread loads an image from the specified file and returns it. If the image cannot be
    .   read (because of missing file, improper permissions, unsupported or invalid format), the function
    .   returns an empty matrix ( Mat::data==NULL ).

		该函数imread从指定的文件加载图像并返回它。 
		如果无法读取图像(由于缺少文件,权限不正确,格式不受支持或格式无效),
		该函数将返回一个空矩阵(Mat :: data == NULL)。
    .   
    .   Currently, the following file formats are supported: 当前,支持以下文件格式:
    .   
    .   -   Windows bitmaps - \*.bmp, \*.dib (always supported)
    .   -   JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section)
    .   -   JPEG 2000 files - \*.jp2 (see the *Note* section)
    .   -   Portable Network Graphics - \*.png (see the *Note* section)
    .   -   WebP - \*.webp (see the *Note* section)
    .   -   Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported)
    .   -   PFM files - \*.pfm (see the *Note* section)
    .   -   Sun rasters - \*.sr, \*.ras (always supported)
    .   -   TIFF files - \*.tiff, \*.tif (see the *Note* section)
    .   -   OpenEXR Image files - \*.exr (see the *Note* section)
    .   -   Radiance HDR - \*.hdr, \*.pic (always supported)
    .   -   Raster and Vector geospatial data supported by GDAL (see the *Note* section)
    .   
    .   @note
    .   -   The function determines the type of an image by the content, not by the file extension.
    		该功能通过内容而不是文件扩展名确定图像的类型
    		
    .   -   In the case of color images, the decoded images will have the channels stored in **B G R** order.
    		对于彩色图像,解码后的图像将具有以** B G R **顺序存储的通道。
    		
    .   -   When using IMREAD_GRAYSCALE, the codec's internal grayscale conversion will be used, if available.
    .   Results may differ to the output of cvtColor()
    		使用IMREAD_GRAYSCALE时,将使用编解码器的内部灰度转换(如果有)。 结果可能与cvtColor()的输出不同
    		
    .   -   On Microsoft Windows\* OS and MacOSX\*, the codecs shipped with an OpenCV image (libjpeg,
    .   libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs,
    .   and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware
    .   that currently these native image loaders give images with different pixel values because of
    .   the color management embedded into MacOSX.

			在Microsoft Windows \ * OS和MacOSX \ *上,
			默认使用OpenCV映像附带的编解码器(libjpeg,libpng,libtiff和libjasper)。 
			因此,OpenCV始终可以读取JPEG,PNG和TIFF。 
			在MacOSX上,还可以选择使用本机MacOSX图像读取器。 
			但是请注意,由于MacOSX中嵌入了色彩管理,当前这些本机图像加载器会为图像提供不同的像素值。
			
    .   -   On Linux\*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for
    .   codecs supplied with an OS image. Install the relevant packages (do not forget the development
    .   files, for example, "libjpeg-dev", in Debian\* and Ubuntu\*) to get the codec support or turn
    .   on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.

			在Linux \ *,BSD版本和其他类似Unix的开源操作系统上,OpenCV会寻找OS映像随附的编解码器。 
			安装相关的软件包(不要忘记在Debian \ *和Ubuntu \ *中忘记开发文件,
			例如“ libjpeg-dev”)以获得编码解码器支持或在CMake中打开OPENCV_BUILD_3RDPARTY_LIBS标志。
			
    .   -   In the case you set *WITH_GDAL* flag to true in CMake and @ref IMREAD_LOAD_GDAL to load the image,
    .   then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting
    .   the following formats: [Raster](http://www.gdal.org/formats_list.html),
    .   [Vector](http://www.gdal.org/ogr_formats.html).

			如果您在CMake中将* WITH_GDAL *标志设置为true并使用@ref IMREAD_LOAD_GDAL加载图像,则将使用[GDAL](http://www.gdal.org)驱动程序对图像进行解码,以支持 以下格式:[Raster](http://www.gdal.org/formats_list.html)、[Vector](http://www.gdal.org/ogr_formats.html)。
			
    .   -   If EXIF information are embedded in the image file, the EXIF orientation will be taken into account
    .   and thus the image will be rotated accordingly except if the flag @ref IMREAD_IGNORE_ORIENTATION is passed.
			如果将EXIF信息嵌入到图像文件中,则将考虑EXIF方向,
			因此,除非传递了@ref IMREAD_IGNORE_ORIENTATION标志,否则图像将相应旋转。
			
	    .   -   Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image.
	    		使用IMREAD_UNCHANGED标志保留PFM图像中的浮点值。
	    		
    .   -   By default number of pixels must be less than 2^30. Limit can be set using system
    .   variable OPENCV_IO_MAX_IMAGE_PIXELS
    		默认情况下,像素数必须小于2 ^ 30。 可以使用系统变量OPENCV_IO_MAX_IMAGE_PIXELS设置限制
    .   
    .   @param filename Name of file to be loaded. 要加载的文件名。
    .   @param flags Flag that can take values of cv::ImreadModes 可以采用cv :: ImreadModes值的标志
    """
    pass

以上为个人经验,希望能给大家一个参考,也希望大家多多支持程序员之家。

相关文章

  • Python黑魔法之metaclass详情

    Python黑魔法之metaclass详情

    Python 有很多黑魔法,为了不分你的心,今天只讲 metaclass。对于 metaclass 这种特性,有两种极端的观点:下面小编将为大家详细的介绍,刚兴趣的小伙伴可以参考一下
    2021-09-09
  • 在Pytorch中使用Mask R-CNN进行实例分割操作

    在Pytorch中使用Mask R-CNN进行实例分割操作

    这篇文章主要介绍了在Pytorch中使用Mask R-CNN进行实例分割操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-06-06
  • 解决Python 中JSONDecodeError: Expecting value: line 1 column 1 (char 0)错误

    解决Python 中JSONDecodeError: Expecting value:&n

    这篇文章主要介绍了解决Python 中JSONDecodeError: Expecting value: line 1 column 1 (char 0)错误问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-03-03
  • PyQt5事件处理之定时在控件上显示信息的代码

    PyQt5事件处理之定时在控件上显示信息的代码

    这篇文章主要介绍了PyQt5事件处理之定时在控件上显示信息的代码,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-03-03
  • pycharm 代码自动补全的实现方法(图文)

    pycharm 代码自动补全的实现方法(图文)

    这篇文章主要介绍了pycharm 代码自动补全的实现方法(图文),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-09-09
  • 解决python字典对值(值为列表)赋值出现重复的问题

    解决python字典对值(值为列表)赋值出现重复的问题

    今天小编就为大家分享一篇解决python字典对值(值为列表)赋值出现重复的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-01-01
  • Python记录详细调用堆栈日志的方法

    Python记录详细调用堆栈日志的方法

    这篇文章主要介绍了Python记录详细调用堆栈日志的方法,涉及Python调用堆栈日志的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
    2015-05-05
  • Python FFT合成波形的实例

    Python FFT合成波形的实例

    今天小编大家分享一篇Python FFT合成波形的实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-12-12
  • PyTorch与PyTorch?Geometric的安装过程

    PyTorch与PyTorch?Geometric的安装过程

    这篇文章主要介绍了PyTorch与PyTorch?Geometric的安装,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-04-04
  • Python爬虫请求模块Urllib及Requests库安装使用教程

    Python爬虫请求模块Urllib及Requests库安装使用教程

    requests和urllib都是Python中常用的HTTP请求库,使用时需要根据实际情况选择,如果要求使用简单、功能完善、性能高的HTTP请求库,可以选择requests,如果需要兼容性更好、功能更加灵活的HTTP请求库,可以选择urllib
    2023-11-11

最新评论

?


http://www.vxiaotou.com