contcapt.py :  » Language-Interface » ChinesePython » chinesepython2.1.3-0.4 » Demo » sgi » sv » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » ChinesePython 
ChinesePython » chinesepython2.1.3 0.4 » Demo » sgi » sv » contcapt.py
import sys
import sv, SV
import gl, GL, DEVICE

def main():
  format = SV.RGB8_FRAMES
  framerate = 25
  queuesize = 16
  samplingrate = 2

  v = sv.OpenVideo()
  # Determine maximum window size based on signal standard
  param = [SV.BROADCAST, 0]
  v.GetParam(param)
  if param[1] == SV.PAL:
    width = SV.PAL_XMAX
    height = SV.PAL_YMAX
    framefreq = 25
  else:
    width = SV.NTSC_XMAX
    height = SV.NTSC_YMAX
    framefreq = 30

  # Allow resizing window if capturing RGB frames, which can be scaled
  if format == SV.RGB8_FRAMES:
    gl.keepaspect(width, height)
    gl.maxsize(width, height)
    gl.stepunit(8, 6)
    gl.minsize(120, 90)
  else:
    if format == SV.YUV411_FRAMES_AND_BLANKING_BUFFER:
      height = height + SV.BLANKING_BUFFER_SIZE
    gl.prefposition(300, 300+width-1, 100, 100+height-1)

  # Open the window
  gl.foreground()
  win = gl.winopen('Continuous Capture')
  gl.RGBmode()
  gl.gconfig()
  if format == SV.RGB8_FRAMES:
    width, height = gl.getsize()
    gl.pixmode(GL.PM_SIZE, 8)
  else:
    gl.pixmode(GL.PM_SIZE, 32)

  svci = (format, width, height, queuesize, samplingrate)
  [svci]

  svci = v.InitContinuousCapture(svci)
  width, height = svci[1:3]
  [svci]

  hz = gl.getgdesc(GL.GD_TIMERHZ)
  gl.noise(DEVICE.TIMER0, hz / framerate)
  gl.qdevice(DEVICE.TIMER0)
  gl.qdevice(DEVICE.WINQUIT)
  gl.qdevice(DEVICE.WINSHUT)
  gl.qdevice(DEVICE.ESCKEY)

  ndisplayed = 0
  lastfieldID = 0

  while 1:
    dev, val = gl.qread()
    if dev == DEVICE.REDRAW:
      oldw = width
      oldh = height
      width, height = gl.getsize()
      if oldw != width or oldh != height:
        v.EndContinuousCapture()
        gl.viewport(0, width-1, 0, height-1)
        svci = (svci[0], width, height) + svci[3:]
        svci = v.InitContinuousCapture(svci)
        width, height = svci[1:3]
        [svci]
        if ndisplayed:
          print 'lost',
          print fieldID/(svci[4]*2) - ndisplayed,
          print 'frames'
        ndisplayed = 0
    elif dev == DEVICE.TIMER0:
      try:
        captureData, fieldID = v.GetCaptureData()
      except sv.error, val:
        if val <> 'no data available':
          print val
        continue
      if fieldID - lastfieldID <> 2*samplingrate:
        print lastfieldID, fieldID
      lastfieldID = fieldID
      if svci[0] == SV.RGB8_FRAMES:
        rgbbuf = captureData.InterleaveFields(1)
      else:
        rgbbuf = captureData.YUVtoRGB(1)
      captureData.UnlockCaptureData()
      gl.lrectwrite(0, 0, width-1, height-1, rgbbuf)
      ndisplayed = ndisplayed + 1
    elif dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT):
      v.EndContinuousCapture()
      v.CloseVideo()
      gl.winclose(win)
      print fieldID, ndisplayed, svci[4]
      print 'lost', fieldID/(svci[4]*2) - ndisplayed,
      print 'frames'
      return

main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.