本文整理汇总了Python中cv2.cv.QueryFrame方法的典型用法代码示例。如果您正苦于以下问题:Python cv.QueryFrame方法的具体用法?Python cv.QueryFrame怎么用?Python cv.QueryFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2.cv
的用法示例。
在下文中一共展示了cv.QueryFrame方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import QueryFrame [as 别名]
def __init__(self, queue, webcam):
super(WebcamImageProvider, self).__init__(queue)
self.camera = cv.CreateCameraCapture(webcam)
img = cv.QueryFrame(self.camera)
if img is None:
raise queue.Empty
self.running = True
示例2: run
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import QueryFrame [as 别名]
def run(self):
while self.running:
img = cv.QueryFrame(self.camera)
self.image_queue.put(img)
c = cv.WaitKey(30)
示例3: process_frames
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import QueryFrame [as 别名]
def process_frames(self):
while True:
frame = cv.QueryFrame(self.capture)
aframe = numpy.asarray(frame[:, :])
g = cv.fromarray(aframe)
g = numpy.asarray(g)
imgray = cv2.cvtColor(g, cv2.COLOR_BGR2GRAY)
raw = str(imgray.data)
scanner = zbar.ImageScanner()
scanner.parse_config('enable')
imagezbar = zbar.Image(frame.width, frame.height, 'Y800', raw)
scanner.scan(imagezbar)
# Process the frames
for symbol in imagezbar:
if not self.process_symbol(symbol):
return
# Update the preview window
cv2.imshow(self.window_name, aframe)
cv.WaitKey(5)
示例4: __init__
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import QueryFrame [as 别名]
def __init__(self,threshold=25, doRecord=True, showWindows=True):
self.writer = None
self.font = None
self.doRecord=doRecord #Either or not record the moving object
self.show = showWindows #Either or not show the 2 windows
self.frame = None
#self.capture=cv.CaptureFromCAM(0)
self.capture=cv.CaptureFromFile('crash-480.mp4')
self.frame = cv.QueryFrame(self.capture) #Take a frame to init recorder
if doRecord:
self.initRecorder()
self.gray_frame = cv.CreateImage(cv.GetSize(self.frame), cv.IPL_DEPTH_8U, 1)
self.average_frame = cv.CreateImage(cv.GetSize(self.frame), cv.IPL_DEPTH_32F, 3)
self.absdiff_frame = None
self.previous_frame = None
self.surface = self.frame.width * self.frame.height
self.currentsurface = 0
self.currentcontours = None
self.threshold = threshold
self.isRecording = False
self.trigger_time = 0 #Hold timestamp of the last detection
if showWindows:
cv.NamedWindow("Image")
cv.CreateTrackbar("Detection treshold: ", "Image", self.threshold, 100, self.onChange)
示例5: run
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import QueryFrame [as 别名]
def run(self):
started = time.time()
while True:
currentframe = cv.QueryFrame(self.capture)
instant = time.time() #Get timestamp o the frame
self.processImage(currentframe) #Process the image
if not self.isRecording:
if self.somethingHasMoved():
self.trigger_time = instant #Update the trigger_time
if instant > started +10:#Wait 5 second after the webcam start for luminosity adjusting etc..
print "Something is moving !"
if self.doRecord: #set isRecording=True only if we record a video
self.isRecording = True
cv.DrawContours (currentframe, self.currentcontours, (0, 0, 255), (0, 255, 0), 1, 2, cv.CV_FILLED)
else:
if instant >= self.trigger_time +10: #Record during 10 seconds
print "Stop recording"
self.isRecording = False
else:
cv.PutText(currentframe,datetime.now().strftime("%b %d, %H:%M:%S"), (25,30),self.font, 0) #Put date on the frame
cv.WriteFrame(self.writer, currentframe) #Write the frame
if self.show:
cv.ShowImage("Image", currentframe)
c=cv.WaitKey(1) % 0x100
if c==27 or c == 10: #Break if user enters 'Esc'.
break
示例6: getImage
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import QueryFrame [as 别名]
def getImage(self):
"""
**SUMMARY**
Retrieve an Image-object from the virtual camera.
**RETURNS**
A SimpleCV Image from the camera.
**EXAMPLES**
>>> cam = VirtualCamera()
>>> while True:
>>> cam.getImage().show()
"""
if (self.sourcetype == 'image'):
self.counter = self.counter + 1
return Image(self.source, self)
elif (self.sourcetype == 'imageset'):
print len(self.source)
img = self.source[self.counter % len(self.source)]
self.counter = self.counter + 1
return img
elif (self.sourcetype == 'video'):
# cv.QueryFrame returns None if the video is finished
frame = cv.QueryFrame(self.capture)
if frame:
img = cv.CreateImage(cv.GetSize(frame), cv.IPL_DEPTH_8U, 3)
cv.Copy(frame, img)
return Image(img, self)
else:
return None
elif (self.sourcetype == 'directory'):
img = self.findLastestImage(self.source, 'bmp')
self.counter = self.counter + 1
return Image(img, self)
示例7: run
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import QueryFrame [as 别名]
def run(self):
hist = cv.CreateHist([180], cv.CV_HIST_ARRAY, [(0,180)], 1 )
backproject_mode = False
while True:
frame = cv.QueryFrame( self.capture )
# Convert to HSV and keep the hue
hsv = cv.CreateImage(cv.GetSize(frame), 8, 3)
cv.CvtColor(frame, hsv, cv.CV_BGR2HSV)
self.hue = cv.CreateImage(cv.GetSize(frame), 8, 1)
cv.Split(hsv, self.hue, None, None, None)
# Compute back projection
backproject = cv.CreateImage(cv.GetSize(frame), 8, 1)
# Run the cam-shift
cv.CalcArrBackProject( [self.hue], backproject, hist )
if self.track_window and is_rect_nonzero(self.track_window):
crit = ( cv.CV_TERMCRIT_EPS | cv.CV_TERMCRIT_ITER, 10, 1)
(iters, (area, value, rect), track_box) = cv.CamShift(backproject, self.track_window, crit)
self.track_window = rect
# If mouse is pressed, highlight the current selected rectangle
# and recompute the histogram
if self.drag_start and is_rect_nonzero(self.selection):
sub = cv.GetSubRect(frame, self.selection)
save = cv.CloneMat(sub)
cv.ConvertScale(frame, frame, 0.5)
cv.Copy(save, sub)
x,y,w,h = self.selection
cv.Rectangle(frame, (x,y), (x+w,y+h), (255,255,255))
sel = cv.GetSubRect(self.hue, self.selection )
cv.CalcArrHist( [sel], hist, 0)
(_, max_val, _, _) = cv.GetMinMaxHistValue( hist)
if max_val != 0:
cv.ConvertScale(hist.bins, hist.bins, 255. / max_val)
elif self.track_window and is_rect_nonzero(self.track_window):
cv.EllipseBox( frame, track_box, cv.CV_RGB(255,0,0), 3, cv.CV_AA, 0 )
if not backproject_mode:
cv.ShowImage( "CamShiftDemo", frame )
else:
cv.ShowImage( "CamShiftDemo", backproject)
cv.ShowImage( "Histogram", self.hue_histogram_as_image(hist))
c = cv.WaitKey(7) % 0x100
if c == 27:
break
elif c == ord("b"):
backproject_mode = not backproject_mode