Sunday, 23 June 2013

Logitech C920 image for OpenCV testing


























Now I have edited a 600 x 400, 24 bit BMP for playing with OpenCV.

,END


ftwebcam.TestWebcamCamera09(cameraNumber = 0, imageSize = (1280, 720), imageCount = 16, timerSecond = 1, fileName = "file2013jun23hkt1452.bmp")



# ftwebcam v0.8 tlfong01 2013jun19

# *****************************************************************************
# 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 os
import pygame
import pygame.camera
from pygame.locals import *

import ftprint

# *****************************************************************************
# Function - TestWebcam()
# Notes -
#   * BenQ 737s 17" LCD monitor native Resolution 1280 x 1024
#   * C920 image size = HD1080 (1920 x 1080), HD720 (1280 x 720)
#   * pygame error: No video mode large enough for 1920 x 1080
#   * $ lsusb -d 046d:0825 Logitech Webcam C270
#   * $ lsusb -d 046d:082d Logitech Webcam C920
# *****************************************************************************

Size640x480 = (640, 480)
Size1280x720 = (1280, 720)
Size1280x1024 = (1280, 1024) # ValueError: Destination surface not the correct width or height
Size1920x1080 = (1920, 1080) # pygame.error: No video mode large enough for 1920x1080

def TestWebcamCamera10(cameraNumber, imageSize, imageCount, timerSecond, fileName):

    ftprint.PrintDoubleSpaceLine("*** Sample run begin - TestWebCamCamera08() 2013jun18hkt10:54 ***")  

    pygame.init()
    pygame.camera.init()

    webCamList = pygame.camera.list_cameras()
    webCamCount = len(webCamList)
    print "Number of cameras found = ", webCamCount
    print "Camera used = ", cameraNumber
    print "Image size = (", imageSize[0], ", ", imageSize[1], ")"
    print "Number of images to get = ", imageCount
    print "Time between images (in seconds) = ", timerSecond

    imageSize = Size1280x720 # debug only !!!

    webCamCamera = pygame.camera.Camera(webCamList[int(cameraNumber)], imageSize)
    webCamCamera.start()

    pygame.display.init()
    webCamDisplay = pygame.display.set_mode(imageSize, 0)

    webCamSurface = pygame.surface.Surface(imageSize, 0, webCamDisplay)

    for count in range(imageCount):

        for event in pygame.event.get(): # Escape key from local keyboard, NOT PuTTY!!!
   if (event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE)):                                
                webCamCamera.stop()
                pygame.quit()
return

   if (event.type == KEYDOWN and event.key == K_x):                                
                webCamCamera.stop()
                pygame.quit()
return

   if (event.type == KEYDOWN and event.key == K_s):
       fullPathFileName = os.path.join('/home/pi/fongtoy/', fileName)
                pygame.image.save(webCamSurface, fullPathFileName)
print "Image saved"        

if webCamCamera.query_image():
            webCamSurface = webCamCamera.get_image(webCamSurface)
            webCamDisplay.blit(webCamSurface, (0,0))
            pygame.display.flip()

        time.sleep(timerSecond)
print "Image number = ", count

    pygame.image.save(webCamSurface, "/home/pi/fongtoy/testImage.bmp")

    print "File name of last image = /home/pi/fongtoy/testImage.bmp",

    ftprint.PrintDoubleSpaceLine("*** Sample run end ***")

.END

No comments:

Post a Comment