当前位置: 首页>>代码示例>>Python>>正文


Python VideoStream.release方法代码示例

本文整理汇总了Python中imutils.video.VideoStream.release方法的典型用法代码示例。如果您正苦于以下问题:Python VideoStream.release方法的具体用法?Python VideoStream.release怎么用?Python VideoStream.release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在imutils.video.VideoStream的用法示例。


在下文中一共展示了VideoStream.release方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: int

# 需要导入模块: from imutils.video import VideoStream [as 别名]
# 或者: from imutils.video.VideoStream import release [as 别名]
		# otherwise, compute the thickness of the line and
		# draw the connecting lines
		thickness = int(np.sqrt(args["buffer"] / float(i + 1)) * 2.5)
		cv2.line(frame, pts[i - 1], pts[i], (0, 0, 255), thickness)

	# show the frame to our screen
	cv2.imshow("Frame", frame)

	if record_video and record_track:
		video_writer.write(frame)

	key = cv2.waitKey(1) & 0xFF

	# if the 'q' key is pressed, stop the loop
	if key == ord("q"):
		break

# cleanup the camera and close any open windows
if not from_vfile:
	if hasattr(camera, 'release'): # Pycamera may not have the release function
		camera.release()
else:
	video_file.release()

if video_writer is not None:
	video_writer.release()

cv2.destroyAllWindows()

开发者ID:myshepherd,项目名称:tritoneye,代码行数:30,代码来源:ball_tracking.py

示例2: ord

# 需要导入模块: from imutils.video import VideoStream [as 别名]
# 或者: from imutils.video.VideoStream import release [as 别名]
    if writer is not None:
        writer.write(frame)
    
    # show the output frame
    cv2.imshow("Frame", frame)
    key = cv2.waitKey(1) & 0xFF

    # if the 'q' key was pressed, break from the  loop
    if key == ord('q'):
        break
    
    # increment the total no.of frames processed thus far and
    # then update the FPS counter
    totalFrames += 1
    fps.update()

# stop the counter and display FPS information
fps.stop()
print("[INFO] elapsed time: {: .2f}".format(fps.elapsed()))
print("[INFO] approx FPS: {: .2f}".format(fps.fps()))

if writer is not None:
    writer.release()

if not args.get("input", False):
    vs.stop()
else:
    vs.release()

# close any open windows
cv2.destroyAllWindows()
开发者ID:sh-raza,项目名称:opencv-implementations,代码行数:33,代码来源:people_counter.py

示例3: len

# 需要导入模块: from imutils.video import VideoStream [as 别名]
# 或者: from imutils.video.VideoStream import release [as 别名]
    if len(faces)>0:
        print ("Found {0} faces!".format(len(faces)))

    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    return frame

while True:
    # Capture frame-by-frame
    _,frame = video_capture.read()

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    if ENABLE_FACE_DETECT:
        resultFrame = faceDetect(gray)
        # Display the resulting frame
        cv2.imshow('Video', resultFrame)

    if ENABLE_FPS:
        print("fps:",t.fps())

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
video_capture.release()
cv2.destroyAllWindows()
开发者ID:wwwins,项目名称:OpenCV-Samples,代码行数:31,代码来源:webcam-face-detect.py

示例4: __init__

# 需要导入模块: from imutils.video import VideoStream [as 别名]
# 或者: from imutils.video.VideoStream import release [as 别名]
class TEVideoHandler:
	def __init__(self):
		self.FRAME_WIDTH = conf.DEF_FRAME_WIDTH
		self.FRAME_HEIGHT = conf.DEF_FRAME_HEIGHT

		# devices
		self.video_file = None
		self.camera = None
		self.picamera = None
		
	def set_frame_size(w, h):
		if self.video_file is not None or self.camera is not None or self.picamera is not None:
			raise TEVideoException("Frame size need to be set before initialization")

		self.FRAME_WIDTH = w
		self.FRAME_HEIGHT = h

	def initialize_with_file(self, filename):
		if self.video_file is not None or self.camera is not None or self.picamera is not None:
			raise TEVideoException("Already Initialized")

		self.video_file = cv2.VideoCapture(filename)

	def initialize_with_configured_cam(self):
		cam_selector = {
			conf.CameraType.PYCAMERA:			lambda: self.initialize_with_pycamera(),
			conf.CameraType.PYCAMERA_ROBUST:	lambda: self.initialize_with_pycamera2(),
			conf.CameraType.WEBCAM:				lambda: self.initialize_with_webcam(),
		}

		cam_selector[conf.CAMERA_TYPE]()


	def initialize_with_pycamera(self):
		if self.video_file is not None or self.camera is not None or self.picamera is not None:
			raise TEVideoException("Already Initialized")

		self.camera = VideoStream(usePiCamera=True).start()
		time.sleep(2.0)

	# It uses picamera library to disable auto control feature
	def initialize_with_pycamera2(self):
		if self.video_file is not None or self.camera is not None or self.picamera is not None:
			raise TEVideoException("Already Initialized")

		self.picamera = PiCamera()
		self.picamera.resolution = (self.FRAME_WIDTH, self.FRAME_HEIGHT)
		self.picamera.framerate = 30
		self.rawCapture = PiRGBArray(self.picamera, size=(self.FRAME_WIDTH, self.FRAME_HEIGHT))

		time.sleep(0.1)

		self.picamera.shutter_speed = self.picamera.exposure_speed
		self.picamera.exposure_mode = 'off'
		g = self.picamera.awb_gains
		self.picamera.awb_mode = 'off'
		self.picamera.awb_gains = g
		self.stream = self.picamera.capture_continuous(self.rawCapture, format="bgr", use_video_port=True)


	# Tested with a monitor webcam, but didn't checked with the webcam macbook
	def initialize_with_webcam(self):
		if self.video_file is not None or self.camera is not None or self.picamera is not None:
			raise TEVideoException("Already Initialized")

		self.camera = VideoStream().start()
		time.sleep(2.0)

	# Read a frame	
	# Return: frame (pixel array)
	# Note: if not grapped (for video file), raise exception
	def read(self):
		frame = None
		if self.video_file is not None:
			(grabbed, frame) = self.video_file.read()
			if not grabbed:
				raise TEInvalidFrameException()
		elif self.camera is not None:
			frame = self.camera.read()
		elif self.picamera is not None:
			data = self.stream.next()
			frame = data.array
			self.rawCapture.truncate(0)

		# If still null frame,
		if frame is None:
			raise TEInvalidFrameException()

		# resize the frame
		frame = imutils.resize(frame, width=self.FRAME_WIDTH)

		return frame

	def release(self):
		if self.video_file is not None:
			self.video_file.release()
		elif self.camera is not None:
			# Pycamera may not have the release function
			if hasattr(self.camera, 'release'): 
				self.camera.release()
开发者ID:myshepherd,项目名称:tritoneye,代码行数:102,代码来源:videoutil.py


注:本文中的imutils.video.VideoStream.release方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。