Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用OpenCV在图像中捕获web_Python_Opencv - Fatal编程技术网

Python 使用OpenCV在图像中捕获web

Python 使用OpenCV在图像中捕获web,python,opencv,Python,Opencv,我想做一个实践,包括在jpg中捕获Web,但它不仅有效(我是新手),这是我使用的代码 import numpy as np import urllib import cv2 def url_to_image("http://www.hereiputweb.com"): resp = urllib.urlopen("http://www.hereiputweb.com") image = np.asarray(bytearray(resp.read()), dtype="ui

我想做一个实践,包括在jpg中捕获Web,但它不仅有效(我是新手),这是我使用的代码

import numpy as np
import urllib
import cv2


def url_to_image("http://www.hereiputweb.com"):

    resp = urllib.urlopen("http://www.hereiputweb.com")
    image = np.asarray(bytearray(resp.read()), dtype="uint8")
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)

    return image
我从手册中得到的代码,但它给了我一个错误:

def url_to_image("http://www.hereiputweb.com"):
我想我没有正确地指出网站,我不应该。。尝试了几种形式,但一无所获。。我做错了什么


关于

这里有一个非常简短的教程()。 相关部分将是

因此,您应该如下定义您的函数:

def url_to_image(url):

    resp = urllib.urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype="uint8")
    image = cv2.imdecode(image, cv2.IMREAD_COLOR)

    return image
我没有检查实施工作;)

然后您可以使用您的功能:

url = "http://www.hereiputweb.com"
my_image = url_to_image(url)

问题不在于您的实现,而在于您的URL

此方法需要返回图像的有效URL。您正在使用的URL不是图像

尝试使用一个图像的URL(例如:一些以.jpg结尾的URL),它会工作的


记住,URL必须是在线的

def url_to_image(url=“):resp=urllib.urlopen(url)应该可以工作。请始终报告您收到的确切错误。请阅读本文。我将帮助您在使用此网站时获得更好的响应。我认为OP想要做的是拍摄给定网站的“截图”。至少这是我从以下句子中理解的”在jpg中捕获网页”。