I want to read two points in a picture.
Most pixel values will be (0,0,0).
I don't know how to take the flatted data and separate it into x,y coordinates.

I use the Image library and VideoCaputre.

i don't know much about Image library, but it's quite easy todo with pygame:

# import pygame
import pygame
from pygame.locals import *

# import our picture
image = pygame.image.load('picture.bmp')

for x in image.get_width():
   for y in image.get_height():
      # for each pixel in the image, print out it's RGB format, or RGBX (rgb and then transparency, I believe)
      print('%s' % str(image.get_at((x,y)) )

This is the code I have so far. I decided to go with the Image module
for reading the picture instances. I use pygame to display what everything is doing.
Its working well, except when I bring one dot1 higher than dot2
then bring dot2 higher than dot1 the program reverses the d.bmp and d2.bmp.

I don't know if I explained it well enough to understand what's happening.

You can test it for yourself to see.
You'll need PIL, Pysco, VideoCaputre, and pygame
I filter all light except IR. I do this with a negative from a film strip
placed over the lens of the web cam. I use three layers.

It eats about half of my CPU Usage.
I have an intel Centrino Due Core
Vista Home 64bit
4 gig RAM

#hopeit with two IR points
#mouse control proto
#K.B. Carte
# d.bmp and d2.bmp are two 7X5 images to show the two
#seprate points. one is red the other is blue.


import VideoCapture
from VideoCapture import Device
import Image, sys, pygame, time
from pygame.locals import *
from psyco import full

full()

cam = Device()
pygame.init()
screen = pygame.display.set_mode((640,480))
font = pygame.font.SysFont("Curier",26)
d = pygame.image.load('d.bmp')
dT = pygame.image.load('d2.bmp')


def xy(im):
    imxy = []
    x = 0
    y = 0
    while x*y <= 307200:
        if im.getpixel((x,y)) >= (200,200,200):
            imxy.append((x,y))
        x += 1
        if x == 640:
            x = 0
            y += 1
        if y == 480:
          return imxy
      
    


while 1:
  try:
    for event in pygame.event.get():
        if event.type == pygame.QUIT: sys.exit()
    imc = cam.getImage()
    bg = pygame.Surface(screen.get_size())
    bg = bg.convert()
    bg.fill((0,0,0))
    dots = xy(imc)
    if dots:
        dOne = dots[0]
        dTwo = dots[1]
        imc = pygame.image.frombuffer(imc.tostring(), (640,480), "RGB")
        bg.blit(imc, (0,0))
        bg.blit(d, dOne)
        bg.blit(dT, dTwo)
        screen.blit(bg, (0,0))
        pygame.draw.line(screen, (255,255,255), dOne, dTwo)
        pygame.display.flip()
    else:
        pass
  except IndexError:
      pass

Don't you think you could save some CPU usage if you replaced the "while 1" by a timer which would run the loop at a certain frequency ?

I'm kind of new to programming. And the only way I know how is with a while loop.

loop:

def main():
   print('in main..')

if '__name__' == '__main__':
   main()

that should work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.