简体   繁体   English

图像读取RGB颜色?

[英]Image reading for RGB colors?

How can I take an image, and read each pixel in the image, and determine if it is green or not. 如何拍摄图像,读取图像中的每个像素,然后确定它是否为绿色。 If the former, return true, if the latter, return false. 如果是前者,则返回true;如果是后者,则返回false。 By green I don't mean 100% green, I meam like greener then red. 绿色不是100%绿色,而是绿色和红色。 (if you know what I mean). (如果你明白我的意思)。 After that, it should output the x, y of the green spot. 之后,它应该输出绿点的x,y。 Now, since its not only going to be one pixel, it would be fine if it lowered the resoloution before hand to maximize speed. 现在,由于它不仅将是一个像素,所以如果可以事先降低分辨率以最大化速度,那就很好了。 I have heard of the Image library, but I haven't seen a way to read each pixel and return its RGB value. 我听说过图片库,但是还没有一种读取每个像素并返回其RGB值的方法。

Also, it would be appreciated if you can also guide me in the direction of taking video (well, one image every so seconds.) and then manipulating those images, and returning an array of tuples. 另外,如果您还可以指导我朝拍摄视频的方向(好吧,每隔几秒钟就拍一张图像),然后操纵这些图像,并返回一个元组数组的方向,将不胜感激。 Thanks! 谢谢!

The PIL ( Python Image Library ) will give you some of the functionality you are asking about. PIL( Python图像库 )将为您提供一些您所要求的功能。 This example shows you how to open a .gif file and examine the RGB values at a given location. 本示例说明如何打开.gif文件并检查给定位置的RGB值。

import Image

im = Image.open('image.gif')
rgb_im = im.convert('RGB')
r, g, b = rgb_im.getpixel((1, 1))

print r, g, b
(65, 100, 137)

Here are the supported Image formats and here is a basic tutorial . 这是受支持的图像格式 ,这是基本教程

The PIL is pretty popular, you should be able to find additional examples and documentation via google. PIL非常受欢迎,您应该可以通过Google找到更多示例和文档 Also there is no official support for Python 3.x (yet?), but you can get an unofficial version of the PIL here - looks like Windows only though. 此外,还没有对Python 3.x的官方支持(还可以吗?),但是您可以在此处获得PIL的非官方版本-虽然看起来像Windows。

Another tutorial . 另一个教程

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM