I'm trying to iterate a pygame 3d surfarray, more specifically pygame.surfarray.array3d("your image")
. I'm receiving video captured from my webcam then converting them into a 3d array, then displaying it onto my window with this code.
def cameraSee(self):
while True:
self.cam.query_image()
self.image = self.cam.get_image()
self.imageArr = pygame.surfarray.array3d(self.image)
pygame.surfarray.blit_array(self.screen,self.imageArr)
os.system("clear")
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
My problem is that I'm trying to have my camera only display any pixel which has an amount of blue > 200 (ranging from 0 - 255) and change the color value of all other pixels to 0. I've tried using an if statement for an array but I get an error stating that I should be using the any()
or all()
.
all my code:
try:
import pygame
import pygame.camera
import pygame.surfarray
import numpy
import os
import sys
import time
except:
print("there was an error importing modules...")
os.system("espeak 'there, was, an, error, importing, modules'")
time.sleep(2)
class aaiVision(object):
def __init__(self,screen,cam,image,imageArr):
self.screen = screen
self.cam = cam
self.image = image
self.imageArr = imageArr
def startUp(self):
os.system("espeak 'eh, eh, i, vision, initializing'")
pygame.init()
pygame.camera.init()
time.sleep(1)
os.system("espeak 'Vision, initialized'")
camList = pygame.camera.list_cameras()
print(camList)
time.sleep(1)
os.system("espeak 'cameras, found, %s'" % str(len(camList)))
time.sleep(1)
self.screen = pygame.display.set_mode((640,480))
time.sleep(0.5)
self.cam = pygame.camera.Camera("/dev/video0",(640,480),"YUV")
time.sleep(0.5)
self.cam.start()
os.system("espeak 'eh, eh, i, vision, online'")
def cameraSee(self):
while True:
self.cam.query_image()
self.image = self.cam.get_image()
self.imageArr = pygame.surfarray.array3d(self.image)
pygame.surfarray.blit_array(self.screen,self.imageArr)
os.system("clear")
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
eyesAwake = aaiVision('', '', '', '')
if __name__ == "__main__":
eyesAwake.startUp()
eyesAwake.cameraSee()
Sorry about some of the indentation errors, I'm not sure how to use the in text code blocks XD