本文整理匯總了Python中cv2.destroyAllWindows方法的典型用法代碼示例。如果您正苦於以下問題:Python cv2.destroyAllWindows方法的具體用法?Python cv2.destroyAllWindows怎麽用?Python cv2.destroyAllWindows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cv2
的用法示例。
在下文中一共展示了cv2.destroyAllWindows方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def main():
capture = cv2.VideoCapture(0)
_, image = capture.read()
previous = image.copy()
while (cv2.waitKey(1) < 0):
_, image = capture.read()
diff = cv2.absdiff(image, previous)
#image = cv2.flip(image, 3)
#image = cv2.norm(image)
_, diff = cv2.threshold(diff, 32, 0, cv2.THRESH_TOZERO)
_, diff = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY)
diff = cv2.medianBlur(diff, 5)
cv2.imshow('video', diff)
previous = image.copy()
capture.release()
cv2.destroyAllWindows()
示例2: processFrames
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def processFrames(self):
try:
for img in self.anotations_list:
img = img.split(';')
# print(img)
# ret,imgcv = cap.read()
if self.video:
ret,imgcv = self.cap.read()
else:
imgcv = cv2.imread(os.path.join('../',self.config["dataset"],img[0]))
result = self.tfnet.return_predict(imgcv)
print(result)
imgcv = self.drawBoundingBox(imgcv,result)
cv2.imshow('detected objects',imgcv)
if cv2.waitKey(10) == ord('q'):
print('exitting loop')
break
except KeyboardInterrupt:
cv2.destroyAllWindows()
print('exitting program')
示例3: show
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def show(im, allobj, S, w, h, cellx, celly):
for obj in allobj:
a = obj[5] % S
b = obj[5] // S
cx = a + obj[1]
cy = b + obj[2]
centerx = cx * cellx
centery = cy * celly
ww = obj[3]**2 * w
hh = obj[4]**2 * h
cv2.rectangle(im,
(int(centerx - ww/2), int(centery - hh/2)),
(int(centerx + ww/2), int(centery + hh/2)),
(0,0,255), 2)
cv2.imshow('result', im)
cv2.waitKey()
cv2.destroyAllWindows()
示例4: __next__
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def __next__(self):
self.count += 1
img0 = self.imgs.copy()
if cv2.waitKey(1) == ord('q'): # q to quit
cv2.destroyAllWindows()
raise StopIteration
# Letterbox
img = [letterbox(x, new_shape=self.img_size, interp=cv2.INTER_LINEAR)[0] for x in img0]
# Stack
img = np.stack(img, 0)
# Normalize RGB
img = img[:, :, :, ::-1].transpose(0, 3, 1, 2) # BGR to RGB
img = np.ascontiguousarray(img, dtype=np.float16 if self.half else np.float32) # uint8 to fp16/fp32
img /= 255.0 # 0 - 255 to 0.0 - 1.0
return self.sources, img, img0, None
示例5: main
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def main():
device = cv2.CAP_OPENNI
capture = cv2.VideoCapture(device)
if not(capture.isOpened()):
capture.open(device)
capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
app = wx.App()
frame = MyFrame(None, -1, 'chapter2.py', capture)
frame.Show(True)
# self.SetTopWindow(frame)
app.MainLoop()
# When everything done, release the capture
capture.release()
cv2.destroyAllWindows()
示例6: main
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def main():
"""
Calibrate the live camera and optionally do a live display of the results
"""
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("config", type=Path, help="camera config path")
parser.add_argument("--height", type=int, default=4)
parser.add_argument("--width", type=int, default=10)
parser.add_argument("--count", type=int, default=10)
parser.add_argument("--view", action="store_true")
args = parser.parse_args()
config = {"camera": derp.util.load_config(args.config)}
camera = Camera(config)
pattern_shape = (args.height, args.width)
camera_matrix, distortion_coefficients = live_calibrate(camera, pattern_shape, args.count)
print(camera_matrix)
print(distortion_coefficients)
if args.view:
live_undistort(camera, camera_matrix, distortion_coefficients)
cv2.destroyAllWindows()
示例7: display_multiple
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def display_multiple(images: List[Tuple[List, Optional[str]]]):
"""Displays one or more captures in a CV2 window. Useful for debugging
Args:
images: List of tuples containing MxNx3 pixel arrays and optional titles OR
list of image data
"""
for image in images:
if isinstance(image, tuple):
image_data = image[0]
else:
image_data = image
if isinstance(image, tuple) and len(image) > 1:
title = image[1]
else:
title = "Camera Output"
cv2.namedWindow(title)
cv2.moveWindow(title, 500, 500)
cv2.imshow(title, image_data)
cv2.waitKey(0)
cv2.destroyAllWindows()
示例8: write
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def write(self, filename, frames, fps, show=False):
fps = max(1, fps)
out = None
try:
for image in frames:
frame = cv2.imread(image)
if show:
cv2.imshow('video', frame)
if not out:
height, width, channels = frame.shape
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
out = cv2.VideoWriter(filename, fourcc, 20, (width, height))
out.write(frame)
finally:
out and out.release()
cv2.destroyAllWindows()
示例9: _run
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def _run(self, n_frames=500, width=1280, height=720, with_threading=False):
if with_threading:
cap = VideoCaptureTreading(0)
else:
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)
if with_threading:
cap.start()
t0 = time.time()
i = 0
while i < n_frames:
_, frame = cap.read()
cv2.imshow('Frame', frame)
cv2.waitKey(1) & 0xFF
i += 1
print('[i] Frames per second: {:.2f}, with_threading={}'.format(n_frames / (time.time() - t0), with_threading))
if with_threading:
cap.stop()
cv2.destroyAllWindows()
示例10: preview
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def preview(self):
""" Blocking function. Opens OpenCV window to display stream. """
self.connect()
win_name = 'RTSP'
cv2.namedWindow(win_name, cv2.WINDOW_AUTOSIZE)
cv2.moveWindow(win_name, 20, 20)
while True:
cv2.imshow(win_name, self.get_frame())
# if self._latest is not None:
# cv2.imshow(win_name,self._latest)
if cv2.waitKey(25) & 0xFF == ord('q'):
break
cv2.waitKey()
cv2.destroyAllWindows()
cv2.waitKey()
示例11: run
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def run(self):
while cv2.getWindowProperty('img', 0) != -1 or cv2.getWindowProperty('watershed', 0) != -1:
ch = cv2.waitKey(50)
if ch == 27:
break
if ch >= ord('1') and ch <= ord('7'):
self.cur_marker = ch - ord('0')
print('marker: ', self.cur_marker)
if ch == ord(' ') or (self.sketch.dirty and self.auto_update):
self.watershed()
self.sketch.dirty = False
if ch in [ord('a'), ord('A')]:
self.auto_update = not self.auto_update
print('auto_update if', ['off', 'on'][self.auto_update])
if ch in [ord('r'), ord('R')]:
self.markers[:] = 0
self.markers_vis[:] = self.img
self.sketch.show()
cv2.destroyAllWindows()
示例12: show2
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def show2(im, allobj):
for obj in allobj:
cv2.rectangle(im,
(obj[1], obj[2]),
(obj[3], obj[4]),
(0,0,255),2)
cv2.imshow('result', im)
cv2.waitKey()
cv2.destroyAllWindows()
示例13: __del__
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def __del__(self):
global TERMINATE
TERMINATE = True
self.sock.close()
try:
cv2.destroyAllWindows()
except:
pass
示例14: test_recognition
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def test_recognition(c1, c2):
extracted_face1 = extract_face_features(gray1, face1[0], (c1, c2))
print(predict_face_is_smiling(extracted_face1))
extracted_face2 = extract_face_features(gray2, face2[0], (c1, c2))
print(predict_face_is_smiling(extracted_face2))
cv2.imshow('gray1', extracted_face1)
cv2.imshow('gray2', extracted_face2)
cv2.waitKey(0)
cv2.destroyAllWindows()
# test_recognition(0.3, 0.05)
# ------------------- LIVE FACE RECOGNITION -----------------------------------
開發者ID:its-izhar,項目名稱:Emotion-Recognition-Using-SVMs,代碼行數:15,代碼來源:Train Classifier and Test Video Feed.py
示例15: __del__
# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import destroyAllWindows [as 別名]
def __del__(self):
"""Deconstructor to close window"""
cv2.destroyAllWindows()