I'm not quite sure what's going on here. I'm trying to make it play a sound when the darkest part of the feed from my web-cam is in a particular location in the display. When I run it I get this error
File "/home/phur/Documents/052617/052617.py", line 42, in piano if par[100, 200] == surface.map_rgb((0, 0, 0)): TypeError: 'NoneType' object has no attribute 'getitem' (0, 0)
Here's my code:
import pygame
import pygame.camera
from pygame.locals import *
import time
import random
import Image
pygame.init()
pygame.camera.init()
size = (640, 480)
md = pygame.display.set_mode(size, 0)
pygame.display.set_caption("Piano")
def piano():
stop_playing = False
camera = pygame.camera.Camera('/dev/video0', size)
camera.start()
while not stop_playing:
captured = camera.get_image(md)
md.blit(captured, (0, 0))
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
stop_playing = True
mp = pygame.mouse.get_pos()
par = pygame.PixelArray.surface.__init__()
print mp
for x in range(0, 213):
for y in range(0, 240):
if par[x, y] == pygame.surface.map_rgb((0, 0, 0)):
pygame.mixer.music.load("C1.wav")
pygame.mixer.music.play()
time.sleep(1)
for x in range(214, 426):
for y in range(0, 240):
if par[x, y] == pygame.surface.map_rgb((0, 0, 0)):
pygame.mixer.music.load("D1.wav")
pygame.mixer.music.play()
time.sleep(1)
for x in range(427, 640):
for y in range(0, 240):
if par[x, y] == pygame.surface.map_rgb((0, 0, 0)):
pygame.mixer.music.load("E1.wav")
pygame.mixer.music.play()
time.sleep(1)
for x in range(0, 320):
for y in range(241, 480):
if par[x, y] == pygame.surface.map_rgb((0, 0, 0)):
pygame.mixer.music.load("F1.wav")
pygame.mixer.music.play()
time.sleep(1)
for x in range(321, 640):
for y in range(241, 480):
if par[x, y] == pygame.surface.map_rgb((0, 0, 0)):
pygame.mixer.music.load("G1.wav")
pygame.mixer.music.play()
time.sleep(1)
piano()
quit()