ftwebcam.TestWebcamCamera05()
def TestWebcamCamera05():
ftprint.PrintDoubleSpaceLine("*** Sample run begin - TestWebCamCamera05() 2013jun15hkt12:07 ***")
Size640x480 = (640, 480)
Size1280x1024 = (1280, 1024)
Size1920x1024 = (1920, 1024)
pygame.init()
pygame.camera.init()
webCamList = pygame.camera.list_cameras()
webCamCount = len(webCamList)
print "Number of web cameras found = ", webCamCount
webCamNumber = raw_input("Enter camera number now: ")
webCamCamera = pygame.camera.Camera(webCamList[int(webCamNumber)], Size640x480)
webCamCamera.start()
pygame.display.init()
webCamDisplay = pygame.display.set_mode(Size640x480, 0)
webCamSurface = pygame.surface.Surface(Size640x480, 0, webCamDisplay)
escapeOrQuitKeyPressed = False
while (escapeOrQuitKeyPressed == False):
inputEvents = pygame.event.get()
for e in inputEvents:
if (e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE)): # !!! Not working !!!
escapeOrQuitKeyPressed == True
break
if escapeOrQuitKeyPressed == True: # !!! Not working !!!
webCamCamera.stop()
pygame.quit()
else:
if webCamCamera.query_image(): # !!! This part OK !!!
webCamSurface = webCamCamera.get_image(webCamSurface)
webCamDisplay.blit(webCamSurface, (0,0))
pygame.display.flip()
ftprint.PrintDoubleSpaceLine("*** Sample run end ***")
# ftwebcam v0.6 tlfong01 2013jun15
# *****************************************************************************
# Module - ftwebcam.py
# Description - Test Logitech webcam C920 and C270
# Reference
# Pygame.camera Reference - http://www.pygame.org/docs/ref/camera.html
# Pygame.camera Turorial - http://www.pygame.org/docs/tut/camera/CameraIntro.html
# Notes
# Logitech C920 spec
# Image zise 2MP 16:9 = 1920 * 1080 = 2,073,600
# Benq FP737s 17" LCD Monitor spec
# Maximum resoltuion = 1280 x 1024
# Motion setting
# /etc/motion/motion.conf setting
# Daemon = off
# webcam_localhost = on
# /etc/default/motion setting
# start_motion_daemon = no
# *****************************************************************************
# *****************************************************************************
# Imports
# *****************************************************************************
import time
import pygame
import pygame.camera
from pygame.locals import *
import ftprint
# *****************************************************************************
# Function - TestWebcam()
# Description -
# Test Webcam
# Notes -
# To save surface to file - pygame.image.save(webCamSurface, "/home/pi/fongtoy/testImage.bmp")
# *****************************************************************************
def TestWebcamCamera05():
ftprint.PrintDoubleSpaceLine("*** Sample run begin - TestWebCamCamera05() 2013jun15hkt12:07 ***")
Size640x480 = (640, 480)
Size1280x1024 = (1280, 1024)
Size1920x1024 = (1920, 1024)
pygame.init()
pygame.camera.init()
webCamList = pygame.camera.list_cameras()
webCamCount = len(webCamList)
print "Number of web cameras found = ", webCamCount
webCamNumber = raw_input("Enter camera number now: ")
webCamCamera = pygame.camera.Camera(webCamList[int(webCamNumber)], Size640x480)
webCamCamera.start()
pygame.display.init()
webCamDisplay = pygame.display.set_mode(Size640x480, 0)
webCamSurface = pygame.surface.Surface(Size640x480, 0, webCamDisplay)
escapeOrQuitKeyPressed = False
while (escapeOrQuitKeyPressed == False):
inputEvents = pygame.event.get()
for e in inputEvents:
if (e.type == QUIT or (e.type == KEYDOWN and e.key == K_ESCAPE)): # !!! Not working !!!
escapeOrQuitKeyPressed == True
break
if escapeOrQuitKeyPressed == True: # !!! Not working !!!
webCamCamera.stop()
pygame.quit()
else:
if webCamCamera.query_image(): # !!! This part OK !!!
webCamSurface = webCamCamera.get_image(webCamSurface)
webCamDisplay.blit(webCamSurface, (0,0))
pygame.display.flip()
ftprint.PrintDoubleSpaceLine("*** Sample run end ***")
# *** Old functions ***********************************************************
def TestWebcam03(imageHoldSeconds):
ftprint.PrintDoubleSpaceLine("*** Sample run begin - Test web cam 2013jun12hkt16:23 ***")
Size640x480 = (640, 480)
Size1280x1024 = (1280, 1024)
Size1920x1024 = (1920, 1024)
pygame.init()
pygame.camera.init()
webCamList = pygame.camera.list_cameras()
if webCamList:
print "List of available cameras = ", webCamList
else:
print "!!! No camera!!! "
# webCam = pygame.camera.Camera(webCamList[0], Size1280x1024)
webCam = pygame.camera.Camera(webCamList[0], Size640x480)
webCam.start()
pygame.display.init()
# webCamDisplay = pygame.display.set_mode(Size1280x1024, 0)
webCamDisplay = pygame.display.set_mode(Size640x480, 0)
# webCamSurface = pygame.surface.Surface(Size1280x1024, 0, webCamDisplay)
webCamSurface = pygame.surface.Surface(Size640x480, 0, webCamDisplay)
webCamSurface = webCam.get_image(webCamSurface)
time.sleep(0.1)
webCamDisplay.blit(webCamSurface, (0,0))
pygame.display.flip()
time.sleep(imageHoldSeconds)
# pygame.image.save(webCamSurface, "/home/pi/fongtoy/testImage.bmp")
webCam.stop()
pygame.quit()
ftprint.PrintDoubleSpaceLine("*** Sample run end ***")
def TestWebcamCamera04():
ftprint.PrintDoubleSpaceLine("*** Sample run begin - TestWebCamCamera04() 2013jun14hkt21:13 ***")
Size640x480 = (640, 480)
Size1280x1024 = (1280, 1024)
Size1920x1024 = (1920, 1024)
pygame.init()
pygame.camera.init()
webCamList = pygame.camera.list_cameras()
if webCamList:
print "List of available cameras = ", webCamList
else:
print "!!! No camera!!! "
# webCam = pygame.camera.Camera(webCamList[0], Size1280x1024)
webCamCamera = pygame.camera.Camera(webCamList[0], Size640x480)
webCamCamera.start()
pygame.display.init()
# webCamDisplay = pygame.display.set_mode(Size1280x1024, 0)
webCamDisplay = pygame.display.set_mode(Size640x480, 0)
# webCamSurface = pygame.surface.Surface(Size1280x1024, 0, webCamDisplay)
webCamSurface = pygame.surface.Surface(Size640x480, 0, webCamDisplay)
while True:
if webCamCamera.query_image():
webCamSurface = webCamCamera.get_image(webCamSurface)
webCamDisplay.blit(webCamSurface, (0,0))
pygame.display.flip()
# pygame.image.save(webCamSurface, "/home/pi/fongtoy/testImage.bmp")
webCamCamera.stop()
pygame.quit()
ftprint.PrintDoubleSpaceLine("*** Sample run end ***")
def TestWebcam03(imageHoldSeconds):
ftprint.PrintDoubleSpaceLine("*** Sample run begin - Test web cam 2013jun12hkt16:23 ***")
Size640x480 = (640, 480)
Size1280x1024 = (1280, 1024)
Size1920x1024 = (1920, 1024)
pygame.init()
pygame.camera.init()
webCamList = pygame.camera.list_cameras()
if webCamList:
print "List of available cameras = ", webCamList
else:
print "!!! No camera!!! "
# webCam = pygame.camera.Camera(webCamList[0], Size1280x1024)
webCam = pygame.camera.Camera(webCamList[0], Size640x480)
webCam.start()
pygame.display.init()
# webCamDisplay = pygame.display.set_mode(Size1280x1024, 0)
webCamDisplay = pygame.display.set_mode(Size640x480, 0)
# webCamSurface = pygame.surface.Surface(Size1280x1024, 0, webCamDisplay)
webCamSurface = pygame.surface.Surface(Size640x480, 0, webCamDisplay)
webCamSurface = webCam.get_image(webCamSurface)
time.sleep(0.1)
webCamDisplay.blit(webCamSurface, (0,0))
pygame.display.flip()
time.sleep(imageHoldSeconds)
# pygame.image.save(webCamSurface, "/home/pi/fongtoy/testImage.bmp")
webCam.stop()
pygame.quit()
ftprint.PrintDoubleSpaceLine("*** Sample run end ***")
def TestWebcam():
ftprint.PrintDoubleSpaceLine("*** Sample run begin - Test web cam 2013jun12hkt16:23 ***")
webCamWidth = 640
webCamHeight = 480
webCamWidth = 1920
webCamHeight = 1024
pygame.init()
pygame.camera.init()
webCamList = pygame.camera.list_cameras()
if webCamList:
print "List of available cameras = ", webCamList
webCam = pygame.camera.Camera(webCamList[0],(webCamWidth, webCamHeight))
webCam.start()
imageSurface = webCam.get_image()
pygame.image.save(imageSurface, "/home/pi/fongtoy/testImage.bmp")
webCam.stop()
pygame.quit()
ftprint.PrintDoubleSpaceLine("*** Sample run end ***")
def TestWebcam01():
# *** Program begin message ***
ftprint.PrintDoubleSpaceLine("*** Sample run begin - Test web cam 2013jun12hkt16:23 ***")
# *** Image/Display size ***
# * Vga *
VgaSize = (640, 480)
# * Logitech C920 *
LogitechC920size = (1920, 1024)
# *** initialize pygame.camera module ***
pygame.init()
pygame.camera.init()
pygame.display.get_wm_info()
# *** Create and start webcam object ***
webCamList = pygame.camera.list_cameras()
if webCamList:
print "List of available cameras = ", webCamList
else:
print "!!! No camera!!! "
webCam = pygame.camera.Camera(webCamList[0],VgaSize)
webCam.start()
# *** Create a display ***
pygame.display.init()
webCamDisplay = pygame.display.set_mode(VgaSize, 0)
# *** Create a surface ***
webCamSurface = pygame.surface.Surface(VgaSize, 0, webCamDisplay)
# *** Get surface ***
webCamSurface = webCam.get_image(webCamSurface)
time.sleep(0.1)
# *** Display surface ***
webCamDisplay.blit(webCamSurface, (0,0))
pygame.display.flip()
time.sleep(1)
# *** Save surface as a BMP file ***
# pygame.image.save(webCamSurface, "/home/pi/fongtoy/testImage.bmp")
# *** stop webcam, quit pygame ***
webCam.stop()
pygame.quit()
# *** Print program end message ***
ftprint.PrintDoubleSpaceLine("*** Sample run end ***")
# .END
# fongtoy v1.11 tlfong01 2013jun15
ProgramTitle = "FongToy v1.11 tlfong01 2013jun15"
import sys
import time
import smbus
import pdb
import spidev
import wiringpi
import wiringpi2
import RPIO as GPIO
from RPIO import PWM
from enum import Enum
from subprocess import call
import ftgpio
import ftprint
import ftspi
import ftiox
import fteeprom
import ftguzuntypi
import ftdemux
import fttest
import ftadc
import ftwebcam
# *** Troubleshooting functions ***
# *** GPIO tests v1.3 tlfong01 2013may23 ***
# ftgpio.TestLed()
# ftgpio.TestBuzzer()
# ftgpio.TestButtonEchoBuzzer()
# ftgpio.TestButtonEchoLed()
# *** SPI Tests v1.3 tlfong01 2013may23 ***
# ftdemux.TestSelectSpiSlaveDevice(spiChannelNumber = 0, spiChipEnableNumber = 0, spiIoxSubAddress = 0, spiSlaveDeviceNumber = 5)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 2, testStartAddress = 0x0123, testWriteDataByte = 0x5a)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 1, testStartAddress = 0x0123, testWriteDataByte = 0x3b)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 0, testStartAddress = 0x0123, testWriteDataByte = 0x3b)
# ftiox.TestMcp23s17BlinkLed(spiChannelNumber = 0, spiChipEnableNumber = 0, spiChipSubAddress = 0)
# ftdemux.TestSelectSpiSlaveDevice(spiChannelNumber = 0, spiChipEnableNumber = 0, spiIoxSubAddress = 0, spiSlaveDeviceNumber = 5)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 0, testStartAddress = 0x0123, testWriteDataByte = 0x3b)
# fttest.TestDemuxEeprom(mcp23s17SubAddress = 0, eepromDemuxAddress = 1, testStartAddress = 0x0411, testWriteDataByte = 0x4c)
# fttest.TestDemuxGuzuntyClock(mcp23s17SubAddress = 0, guzuntyClockDemuxAddress = 2, secondCount = 10)
# *** Main program ***
# *** Start program message ***
ftprint.StartProgram(ProgramTitle)
# *** Main tests ***
# *** SPI loop back ***
# ftspi.TestSpiLoopBackV01(spiChannelNumber = 0, spiChipEnableNumber = 1, testDataByte = 0x55, testTime = 0.001, testCount = 60000)
# *** ADC ***
# ftadc.TestMcp3208v03()
# ftadc.TestMcp3201v04()
# *** EEPROM ***
# fteeprom.TestEeporm25Lc256v01(spiChannelNumber = 0, spiChipEnableNumber = 1, startAddress = 0x4100, testDataByte = 0x55)
# *** Mcp23s17 ***
# ftiox.TestMcp23s17BlinkLed(spiChannelNumber = 0, spiChipEnableNumber = 0, spiChipSubAddress = 0)
# *** Demux ***
# ftdemux.TestDemuxV01(spiChannelNumber = 0, spiChipEnableNumber = 0, spiIoxSubAddress = 0, spiSlaveDeviceNumber = 5)
# *** Guzunty Pi Step Motor ***
# ... test functions already moved to ftguzunti.py tlfong01 2013jun10 ...
# *** Webcam ***
# ftwebcam.TestWebcam()
# ftwebcam.TestWebcam01()
# ftwebcam.TestWebcam03(imageHoldSeconds = 10)
# ftwebcam.TestWebcamCamera04()
ftwebcam.TestWebcamCamera05()
# *** Stop program message ***
ftprint.StopProgram()
# .END
.END
No comments:
Post a Comment