title: How do you detect the rgb value of some pixels from a png, in python?
body: <p>My code takes a screenshot, (should) test if any of the pixels in the screenshot are a general rgb value (in my example they are in the range of: r_min, r_max and g_min, g_max. Also, the end_time is there to make sure that there is enough time to scan all the pixels, since it will then screenshot another photo, and check for the pixels in the other one, until it finds the specific pixels, after that, it changes the value of variable (fish_found) from 0 to 1, and gets through the if statement.</p>
  <p>This is the code that I came up with:</p>
  <pre><code>    fish_found = 0
      im = screenshot('check.png')
      def find_fish(image_name):
  
          r_min = 140
          r_max = 190
          g_min = 85
          g_max = 185
          fish_found = 0
          img = Image.open(image_name)
          rgb = img.convert('RGB')
          for x in range(img.size[0]):
              for y in range(img.size[1]):
                  r, g, b = rgb.getpixel((x, y))
                  if r &gt;= r_min and r &lt;= r_max and g &gt;= g_min and g &lt;= g_max:
                      fish_found = fish_found + 1
  
      while True:
          im = screenshot('check.png', region=(990,415,20,20))
          end_time = datetime.now() + timedelta(seconds=0.5)
          while datetime.now() &lt; end_time:
              find_fish('check.png')
          print(fish_found)
          if fish_found &gt; 0:
              print(&quot;You found a fish&quot;)
  </code></pre>