pil

方法二,使用PIL+requests:import requests
from PIL import Image
from io import BytesIOresponse = requests.get(img_src)
image = Image.open(BytesIO(response.content))
image.save('D:/9.jpg')

import timeimport cv2
import numpy as np
import requestspath='d:/guo.jpg'# img=cv2.imread(path)
# x = img.tobytes()
# # 从二进制文件到图片(numpy.ndarray):
#
# aaa=np.fromstring(x, np.uint8)
# img = cv2.imdecode(aaa ,cv2.IMREAD_COLOR)
#
# cv2.imshow("1",img)
# cv2.waitKeyEx()
# import cv2   # opencv-python (3.4.2.16)
# import numpy as np  # numpy (1.14.5)#每一张图片需要600ms
for i in range(10):start=time.time()file = requests.get("https://www.baidu.com/img/bd_logo1.png")img = cv2.imdecode(np.fromstring(file.content, np.uint8), 1)    #file.content 是读取的远程文件的字节流print('time',time.time()-start)
cv2.imshow("1",img)
cv2.waitKeyEx()#需要1000ms左右
for i in range(10):start=time.time()# file = requests.get("https://www.baidu.com/img/bd_logo1.png")url = 'http://i5.qhimg.com/t019c3e49c9c9319c33.jpg'url = 'https://www.baidu.com/img/bd_logo1.png'cap = cv2.VideoCapture(url)ret = cap.isOpened()while (ret):ret, img = cap.read()if not ret: break# img = cv2.imdecode(np.fromstring(file.content, np.uint8), 1)    #file.content 是读取的远程文件的字节流print('time',time.time()-start)
cv2.imshow('photo', img)
cv2.waitKey(0)

c++读取:

https://answers.opencv.org/question/91344/load-image-from-url/

#include "curl/curl.h" // has to go before opencv headers#include <iostream>
#include <vector>
using namespace std;#include <opencv2/opencv.hpp>
using namespace cv;//curl writefunction to be passed as a parameter
// we can't ever expect to get the whole image in one piece,
// every router / hub is entitled to fragment it into parts
// (like 1-8k at a time),
// so insert the part at the end of our stream.
size_t write_data(char *ptr, size_t size, size_t nmemb, void *userdata)
{vector<uchar> *stream = (vector<uchar>*)userdata;size_t count = size * nmemb;stream->insert(stream->end(), ptr, ptr + count);return count;
}//function to retrieve the image as cv::Mat data type
cv::Mat curlImg(const char *img_url, int timeout=10)
{vector<uchar> stream;CURL *curl = curl_easy_init();curl_easy_setopt(curl, CURLOPT_URL, img_url); //the img urlcurl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); // pass the writefunctioncurl_easy_setopt(curl, CURLOPT_WRITEDATA, &stream); // pass the stream ptr to the writefunctioncurl_easy_setopt(curl, CURLOPT_TIMEOUT, timeout); // timeout if curl_easy hangs, CURLcode res = curl_easy_perform(curl); // start curlcurl_easy_cleanup(curl); // cleanupreturn imdecode(stream, -1); // 'keep-as-is'
}int main(void)
{Mat image = curlImg("http://www.cars.co.za/images/pictures/general/graphic_sellyourcar.png");if (image.empty())return -1; // load failnamedWindow( "Image output", CV_WINDOW_AUTOSIZE );imshow("Image output",image); // here's your car ;)waitKey(0); // infinite
}

