Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.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
Selenium Webdriver,屏幕截图为numpy数组(Python)_Python_Selenium Webdriver_Screenshot - Fatal编程技术网

Selenium Webdriver,屏幕截图为numpy数组(Python)

Selenium Webdriver,屏幕截图为numpy数组(Python),python,selenium-webdriver,screenshot,Python,Selenium Webdriver,Screenshot,有没有办法用SeleniumWebDriver截图并转换成numpy数组而不是保存它?我需要将它与openCV一起使用 注意:我不想保存图像并再次打开它我相信有一种更有效的方法可以做到这一点,但这对我来说是有效的: from selenium import webdriver from PIL import Image import StringIO import numpy as np browser = webdriver.Firefox() browser.get('https://ww

有没有办法用SeleniumWebDriver截图并转换成numpy数组而不是保存它?我需要将它与openCV一起使用


注意:我不想保存图像并再次打开它

我相信有一种更有效的方法可以做到这一点,但这对我来说是有效的:

from selenium import webdriver
from PIL import Image
import StringIO
import numpy as np

browser = webdriver.Firefox()
browser.get('https://www.google.ca/?gws_rd=ssl')

data = browser.get_screenshot_as_png()

img = Image.open(StringIO.StringIO(data))

numpy_array = np.asarray(img)

Python3:
导入io;io.字节io(数据)