mirror of https://github.com/python/cpython
Added resizevideo() interface to LiveVideoIn and rationalized size
adjustments (somewhat). Adapted Vsend to use it.
This commit is contained in:
parent
cfb6bb2a30
commit
d65f45da26
|
@ -27,20 +27,26 @@ except ImportError:
|
||||||
|
|
||||||
class LiveVideoIn:
|
class LiveVideoIn:
|
||||||
|
|
||||||
# Initialize an instance.
|
# Initialize an instance. Arguments:
|
||||||
# Parameters:
|
# vw, vh: size of the video window data to be captured.
|
||||||
# - vw, vh specify the size of the video window.
|
# For some reason, vw MUST be a multiples of 4.
|
||||||
# This initializes continuous capture.
|
# Note that the data has to be cropped unless vw and vh are
|
||||||
|
# just right for the video board (vw:vh == 4:3 and vh even).
|
||||||
|
|
||||||
def init(self, pktmax, vw, vh):
|
def init(self, pktmax, vw, vh):
|
||||||
if not have_video:
|
if not have_video:
|
||||||
raise RuntimeError, 'no video available'
|
raise RuntimeError, 'no video available'
|
||||||
|
if vw % 4 != 0:
|
||||||
|
raise ValueError, 'vw must be a multiple of 4'
|
||||||
|
self.pktmax = pktmax
|
||||||
realvw = vh*SV.PAL_XMAX/SV.PAL_YMAX
|
realvw = vh*SV.PAL_XMAX/SV.PAL_YMAX
|
||||||
if realvw < vw:
|
if realvw < vw:
|
||||||
print 'Funny, image too narrow...'
|
realvw = vw
|
||||||
self.realwidth, self.realheight = v.QuerySize(realvw, vh)
|
self.realwidth, self.realheight = v.QuerySize(realvw, vh)
|
||||||
##print 'Recording video in size', \
|
# Initialize capture
|
||||||
## self.realwidth, self.realheight
|
(mode, self.realwidth, self.realheight, qsize, rate) = \
|
||||||
|
v.InitContinuousCapture(SV.RGB8_FRAMES, \
|
||||||
|
self.realwidth, self.realheight, 1, 5)
|
||||||
self.width = vw
|
self.width = vw
|
||||||
self.height = vh
|
self.height = vh
|
||||||
self.x0 = (self.realwidth-self.width)/2
|
self.x0 = (self.realwidth-self.width)/2
|
||||||
|
@ -50,15 +56,22 @@ class LiveVideoIn:
|
||||||
# Compute # full lines per packet
|
# Compute # full lines per packet
|
||||||
self.lpp = pktmax / self.width
|
self.lpp = pktmax / self.width
|
||||||
self.pktsize = self.lpp*self.width
|
self.pktsize = self.lpp*self.width
|
||||||
##print 'lpp =', self.lpp, '; pktsize =', self.pktsize
|
|
||||||
# Initialize capture
|
|
||||||
v.SetSize(self.realwidth, self.realheight)
|
|
||||||
dummy = v.InitContinuousCapture(SV.RGB8_FRAMES, \
|
|
||||||
self.realwidth, self.realheight, 1, 5)
|
|
||||||
self.data = None
|
self.data = None
|
||||||
|
self.dataoffset = 0
|
||||||
self.lpos = 0
|
self.lpos = 0
|
||||||
|
self.justright = (self.realwidth == self.width and \
|
||||||
|
self.realheight == self.height)
|
||||||
|
## if not self.justright:
|
||||||
|
## print 'Want:', self.width, 'x', self.height,
|
||||||
|
## print '; grab:', self.realwidth, 'x', self.realheight
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
# Change the size of the video being displayed.
|
||||||
|
|
||||||
|
def resizevideo(self, vw, vh):
|
||||||
|
self.close()
|
||||||
|
self = self.init(self.pktmax, vw, vh)
|
||||||
|
|
||||||
# Remove an instance.
|
# Remove an instance.
|
||||||
# This turns off continuous capture.
|
# This turns off continuous capture.
|
||||||
|
|
||||||
|
@ -75,21 +88,25 @@ class LiveVideoIn:
|
||||||
# - number of scan lines = self.lpp (PKTMAX / vw)
|
# - number of scan lines = self.lpp (PKTMAX / vw)
|
||||||
|
|
||||||
def getnextpacket(self):
|
def getnextpacket(self):
|
||||||
if not self.data:
|
if not self.data or self.dataoffset >= len(self.data):
|
||||||
try:
|
try:
|
||||||
cd, id = v.GetCaptureData()
|
cd, id = v.GetCaptureData()
|
||||||
except sv.error:
|
except sv.error:
|
||||||
return None
|
return None
|
||||||
data = cd.InterleaveFields(1)
|
data = cd.InterleaveFields(1)
|
||||||
cd.UnlockCaptureData()
|
cd.UnlockCaptureData()
|
||||||
self.data = imageop.crop(data, 1, \
|
if self.justright:
|
||||||
self.realwidth, \
|
self.data = data
|
||||||
self.realheight, \
|
else:
|
||||||
self.x0, self.y0, \
|
self.data = imageop.crop(data, 1, \
|
||||||
self.x1, self.y1)
|
self.realwidth, \
|
||||||
|
self.realheight, \
|
||||||
|
self.x0, self.y0, \
|
||||||
|
self.x1, self.y1)
|
||||||
self.lpos = 0
|
self.lpos = 0
|
||||||
data = self.data[:self.pktsize]
|
self.dataoffset = 0
|
||||||
self.data = self.data[self.pktsize:]
|
data = self.data[self.dataoffset:self.dataoffset+self.pktsize]
|
||||||
lpos = self.lpos
|
lpos = self.lpos
|
||||||
|
self.dataoffset = self.dataoffset + self.pktsize
|
||||||
self.lpos = self.lpos + self.lpp
|
self.lpos = self.lpos + self.lpp
|
||||||
return lpos, data
|
return lpos, data
|
||||||
|
|
|
@ -118,10 +118,8 @@ def main():
|
||||||
w, h = gl.getsize()
|
w, h = gl.getsize()
|
||||||
x, y = gl.getorigin()
|
x, y = gl.getorigin()
|
||||||
if (w, h) <> (width, height):
|
if (w, h) <> (width, height):
|
||||||
lvi.close()
|
|
||||||
width, height = w, h
|
width, height = w, h
|
||||||
lvi = LiveVideoIn.LiveVideoIn() \
|
lvi.resizevideo(width, height)
|
||||||
.init(pktmax, width, height)
|
|
||||||
lvo.resizevideo(width, height)
|
lvo.resizevideo(width, height)
|
||||||
|
|
||||||
rv = lvi.getnextpacket()
|
rv = lvi.getnextpacket()
|
||||||
|
|
Loading…
Reference in New Issue