Python通过url获取图片的几种方法
2018-07-05 19:20
531 查看
图片源:http://n1image.hjfile.cn/shetuan/2017-05-17-1495016837-986-732.jpg
方法及特性在注释中。#encoding:utf-8 from cv2 import * import urllib import numpy as np import requests as req from PIL import Image from io import BytesIO from skimage import io img_src = 'http://n1image.hjfile.cn/shetuan/2017-05-17-1495016837-986-732.jpg' ############## # opencv # ############## #opencv不能直接从网络获取图片,但是opencv的VideoCapture类可以从url加载视频 # cap = VideoCapture(img_src) # if( cap.isOpened() ): # ret, img = cap.read() # img = resize(img, (800, 600)) # imshow("image", img) # waitKey(0) ######################## # opencv+urllib+numpy # ######################## #urllib的urlopen方法返回一个类文件对象,将对象重新编码为图片传给Mat # resp = urllib.urlopen(img_src) # image = np.asarray(bytearray(resp.read()), dtype="uint8") # image = imdecode(image, IMREAD_COLOR) # image = resize(image, (900, 600)) # imshow("image", image) # waitKey(0) ######################## # PIL+requests # ######################## #字节形式访问请求响应体,用返回的二进制重新创建一张图片 # response = req.get(img_src) # image = Image.open(BytesIO(response.content)) # image.show() ######################## # skimage # ######################## #最方便的方法,直接读物网页图片 image = io.imread(img_src) io.imshow(image) io.show()
阅读更多
相关文章推荐
- Python通过url获取图片的几种方法
- 通过url获取图片尺寸的几种方法:JS和php
- 通过url获取图片尺寸的几种方法:JS和php
- C# 通过URL获取图片并显示在PictureBox上的方法
- ASP.NET 实现通过URL 获取远程的图片或者文件方法
- python通过urllib2获取带有中文参数url内容的方法
- js通过URL快速获取图片宽高的方法
- 使用Python和OpenCV通过网址URL获取图片
- C# 通过URL获取图片并显示在PictureBox上的方法
- Python通过PIL获取图片主要颜色并和颜色库进行对比的方法
- Python通过PIL获取图片主要颜色并和颜色库进行对比的方法
- Python 通过URL打开图片的几种方式
- C# 通过URL获取图片并显示在PictureBox上的方法
- C# 通过URL获取图片并显示在PictureBox上的方法
- Python通过正则表达式获取,去除(过滤)或者替换HTML标签的几种方法(本文由169it.com搜集整理)
- JS中通过url动态获取图片大小的方法小结(两种方法)
- python通过urllib2获取带有中文参数url内容的方法
- C# 通过URL获取图片并显示在PictureBox上的方法
- 通过ASP.NET获取URL地址方法
- ASP.NET 取得 Request URL 的各个部分和通过ASP.NET获取URL地址的方法