def saveframes(vout, queue, done, mono, monotreshold, convertor): while 1: x = queue.get() if not x: break data, t = x if convertor: data = convertor(data, len(data), 1) elif mono and monotreshold >= 0: data = imageop.grey2mono(data, len(data), 1,\ monotreshold) elif mono: data = imageop.dither2mono(data, len(data), 1) vout.writeframe(t, data, None) sys.stderr.write('Done writing video\n') vout.close() done.release_lock()
def write_frame(self, t, data): t = t * self.speed_factor if not self.vout: gl.ringbell() return 0 if self.convertor: data = self.convertor(data, len(data), 1) elif self.mono: if self.mono_use_thresh: data = imageop.grey2mono(data, \ len(data), 1,\ self.mono_thresh) else: data = imageop.dither2mono(data, \ len(data), 1) try: self.vout.writeframe(int(t), data, None) except IOError, msg: self.reset() if msg == (0, 'Error 0'): msg = 'disk full??' fl.show_message('IOError', str(msg), '') return 0
#! /usr/bin/env python
skipstretch = skipstretch + 1 continue if skipstretch: print skipstretch, 'skipped' skipstretch = 0 okstretch = okstretch + 1 # # Save field. # XXXX Works only for fields and top-to-bottom # start = frameno*fieldsize field = data[start:start+fieldsize] if convertor: field = convertor(field, len(field), 1) elif mono and monotreshold >= 0: field = imageop.grey2mono( \ field, len(field), 1, monotreshold) elif mono: field = imageop.dither2mono( \ field, len(field), 1) realframeno = realframeno + 1 vout.writeframe(int(realframeno*tpf), field, None) print okstretch, 'ok', print skipstretch, 'skipped' print 'Skipped', nskipped, 'duplicate frames' vout.close() gl.wintitle('(done) ' + filename) # Initialize audio recording AQSIZE = 8*8000 # XXX should be a user option
def main(use_rgbimg=1): # Create binary test files uu.decode(get_qualified_path('testrgb' + os.extsep + 'uue'), 'test' + os.extsep + 'rgb') if use_rgbimg: image, width, height = getrgbimage('test' + os.extsep + 'rgb') else: image, width, height = getimage('test' + os.extsep + 'rgb') # Return the selected part of image, which should by width by height # in size and consist of pixels of psize bytes. if verbose: print 'crop' newimage = imageop.crop(image, 4, width, height, 0, 0, 1, 1) # Return image scaled to size newwidth by newheight. No interpolation # is done, scaling is done by simple-minded pixel duplication or removal. # Therefore, computer-generated images or dithered images will # not look nice after scaling. if verbose: print 'scale' scaleimage = imageop.scale(image, 4, width, height, 1, 1) # Run a vertical low-pass filter over an image. It does so by computing # each destination pixel as the average of two vertically-aligned source # pixels. The main use of this routine is to forestall excessive flicker # if the image two vertically-aligned source pixels, hence the name. if verbose: print 'tovideo' videoimage = imageop.tovideo(image, 4, width, height) # Convert an rgb image to an 8 bit rgb if verbose: print 'rgb2rgb8' greyimage = imageop.rgb2rgb8(image, width, height) # Convert an 8 bit rgb image to a 24 bit rgb image if verbose: print 'rgb82rgb' image = imageop.rgb82rgb(greyimage, width, height) # Convert an rgb image to an 8 bit greyscale image if verbose: print 'rgb2grey' greyimage = imageop.rgb2grey(image, width, height) # Convert an 8 bit greyscale image to a 24 bit rgb image if verbose: print 'grey2rgb' image = imageop.grey2rgb(greyimage, width, height) # Convert a 8-bit deep greyscale image to a 1-bit deep image by # thresholding all the pixels. The resulting image is tightly packed # and is probably only useful as an argument to mono2grey. if verbose: print 'grey2mono' monoimage = imageop.grey2mono(greyimage, width, height, 0) # monoimage, width, height = getimage('monotest.rgb') # Convert a 1-bit monochrome image to an 8 bit greyscale or color image. # All pixels that are zero-valued on input get value p0 on output and # all one-value input pixels get value p1 on output. To convert a # monochrome black-and-white image to greyscale pass the values 0 and # 255 respectively. if verbose: print 'mono2grey' greyimage = imageop.mono2grey(monoimage, width, height, 0, 255) # Convert an 8-bit greyscale image to a 1-bit monochrome image using a # (simple-minded) dithering algorithm. if verbose: print 'dither2mono' monoimage = imageop.dither2mono(greyimage, width, height) # Convert an 8-bit greyscale image to a 4-bit greyscale image without # dithering. if verbose: print 'grey2grey4' grey4image = imageop.grey2grey4(greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image without # dithering. if verbose: print 'grey2grey2' grey2image = imageop.grey2grey2(greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image with # dithering. As for dither2mono, the dithering algorithm is currently # very simple. if verbose: print 'dither2grey2' grey2image = imageop.dither2grey2(greyimage, width, height) # Convert a 4-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey42grey' greyimage = imageop.grey42grey(grey4image, width, height) # Convert a 2-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey22grey' image = imageop.grey22grey(grey2image, width, height) # Cleanup unlink('test' + os.extsep + 'rgb')
tpf = 1000 / 50.0 #XXXX for frameno in range(0, number * 2): if frameno <> 0 and \ bitvec[frameno] == bitvec[frameno-1]: nskipped = nskipped + 1 continue # # Save field. # XXXX Works only for fields and top-to-bottom # start = frameno * fieldsize field = data[start:start + fieldsize] if convertor: field = convertor(field, x, y) elif mono and monotreshold >= 0: field = imageop.grey2mono(field, x, y, \ 1, monotreshold) elif mono: field = imageop.dither2mono(field, x, y) vout.writeframe(int(realframeno * tpf), field, None) print 'Skipped', nskipped, 'duplicate frames' vout.close() gl.wintitle('(done) ' + filename) # Don't forget to call the main program try: main() except KeyboardInterrupt: print '[Interrupt]'
def main(use_rgbimg=1): # Create binary test files uu.decode(get_qualified_path('testrgb'+os.extsep+'uue'), 'test'+os.extsep+'rgb') if use_rgbimg: image, width, height = getrgbimage('test'+os.extsep+'rgb') else: image, width, height = getimage('test'+os.extsep+'rgb') # Return the selected part of image, which should by width by height # in size and consist of pixels of psize bytes. if verbose: print 'crop' newimage = imageop.crop (image, 4, width, height, 0, 0, 1, 1) # Return image scaled to size newwidth by newheight. No interpolation # is done, scaling is done by simple-minded pixel duplication or removal. # Therefore, computer-generated images or dithered images will # not look nice after scaling. if verbose: print 'scale' scaleimage = imageop.scale(image, 4, width, height, 1, 1) # Run a vertical low-pass filter over an image. It does so by computing # each destination pixel as the average of two vertically-aligned source # pixels. The main use of this routine is to forestall excessive flicker # if the image two vertically-aligned source pixels, hence the name. if verbose: print 'tovideo' videoimage = imageop.tovideo (image, 4, width, height) # Convert an rgb image to an 8 bit rgb if verbose: print 'rgb2rgb8' greyimage = imageop.rgb2rgb8(image, width, height) # Convert an 8 bit rgb image to a 24 bit rgb image if verbose: print 'rgb82rgb' image = imageop.rgb82rgb(greyimage, width, height) # Convert an rgb image to an 8 bit greyscale image if verbose: print 'rgb2grey' greyimage = imageop.rgb2grey(image, width, height) # Convert an 8 bit greyscale image to a 24 bit rgb image if verbose: print 'grey2rgb' image = imageop.grey2rgb(greyimage, width, height) # Convert a 8-bit deep greyscale image to a 1-bit deep image by # thresholding all the pixels. The resulting image is tightly packed # and is probably only useful as an argument to mono2grey. if verbose: print 'grey2mono' monoimage = imageop.grey2mono (greyimage, width, height, 0) # monoimage, width, height = getimage('monotest.rgb') # Convert a 1-bit monochrome image to an 8 bit greyscale or color image. # All pixels that are zero-valued on input get value p0 on output and # all one-value input pixels get value p1 on output. To convert a # monochrome black-and-white image to greyscale pass the values 0 and # 255 respectively. if verbose: print 'mono2grey' greyimage = imageop.mono2grey (monoimage, width, height, 0, 255) # Convert an 8-bit greyscale image to a 1-bit monochrome image using a # (simple-minded) dithering algorithm. if verbose: print 'dither2mono' monoimage = imageop.dither2mono (greyimage, width, height) # Convert an 8-bit greyscale image to a 4-bit greyscale image without # dithering. if verbose: print 'grey2grey4' grey4image = imageop.grey2grey4 (greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image without # dithering. if verbose: print 'grey2grey2' grey2image = imageop.grey2grey2 (greyimage, width, height) # Convert an 8-bit greyscale image to a 2-bit greyscale image with # dithering. As for dither2mono, the dithering algorithm is currently # very simple. if verbose: print 'dither2grey2' grey2image = imageop.dither2grey2 (greyimage, width, height) # Convert a 4-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey42grey' greyimage = imageop.grey42grey (grey4image, width, height) # Convert a 2-bit greyscale image to an 8-bit greyscale image. if verbose: print 'grey22grey' image = imageop.grey22grey (grey2image, width, height) # Cleanup unlink('test'+os.extsep+'rgb')
skipstretch = skipstretch + 1 continue if skipstretch: print skipstretch, 'skipped' skipstretch = 0 okstretch = okstretch + 1 # # Save field. # XXXX Works only for fields and top-to-bottom # start = frameno * fieldsize field = data[start:start + fieldsize] if convertor: field = convertor(field, len(field), 1) elif mono and monotreshold >= 0: field = imageop.grey2mono( \ field, len(field), 1, monotreshold) elif mono: field = imageop.dither2mono( \ field, len(field), 1) realframeno = realframeno + 1 vout.writeframe(int(realframeno * tpf), field, None) print okstretch, 'ok', print skipstretch, 'skipped' print 'Skipped', nskipped, 'duplicate frames' vout.close() gl.wintitle('(done) ' + filename) # Initialize audio recording
#! /usr/bin/env python # Copy a video file, interactively, frame-by-frame. import sys import getopt from gl import * from DEVICE import * import VFile import VGrabber import string import imageop def report(time, iframe): print 'Frame', iframe, ': t =', time def usage(): sys.stderr.write('usage: Vcopy [-t type] [-m threshold] [-a] infile outfile\n') sys.stderr.write('-t Convert to other type\n') sys.stderr.write('-a Automatic\n') sys.stderr.write('-m Convert grey to mono with threshold\n') sys.stderr.write('-d Convert grey to mono with dithering\n') sys.exit(2) def help(): print 'Command summary:' print 'n get next image from input' print 'w write current image to output' class GrabbingVoutFile(VFile.VoutFile, VGrabber.VGrabber): pass def main(): foreground() try: opts, args = getopt.getopt(sys.argv[1:], 't:am:d') except getopt.error, msg:
if c == 'G': c3i(0,255,0) clear() if c == 'B': c3i(0,0,255) clear() if c == 'w' or continuous: if use_grabber: try: data, cdata = ofilm.grabframe() except VFile.Error, msg: print msg break if tomono: data = imageop.grey2mono(data, \ ifilm.width, ifilm.height, \ treshold) if tomonodither: data = imageop.dither2mono(data, \ ifilm.width, ifilm.height) ofilm.writeframe(time, data, cdata) print 'Frame', iframe, 'written.' if c == 'n' or continuous: try: time,data,cdata = ifilm.getnextframe() ifilm.showframe(data, cdata) iframe = iframe+1 report(time, iframe) except EOFError: print 'EOF' if continuous:
if c == 'G': c3i(0, 255, 0) clear() if c == 'B': c3i(0, 0, 255) clear() if c == 'w' or continuous: if use_grabber: try: data, cdata = ofilm.grabframe() except VFile.Error, msg: print msg break if tomono: data = imageop.grey2mono(data, \ ifilm.width, ifilm.height, \ treshold) if tomonodither: data = imageop.dither2mono(data, \ ifilm.width, ifilm.height) ofilm.writeframe(time, data, cdata) print 'Frame', iframe, 'written.' if c == 'n' or continuous: try: time, data, cdata = ifilm.getnextframe() ifilm.showframe(data, cdata) iframe = iframe + 1 report(time, iframe) except EOFError: print 'EOF' if continuous:
#! /usr/bin/env python # Capture a CMIF movie using the Indigo video library and board in burst mode # User interface: # # Start the application. Resize the window to the desired movie size. # Press the left mouse button to start recording, release it to end # recording. You can record as many times as you wish, but each time # you overwrite the output file(s), so only the last recording is # kept. # # Press ESC or select the window manager Quit or Close window option # to quit. If you quit before recording anything, the output file(s) # are not touched. import sys sys.path.append('/ufs/guido/src/video') import sv, SV import VFile import gl, GL, DEVICE import al, AL import time import posix import getopt import string import imageop import sgi # Usage and help functions (keep this up-to-date if you change the program!) def usage():
#! /usr/bin/env python # Copy a video file, interactively, frame-by-frame. import sys import getopt from gl import * from DEVICE import * import VFile import VGrabber import string import imageop def report(time, iframe): print 'Frame', iframe, ': t =', time def usage(): sys.stderr.write( 'usage: Vcopy [-t type] [-m threshold] [-a] infile outfile\n') sys.stderr.write('-t Convert to other type\n') sys.stderr.write('-a Automatic\n') sys.stderr.write('-m Convert grey to mono with threshold\n') sys.stderr.write('-d Convert grey to mono with dithering\n') sys.exit(2) def help(): print 'Command summary:' print 'n get next image from input' print 'w write current image to output' class GrabbingVoutFile(VFile.VoutFile, VGrabber.VGrabber): pass
def main(): foreground() opts, args = getopt.getopt(sys.argv[1:], 't:am:d') if len(args) <> 2: usage() [ifile, ofile] = args print 'open film ', ifile ifilm = VFile.VinFile().init(ifile) print 'open output ', ofile ofilm = VFile.VoutFile().init(ofile) ofilm.setinfo(ifilm.getinfo()) use_grabber = 0 continuous = 0 tomono = 0 tomonodither = 0 for o, a in opts: if o == '-t': ofilm.format = a use_grabber = 1 if o == '-a': continuous = 1 if o == '-m': if ifilm.format <> 'grey': print '-m only supported for greyscale' sys.exit(1) tomono = 1 treshold = string.atoi(a) ofilm.format = 'mono' if o == '-d': if ifilm.format <> 'grey': print '-m only supported for greyscale' sys.exit(1) tomonodither = 1 ofilm.format = 'mono' ofilm.writeheader() # prefsize(ifilm.width, ifilm.height) w = winopen(ifile) qdevice(KEYBD) qdevice(ESCKEY) qdevice(WINQUIT) qdevice(WINSHUT) print 'qdevice calls done' # help() # time, data, cdata = ifilm.getnextframe() ifilm.showframe(data, cdata) iframe = 1 report(time, iframe) # while 1: if continuous: dev = KEYBD else: dev, val = qread() if dev in (ESCKEY, WINQUIT, WINSHUT): break if dev == REDRAW: reshapeviewport() elif dev == KEYBD: if continuous: c = '0' else: c = chr(val) #XXX Debug if c == 'R': c3i(255, 0, 0) clear() if c == 'G': c3i(0, 255, 0) clear() if c == 'B': c3i(0, 0, 255) clear() if c == 'w' or continuous: if use_grabber: data, cdata = ofilm.grabframe() if tomono: data = imageop.grey2mono(data, \ ifilm.width, ifilm.height, \ treshold) if tomonodither: data = imageop.dither2mono(data, \ ifilm.width, ifilm.height) ofilm.writeframe(time, data, cdata) print 'Frame', iframe, 'written.' if c == 'n' or continuous: try: time, data, cdata = ifilm.getnextframe() ifilm.showframe(data, cdata) iframe = iframe + 1 report(time, iframe) except EOFError: print 'EOF' if continuous: break ringbell() elif dev == INPUTCHANGE: pass else: print '(dev, val) =', (dev, val) ofilm.close()
#! /usr/bin/env python # Capture a CMIF movie using the Indigo video library and board in burst mode # User interface: # # Start the application. Resize the window to the desired movie size. # Press the left mouse button to start recording, release it to end # recording. You can record as many times as you wish, but each time # you overwrite the output file(s), so only the last recording is # kept. # # Press ESC or select the window manager Quit or Close window option # to quit. If you quit before recording anything, the output file(s) # are not touched. import sys sys.path.append('/ufs/guido/src/video') import sv, SV import VFile import gl, GL, DEVICE import al, AL import time import posix import getopt import string import imageop import sgi # Usage and help functions (keep this up-to-date if you change the program!) def usage(): print 'Usage: Vrecb [options] [moviefile [audiofile]]' print