本文整理汇总了Python中pygame.camera方法的典型用法代码示例。如果您正苦于以下问题:Python pygame.camera方法的具体用法?Python pygame.camera怎么用?Python pygame.camera使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pygame
的用法示例。
在下文中一共展示了pygame.camera方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def start(self, device, maxSize=(1280,720)):
#cam = self.getCam()
if self.camTimer.isActive():
self.stop()
logger.info("Using camera: %s", device)
# Open Camera
self.cam = pygame.camera.Camera(device, maxSize)
# Start Camera
self.cam.start()
# Get actual capture size
self.size = self.cam.get_size()
# Init surface buffer
self.buffer = pygame.surface.Surface(self.size)
logger.info("Detected size: %d*%d", self.size[0], self.size[1])
# Start polling at 50hz
self.setMaxFPS(fps=50)
self.sigPlaying.emit(True)
示例2: capture
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def capture(self, retry: bool = True) -> None:
"""Captures an image from a camera or set of non-unique cameras."""
super().capture(retry=retry)
# Capture images
try:
# with self.usb_camera_lock:
self.enable_cameras(wait_for_enable=True, timeout=10)
self.capture_images()
self.disable_cameras(wait_for_disable=True, timeout=10)
except DAC5578DriverError as e:
raise exceptions.CaptureError(logger=self.logger) from e
except Exception as e:
message = "Unable to capture, unhandled exception: {}".format(type(e))
self.logger.warning(message)
raise exceptions.CaptureError(logger=self.logger) from e
示例3: oneSave
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def oneSave(angleStep): #=angle
global sMat, bb, fp
rr=0
#x=startx #camera picture X
y=sTop #camera picture Y
#---export xyz--- to filename.xyz
y=sTop+1
while y<height-sBott:
xx = sMat[y-sTop][angleStep]
if xx!=0 and xx>-200:
angle=float(2*pi/(loop-1)*angleStep)
rx=float(math.sin(angle)*xx*nasDef)
ry=float(math.cos(angle)*xx*nasDef)
rz = y
co = str(rx)+" "+str(ry)+" "+str(rz)
#cop = str(angle)+" > "+str(xx)+" > "+co
#print cop
fp.write(co+"\n")
y=y+kroky
#time.sleep(0.2)
示例4: available_devices
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def available_devices():
"""Returns a list of available device names or numbers; each name or
number can be used to pass as Setup's device keyword argument
arguments
None
keyword arguments
None
returns
devlist -- a list of device names or numbers, e.g.
['/dev/video0','/dev/video1'] or [0,1]
"""
return pygame.camera.list_cameras()
# # # # #
# classes
示例5: close
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def close(self):
"""Shuts down connection to the webcam and closes logfile
arguments
None
keyword arguments
None
returns
None
"""
# close camera
self.cam.stop()
示例6: init_cams
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def init_cams(self, which_cam_idx):
# gets a list of available cameras.
self.clist = pygame.camera.list_cameras()
print (self.clist)
if not self.clist:
raise ValueError("Sorry, no cameras detected.")
try:
cam_id = self.clist[which_cam_idx]
except IndexError:
cam_id = self.clist[0]
# creates the camera of the specified size and in RGB colorspace
self.camera = pygame.camera.Camera(cam_id, self.size, "RGB")
# starts the camera
self.camera.start()
self.clock = pygame.time.Clock()
# create a surface to capture to. for performance purposes, you want the
# bit depth to be the same as that of the display surface.
self.snapshot = pygame.surface.Surface(self.size, 0, self.display)
示例7: get_and_flip
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def get_and_flip(self):
# if you don't want to tie the framerate to the camera, you can check and
# see if the camera has an image ready. note that while this works
# on most cameras, some will never return true.
if 0 and self.camera.query_image():
# capture an image
self.snapshot = self.camera.get_image(self.snapshot)
if 0:
self.snapshot = self.camera.get_image(self.snapshot)
#self.snapshot = self.camera.get_image()
# blit it to the display surface. simple!
self.display.blit(self.snapshot, (0,0))
else:
self.snapshot = self.camera.get_image(self.display)
#self.display.blit(self.snapshot, (0,0))
pygame.display.flip()
示例8: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def __init__(self):
try:
pygame.init()
pygame.camera.init()
pygame.mouse.set_visible(False)
self.screen = pygame.display.set_mode((800,480),pygame.NOFRAME)
self.cam_list = pygame.camera.list_cameras()
self.webcam = pygame.camera.Camera(self.cam_list[0],(32,24))
self.webcam.start()
logger.info('Initialized pygame display')
except:
logger.warning('Unable to initialize pygame display')
try:
self.shared = memcache.Client(['127.0.0.1:11211'], debug=0)
logger.info('Initialized memcache client')
except:
logger.warning('Unable to initialize memcache client')
self.canny = False
self.ph = '6.5'
self.ec = '3.2'
self.water_temp = '20.1'
self.air_temp = '21.1'
self.humidity = '38'
self.co2 = '410'
self.o2 = '17.1'
# self.figure = matplotlib.pyplot.figure()
# self.plot = self.figure.add_subplot(111)
# self.runSeabornEx()
示例9: __init__
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def __init__(self,parent=None):
super(QtCore.QObject, self).__init__(parent)
pygame.init() #Do we need this? Or is it done already elsewhere
pygame.camera.init()
self.cam = None
self.buffer = None
self.size = (1280, 720)
# Get new image from camera at cam fps
self.camTimer = QtCore.QTimer(self)
self.camTimer.timeout.connect(self.emitNextFrame)
示例10: getDevices
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def getDevices(self):
return pygame.camera.list_cameras()
示例11: stop
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def stop(self):
"""Start running and polling the camera"""
# Stop polling camera
self.camTimer.stop()
# Turn off camera
if self.cam is not None:
self.cam.stop()
self.sigPlaying.emit(False)
示例12: setMaxFPS
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def setMaxFPS(self, fps=50):
""" Sets the camera polling rate. How fast images are emitted ultimately depends on the camera."""
self.camTimer.start(1000/50)
示例13: webcam
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def webcam():
client_id = "2ed32bb280dd0b8"
pygame.camera.init()
# pygame.camera.list_camera() #Camera detected or not
try:
if os.name == "nt":
cam = pygame.camera.Camera(0, (640, 480))
else:
cam = pygame.camera.Camera("/dev/video0", (640, 480))
cam.start()
except:
return "error finding a camera"
img = cam.get_image()
pygame.image.save(img, "im.png")
headers = {"Authorization": "Client-ID 2ed32bb280dd0b8"}
api_key = 'eb215a75b4e3b0e3604c42b98f3ab7b41656ddfb'
url = "https://api.imgur.com/3/upload.json"
j1 = requests.post(
url,
headers=headers,
data={
'key': api_key,
'image': b64encode(open('im.png', 'rb').read()),
'type': 'base64',
'name': 'im.png',
'title': 'screen'
}, verify=False
)
os.remove('im.png')
return json.loads(j1.text)["data"]["link"]
示例14: capture_images
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def capture_images(self) -> None:
"""Captures an image from each active camera."""
self.logger.debug("Capturing images")
# Get real or simulated camera paths
if not self.simulate:
camera_paths = usb.get_camera_paths(self.vendor_id, self.product_id)
else:
camera_paths = []
for i in range(self.num_cameras):
camera_paths.append("simulate_path")
# Check correct number of camera paths
num_detected = len(camera_paths)
if num_detected != self.num_cameras:
message = "Incorrect number of cameras detected, expected {}, detected {}".format(
self.num_cameras, num_detected
)
message += ". Proceeding with capture anyway"
self.logger.warning(message)
# Capture an image from each active camera
for index, camera_path in enumerate(camera_paths):
# Get timestring in ISO8601 format
timestring = datetime.datetime.utcnow().strftime("%Y-%m-%d-T%H:%M:%SZ")
# Get filename for individual camera or camera instance in set
if self.num_cameras == 1:
filename = "{}_{}.png".format(timestring, self.name)
else:
filename = "{}_{}.{}.png".format(timestring, self.name, index + 1)
# Create image path
capture_image_path = self.capture_dir + filename
final_image_path = self.directory + filename
# Capture image
self.capture_image_pygame(camera_path, capture_image_path)
shutil.move(capture_image_path, final_image_path)
示例15: main
# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import camera [as 别名]
def main():
pygame.init()
pygame.camera.init()
VideoCapturePlayer().main()
pygame.quit()