本文整理汇总了Python中cv2.cv.WaitKey方法的典型用法代码示例。如果您正苦于以下问题:Python cv.WaitKey方法的具体用法?Python cv.WaitKey怎么用?Python cv.WaitKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2.cv
的用法示例。
在下文中一共展示了cv.WaitKey方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import WaitKey [as 别名]
def main():
"""Open test color images, create display window, start the search"""
cv.NamedWindow(WNDNAME, 1)
for name in [ "../c/pic%d.png" % i for i in [1, 2, 3, 4, 5, 6] ]:
img0 = cv.LoadImage(name, 1)
try:
img0
except ValueError:
print "Couldn't load %s\n" % name
continue
# slider deleted from C version, same here and use fixed Canny param=50
img = cv.CloneImage(img0)
cv.ShowImage(WNDNAME, img)
# force the image processing
draw_squares( img, find_squares4( img ) )
# wait for key.
if cv.WaitKey(-1) % 0x100 == 27:
break
示例2: run
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import WaitKey [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 WaitKey [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: run
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import WaitKey [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
示例5: run
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import WaitKey [as 别名]
def run(self):
self.on_segment()
cv.WaitKey(0)
示例6: run
# 需要导入模块: from cv2 import cv [as 别名]
# 或者: from cv2.cv import WaitKey [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