python opencv读取网络图片相关推荐

  1. 解决Python OpenCV 读取视频并抽帧出现error while decoding的问题

    解决Python OpenCV 读取视频抽帧出现error while decoding的问题 1. 问题 2. 解决 3. 源代码 参考 1. 问题 读取H264视频,抽帧视频并保存,报错如下: [ ...

  2. python opencv读取视频没声音_python + opencv: 解决不能读取视频的问题

    博主一开始使用python2.7和Opencv2.4.10来获取摄像头图像,程序如下: cap = cv2.VideoCapture(0) ret, frame = cap.read() 使用这个程序 ...

  3. Python+Opencv读取高帧率USB摄像头问题

    前几次使用Python+Opencv,对网络摄像头,USB摄像头进行数据采集,基本流程已经跑通,没什么大问题.最近项目中使用了一款120fps/s的USB摄像头,但是调试好代码运行后,问题来了. 遇到 ...

  4. python opencv 读取png图像的alpha通道

    关于python opencv加载png图像的文章非常少,由官方文档得知加参数cv2.IMREAD_UNCHANGED即可 img = cv2.imread(filepath, cv2.IMREAD_ ...

  5. python opencv 读取视频流不解码_python + opencv: 解决不能读取视频的问题

    博主一开始使用python2.7和Opencv2.4.10来获取摄像头图像,程序如下: cap = cv2.VideoCapture(0) ret, frame = cap.read()使用这个程序能 ...

  6. python opencv 读取图片_Python opencv 读取图像

    对于 matlab 起家做数字图像处理的人来讲都非常适应matlab对图像处理的操作和思路,尤其是它可以非常方便直观的看到图像的RGB值. 由于最近在研究深度学习的计算机视觉方面的东西,于是完全自学接 ...

  7. Python OpenCV 读取USB摄像头报错问题解决

    报错信息: Traceback (most recent call last):   File "G:\Python图像识别相关学习视频\人体姿势检测.py", line 32, ...

  8. python opencv 读取USB摄像头的像素问题

    问题描述 每次调用capture读取video的时候,还回的像素都是640x480,不管是笔记本的摄像头还是USB摄像头,明明我的摄像头是支持130万读取的功能的呀. 问题分析 一番查找,关于用ope ...

  9. python opencv 读取显示图片

    读取图片路径有中文似乎会产生问题 import cv2 import numpy as np img = cv2.imread('touxiang.jpg',cv2.IMREAD_GRAYSCALE) ...

最新文章

  1. Linux之进程管理
  2. 什么是错误的幻数错误?
  3. 新一代平板电脑 三星Galaxy Note 10.1将于本月末发布 - TECH2IPO创见
  4. 使用SpringBoot搭建一个简单的webSocket服务
  5. rk3399_secureboot在linux环境中操作说明
  6. paip.lbmall 安装doc
  7. 我的世界f服务器自定义皮肤,我的世界服务器皮肤指令
  8. Windows Terminal美化教程
  9. IntelliJ IDEA下载 与 破解(Evaluate for free 灰色)
  10. acwing1282. 搜索关键词(AC 自动机)
  11. Centos8创建pem文件进行远程连接
  12. 自学4年多 Github 上斩获 90k Star! 聊聊自学习编程的正确姿势!
  13. protel dxp 2004电路仿真
  14. 浅释丹道筑基功―—―混元桩【转载】
  15. ccf 命令行选项 java,DiskPart 命令行选项
  16. Cocos2d-x学习(七):cocos2d-x中ScrollView的简单实现
  17. 混合波束成形matlab,探索 5G 系统的混合波束成形架构
  18. 数学外行朋友值得一读的5本经典数学书
  19. 多线程|pi1.c 使用2个线程根据莱布尼兹级数计算PI
  20. es统计mysql 报表_用Elasticsearch实现统计排行榜

热门文章

  1. 使用QEMU创建虚拟机
  2. html5制作交互式课件,用flash制作交互式课件.ppt
  3. 三维家导入户型镜像怎么使用_UG虎钳三维建模教学,认真看仔细学习了!
  4. mysql定制化_【MySQL技巧】定制你的MySQL命令行-阿里云开发者社区
  5. nginx 正则匹配优化(一)
  6. html转jsp后空白页,netbeans 运行这个JSP 页面,结果是空白页。.
  7. 曙光i620c20用户手册_曙光天阔I620-G20服务器技术白皮书.pdf
  8. linux环境下运行open error,错误:运行OpenCL代码时clGetPlatformIDs -1001(Linux)
  9. python输入一个整数倒序输出_利用Python实现倒序任意整数
  10. 计算机基础资料管理办法,计算机基础知识试题(答案_)资料.doc