Beispiel #1
0
	def getnextpacket(self):
		if not self.data or self.dataoffset >= len(self.data):
			try:
				cd, id = v.GetCaptureData()
			except sv.error:
				return None
			data = cd.InterleaveFields(1)
			cd.UnlockCaptureData()
			if self.justright:
				self.data = data
			else:
				self.data = imageop.crop(data, 1, \
					  self.realwidth, \
					  self.realheight, \
					  self.x0, self.y0, \
					  self.x1, self.y1)
			self.lpos = 0
			self.dataoffset = 0
			if self.type == 'mono':
				self.data = imageop.dither2mono(self.data, \
					  self.width, self.height)
			elif self.type == 'grey2':
				self.data = imageop.dither2grey2(self.data, \
					  self.width, self.height)
			elif self.type == 'grey4':
				self.data = imageop.grey2grey4(self.data, \
					  self.width, self.height)
		data = self.data[self.dataoffset:self.dataoffset+self.pktsize]
		lpos = self.lpos
		self.dataoffset = self.dataoffset + self.pktsize
		self.lpos = self.lpos + self.lpp
		return lpos, data
Beispiel #2
0
def applypackfactor(image, w, h, pf, bpp):
	import imageop
	if type(pf) == type(()):
		xpf, ypf = pf
	elif pf == 0:
		xpf = ypf = 1
	else:
		xpf = ypf = pf
	w1 = w/xpf
	h1 = h/abs(ypf)
	if ypf < 0:
		ypf = -ypf
		image = imageop.crop(image, bpp, w1, h1, 0, h1-1, w1-1, 0)
	return imageop.scale(image, bpp, w1, h1, w, h)
Beispiel #3
0
def applypackfactor(image, w, h, pf, bpp):
    import imageop
    if type(pf) == type(()):
        xpf, ypf = pf
    elif pf == 0:
        xpf = ypf = 1
    else:
        xpf = ypf = pf
    w1 = w / xpf
    h1 = h / abs(ypf)
    if ypf < 0:
        ypf = -ypf
        image = imageop.crop(image, bpp, w1, h1, 0, h1 - 1, w1 - 1, 0)
    return imageop.scale(image, bpp, w1, h1, w, h)
Beispiel #4
0
#! /usr/bin/env python
Beispiel #5
0
		if tout - told < mindelta:
			continue
		told = tout
		if newtype:
			data = convert(data, inwidth, inheight)
		if scale:
			data = imageop.scale(data, vout.bpp/8, \
				  inwidth, inheight, newwidth, newheight)
		if flip:
			x0, y0 = 0, 0
			x1, y1 = newwidth-1, newheight-1
			if vin.upside_down <> vout.upside_down:
				y1, y0 = y0, y1
			if vin.mirror_image <> vout.mirror_image:
				x1, x0 = x0, x1
			data = imageop.crop(data, vout.bpp/8, \
				  newwidth, newheight, x0, y0, x1, y1)
		print 'Writing frame', nout
		vout.writeframe(tout, data, cdata)
		nout = nout + 1

	vout.close()
	vin.close()


# Don't forget to call the main program

try:
	main()
except KeyboardInterrupt:
	print '[Interrupt]'
Beispiel #6
0
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')
Beispiel #7
0
#! /usr/bin/env python
Beispiel #8
0
#! /usr/bin/env python
# Copy a video file, fixing the line width to be a multiple of 4

# Usage:
#
# Vfix [infile [outfile]]

# Options:
#
# infile     : input file (default film.video)
# outfile    : output file (default out.video)

import sys
import imageop
sys.path.append('/ufs/guido/src/video')
import VFile

# Main program -- mostly command line parsing
def main():
	args = sys.argv[1:]
	if len(args) < 1:
		args.append('film.video')
	if len(args) < 2:
		args.append('out.video')
	if len(args) > 2:
		sys.stderr.write('usage: Vfix [infile [outfile]]\n')
		sys.exit(2)
	sts = process(args[0], args[1])
	sys.exit(sts)
Beispiel #9
0
source: https://www.securityfocus.com/bid/31932/info

Python's 'imageop' module is prone to a buffer-overflow vulnerability.

Successful exploits may allow attackers to execute arbitrary code in the context of applications using the vulnerable Python modules. This may result in a compromise of the underlying system. Failed attempts may lead to a denial-of-service condition.

These issues affect versions prior to Python 2.5.2-r6. 

