使这项工作跨平台工作可能需要相当多的工作。如果您的最终目标是 Windows,那么为什么不使用 ambone 项目,它似乎完全符合您的要求呢?
http://amblone.com/guide http://amblone.com/guide
无论如何,这是一个使用 ffmpeg 和graphicsmagick 的解决方案,速度相当快(在我的 i7 8GB 笔记本电脑上)。ffmpeg精确捕获一个屏幕,将其缩小到可以的最小正方形尺寸,将输出通过管道传输到graphicsmagick Convert,在其中将其大小调整为1x1像素,然后报告图像rgb值。
#!/bin/bash
mkfifo /tmp/screencap.fifo
while true
do
# this version will send the info to a fifo
# ffmpeg -y -loglevel error -f x11grab -s 1920x1080 -i :0.0 -s 32x32 \
# -vframes 1 -f image2 -threads 2 - | gm convert - -resize 1x1 \
# txt:- > /tmp/screencap.fifo
# this version will write out the info to the command line
# and will show you what is going on.
ffmpeg -y -loglevel error -f x11grab -s 1920x1080 -i :0.0 -s 32x32 \
-vframes 1 -f image2 -threads 2 - | gm convert - -resize 1x1 txt:-
done
exit
这会给你类似下面的东西:
0,0: ( 62, 63, 63) #3E3F3F
0,0: (204,205,203) #CCCDCB
0,0: ( 77, 78, 76) #4D4E4C
0,0 是正在读取的像素的位置。括号中的数字是各自的 R、G、B 值,末尾的数字是典型的 html 式十六进制值。在上面的情况下,只有 1 个像素,但您可以(如果您希望将基本方向作为广义 RGB 值)只需更改-resize 1x1
上面的部分-resize 3x3
你会得到类似的东西:
0,0: ( 62, 63, 65) #3E3F41
1,0: ( 90, 90, 91) #5A5A5B
2,0: (104,105,106) #68696A
0,1: ( 52, 51, 52) #343334
1,1: ( 60, 60, 59) #3C3C3B
2,1: ( 64, 64, 64) #404040
0,2: ( 49, 49, 50) #313132
1,2: ( 60, 60, 60) #3C3C3C
2,2: ( 65, 65, 65) #414141
我将让您将该信息传递给您的arduino。
ffmpeg很棒,但是您必须记住关闭屏幕捕获位(在我的示例中-f x11grab
)与您的 Windows 系统使用的任何内容。这里有一个SO link https://stackoverflow.com/questions/6766333/capture-windows-screen-with-ffmpeg更详细一点。
如果你真的坚持做一些跨平台的东西,那么我建议深入研究带有 python 绑定的 openCV 并使用帧缓冲设备作为视频输入,将结果缩小到 1x1 像素,并使用生成的颜色平均值来驱动你的 pwm 通过一些UDP 广播类型。