Firefox,Selenium,toDataURL,Uint8ClampedArray和Python [英] Firefox, Selenium, toDataURL, Uint8ClampedArray and Python

查看:643
本文介绍了Firefox,Selenium,toDataURL,Uint8ClampedArray和Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在访问Javascript上的图像数据。



使用canvas.toDataURL()方法传递画布数据非常简单,但是现在我想通过Selenium API以最高效的方式将此传递给Python进程。缺点是图像被编码和解码为PNG,给处理增加了大量的开销。



我只是想知道我是否可以将原始数组数据从Javascript传递通过Selenium传递数据

通过Selenium传递数据




    < >
  • 以某种toDataURL()方式将原始像素数据转换为base64编码,或者直接在Javascript中进行处理(希望通过JIT循环)




看起来像canvasContext.getImageData(0,0,w,h).data对象类型是Uint8ClampedArray。将这些数据转换为可以通过Selenium轻松传递给Python的最佳方式是什么?



Selenium 2.0 RC,任何Firefox版本都可以使用。 / p>

解决方案

由于您通过getEval与浏览器之间的通信是基于字符串的,我认为没有从base64编码图像数据。发送原始二进制数据可能不可能。



您可以设计自己的字符串编码方案,但它可能与内置方法一样有效。


I am accessing image data on Javascript. Now I'd like to pass this to Python process through Selenium API in the most efficient possible manner.

Passing canvas data is easy with canvas.toDataURL() method, but the downside is that the image is encoded and decoded to PNG, adding substantial overhead to the process.

I was just wondering if I could pass the raw array data from Javascript to Python via Selenium, so that

  • Either passing data in the native format (unsigned integer data)

  • Convert raw pixel data to base64 encoding, in some kind of toDataURL() manner or simply doing the processing yourself in Javascript (hopefully JIT'ed loop)

Looks like canvasContext.getImageData(0, 0, w, h).data object type is Uint8ClampedArray. What would be the best way to convert this data to some format which can be easily passed through Selenium to Python?

Selenium 2.0 RC, any Firefox version can be used.

解决方案

Since your communication between Selenium and the browser through getEval is string based, I think that there is no escape from base64 encoding the image data. sending raw binary data will probably not be possible.

You can probably devise your own string encoding scheme, but it'll probably be as effective as the built in methods.

这篇关于Firefox,Selenium,toDataURL,Uint8ClampedArray和Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