import imageop
s = ''
imageop.crop(s, 1, 65536, 65536, 0, 0, 65536, 65536)
Beispiel #10
0
#! /usr/bin/env python
Beispiel #11
0
        sys.stderr.write('Vfix: input not in grey format\n')
        return 1
    vout.setinfo(info)
    inwidth, height = vin.getsize()
    pf = vin.packfactor
    if (inwidth / pf) % 4 == 0:
        sys.stderr.write('Vfix: fix not necessary\n')
        return 1
    outwidth = (inwidth / pf / 4) * 4 * pf
    print 'inwidth =', inwidth, 'outwidth =', outwidth
    vout.setsize(outwidth, height)
    vout.writeheader()
    n = 0
    try:
        while 1:
            t, data, cdata = vin.getnextframe()
            n = n + 1
            sys.stderr.write('Frame ' + ` n ` + '...')
            data = imageop.crop(data, 1, inwidth/pf, height/pf, \
             0, 0, outwidth/pf-1, height/pf-1)
            vout.writeframe(t, data, None)
            sys.stderr.write('\n')
    except EOFError:
        pass
    return 0


# Don't forget to call the main program

main()
Beispiel #12
0
		sys.stderr.write('Vfix: input not in grey format\n')
		return 1
	vout.setinfo(info)
	inwidth, height = vin.getsize()
	pf = vin.packfactor
	if (inwidth/pf)%4 == 0:
		sys.stderr.write('Vfix: fix not necessary\n')
		return 1
	outwidth = (inwidth/pf/4)*4*pf
	print 'inwidth =', inwidth, 'outwidth =', outwidth
	vout.setsize(outwidth, height)
	vout.writeheader()
	n = 0
	try:
		while 1:
			t, data, cdata = vin.getnextframe()
			n = n + 1
			sys.stderr.write('Frame ' + `n` + '...')
			data = imageop.crop(data, 1, inwidth/pf, height/pf, \
				0, 0, outwidth/pf-1, height/pf-1)
			vout.writeframe(t, data, None)
			sys.stderr.write('\n')
	except EOFError:
		pass
	return 0


# Don't forget to call the main program

main()
Beispiel #13
0
#! /usr/bin/env python
Beispiel #14
0
# Live video input class.
Beispiel #15
0
import imageop as im

TRAIN = True
CROP = False
PosSamNO = 2400  #正样本个数
NegSamNO = 12000
HardExampleNO = 0

hog = cv2.HOGDescriptor()
# print type(cv2.HOGDescriptor_getDefaultPeopleDetector())
# iter = 0
# flag = True
# for iter in range(len(cv2.HOGDescriptor_getDefaultPeopleDetector())):
#     print cv2.HOGDescriptor_getDefaultPeopleDetector()[iter]
#
# print len(cv2.HOGDescriptor_getDefaultPeopleDetector())
myDetector = np.array([[]])
descriptor = 0
num = 0
if TRAIN:
    imagePath = "D:\\FFOutput\\Thefirst"  # input your video path
    for imagePath in paths.list_images(imagePath):
        print("Handling image %s ." % (imagePath))
        image = cv2.imread(imagePath)

        if CROP:
            image = im.crop((100, 100, 200, 200))  # test
        descriptor = hog.compute(image, (8, 8))
        descriptorDim = len(descriptor)
    #sampleFeatureMat = Mat::zeros(PosSamNO + NegSamNO + HardExampleNO, descriptorDim, CV_32FC1);
Beispiel #16
0
# Live video input class.
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')
Beispiel #18
0
#! /usr/bin/env python
# Universal (non-interactive) CMIF video file copier.

# Possibilities:
#
# - Manipulate the time base:
#   = resample at a fixed rate
#   = divide the time codes by a speed factor (to make it go faster/slower)
#   = drop frames that are less than n msec apart (to accommodate slow players)
# - Convert to a different format
# - Magnify (scale) the image

# Usage function (keep this up-to-date if you change the program!)
def usage():
	print 'Usage: Vcopy [options] [infile [outfile]]'
	print
	print 'Options:'
	print
	print '-t type    : new image type (default unchanged)'
	print
	print '-M magnify : image magnification factor (default unchanged)'
	print '-w width   : output image width (default height*4/3 if -h used)'
	print '-h height  : output image height (default width*3/4 if -w used)'
	print
	print '-p pf      : new x and y packfactor (default unchanged)'
	print '-x xpf     : new x packfactor (default unchanged)'
	print '-y ypf     : new y packfactor (default unchanged)'
	print
	print '-m delta   : drop frames closer than delta msec (default 0)'
	print '-r delta   : regenerate input time base delta msec apart'