我希望使用没有adb screencap
标志的-p
实用程序。我原以为输出会以原始格式转储,但看起来不像。我尝试用Pillow
(python)库打开原始图像文件,结果是:
$ adb pull /sdcard/screenshot.raw screenshot.raw
$ python
>>> from PIL import Image
>>> Image.open('screenshot.raw')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/....../lib/python2.7/site-packages/PIL/Image.py", line 2025, in open
raise IOError("cannot identify image file")
IOError: cannot identify image file
如果找不到正确的方法来读取这样的原始图像,我甚至尝试了以下方法:How to read a raw image using PIL?
>>> with open('screenshot.raw', 'rb') as f:
... d = f.read()
...
>>> from PIL import Image
>>> Image.frombuffer('RGB', len(d), d)
__main__:1: RuntimeWarning: the frombuffer defaults may change in a future release; for portability, change the call to read:
frombuffer(mode, size, data, 'raw', mode, 0, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/..../lib/python2.7/site-packages/PIL/Image.py", line 1896, in frombuffer
return frombytes(mode, size, data, decoder_name, args)
File "/Users/..../lib/python2.7/site-packages/PIL/Image.py", line 1821, in frombytes
im = new(mode, size)
File "/Users/..../lib/python2.7/site-packages/PIL/Image.py", line 1787, in new
return Image()._new(core.fill(mode, size, color))
TypeError: must be 2-item sequence, not int
所有可能的模式选项都会导致相同的TypeError
异常。
下面是hexdump
实用程序所揭示的内容:
$ hexdump -C img.raw | head
00000000 d0 02 00 00 00 05 00 00 01 00 00 00 1e 1e 1e ff |................|
00000010 1e 1e 1e ff 1e 1e 1e ff 1e 1e 1e ff 1e 1e 1e ff |................|
*
000038c0 1e 1e 1e ff 1e 1e 1e ff 21 21 21 ff 2b 2b 2b ff |........!!!.+++.|
000038d0 1e 1e 1e ff 1e 1e 1e ff 1e 1e 1e ff 1e 1e 1e ff |................|
*
00004400 1e 1e 1e ff 1e 1e 1e ff 47 47 47 ff 65 65 65 ff |........GGG.eee.|
00004410 20 20 20 ff 1e 1e 1e ff 1e 1e 1e ff 1e 1e 1e ff | .............|
00004420 1e 1e 1e ff 1e 1e 1e ff 1e 1e 1e ff 1e 1e 1e ff |................|
*
在osx上:
$ file screenshot.raw
screenshot.raw: data
在没有screencap
标志的情况下,-p
帮助页面也不会显示输出数据的格式:
$ adb shell screencap -h
usage: screencap [-hp] [FILENAME]
-h: this message
-p: save the file as a png.
If FILENAME ends with .png it will be saved as a png.
If FILENAME is not given, the results will be printed to stdout.
发布于 2014-02-26 00:00:17
由于您的文件的摘录,我想您的原始文件被格式化为宽度x高度,然后整个RGBA像素集(32位)(宽度x高度时间)--我看到您在这里看到的是一个720x1280图像。
希望ImageMagick工具集可以帮助您以更合适的文件格式查看/转换它。下面的示例可能对您有所帮助(ImageMagick转换命令,有关osx,请参见http://cactuslab.com/imagemagick/ )。
# skip header info
dd if=screenshot.raw of=screenshot.rgba skip=12 bs=1
# convert rgba to png
convert -size 720x1280 -depth 8 screenshot.rgba screenshot.png
如果它不起作用,您可以尝试通过skip=8和/或720x1280将skip=8更改为1280x720。
希望能有所帮助
发布于 2015-09-22 23:12:58
格式:
width
height
pixel format
width
* heigth
* bytespp
)字节为字节数组- image data
,其中bytespp
是每个像素的字节,依赖于pixel format
。通常bytespp
是4。来自source code of screencap的信息。
以你为例:
00000000 d0 02 00 00 00 05 00 00 01 00 00 00 1e 1e 1e ff
d0 02 00 00
-宽度- uint32 0x000002d0 = 72000 05 00 00
-高度- uint32 0x00000500 = 128001 00 00 00
-像素格式- uint32 0x00000001 =1= PixelFormat.RGBA_8888
=> bytespp = 4
=> RGBA1e 1e 1e ff
-第一像素数据- R = 0x1e; G = 0x1e; B = 0x1e; A = 0xff;
以大小720*1280*4的字节数组存储数据的像素。
发布于 2019-12-24 07:39:40
要阅读亚行用python编写的原始格式:
from PIL import Image
Image.frombuffer('RGBA', (1920, 1080), raw[12:], 'raw', 'RGBX', 0, 1)
最重要的部分是跳过标题,正如@Emmanuel的回答中提到的
请注意,(1920,1080)是您的设备分辨率,可以通过
adb shell wm size
希望这将节省12个小时来调查为什么cv2.火柴模板在几乎相同的图像上有不同的匹配。
https://stackoverflow.com/questions/22034959
复制