Python opencv 读取图片

举报
千江有水千江月 发表于 2021/07/14 23:38:01 2021/07/14
【摘要】 环境信息ModelArtsNotebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04JupyterLab - Notebook - Conda-python3  opencv 读取图片import cv2--------------------------------------------------------------------------...

环境信息

  • ModelArts
    • Notebook - pytorch1.4-cuda10.1-cudnn7-ubuntu18.04
      • JupyterLab - Notebook - Conda-python3

opencv 读取图片

import cv2

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-c8ec22b3e787> in <module>
----> 1 import cv2

ModuleNotFoundError: No module named 'cv2'
!pip install opencv-python

Looking in indexes: http://repo.myhuaweicloud.com/repository/pypi/simple
Collecting opencv-python
  Downloading http://repo.myhuaweicloud.com/repository/pypi/packages/6b/73/a8921d221a673600dc744033786eeab56ed5116686a1b932b724a33003c6/opencv_python-4.5.3.56-cp37-cp37m-manylinux2014_x86_64.whl (49.9 MB)
     |████████████████████████████████| 49.9 MB 54.2 MB/s eta 0:00:01                   | 7.1 MB 54.2 MB/s eta 0:00:01            | 9.7 MB 54.2 MB/s eta 0:00:01                | 11.8 MB 54.2 MB/s eta 0:00:01               | 15.5 MB 54.2 MB/s eta 0:00:014.2 MB/s eta 0:00:01  | 25.8 MB 54.2 MB/s eta 0:00:01   | 31.1 MB 54.2 MB/s eta 0:00:01��█████▏       | 37.6 MB 54.2 MB/s eta 0:00:01��███████████████████▎   | 44.2 MB 54.2 MB/s eta 0:00:01
Requirement already satisfied: numpy>=1.14.5 in /home/ma-user/modelarts-sdk (from opencv-python) (1.21.0)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.5.3.56
import cv2
img = cv2.imread("1.png")
img

array([[[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       ...,

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]],

       [[255, 255, 255],
        [255, 255, 255],
        [255, 255, 255],
        ...,
        [255, 255, 255],
        [255, 255, 255],
        [255, 255, 255]]], dtype=uint8)

help

help(cv2.imread)

Help on built-in function imread:

imread(...)
    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 ).
    .   
    .   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)

......

相关链接


备注

  1. 欢迎各位同学一起来交流学习心得^_^
  2. 在线课程、沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。