本文整理汇总了Python中Camera.Camera.get_frame方法的典型用法代码示例。如果您正苦于以下问题:Python Camera.get_frame方法的具体用法?Python Camera.get_frame怎么用?Python Camera.get_frame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Camera.Camera
的用法示例。
在下文中一共展示了Camera.get_frame方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import get_frame [as 别名]
class Main:
"""Clase principal """
def __init__(self):
self.camera = Camera()
self.borracho_actual = None
self.indice = 0
# cargamos el archivo creado con glade
self.gladefile = "pychupito/gui/chupiventana.glade"
self.glade = gtk.Builder()
self.glade.add_from_file(self.gladefile)
# cargamos las variables
self.window = self.glade.get_object("chupiventana")
self.image_add = self.glade.get_object("image_add")
self.image_delete = self.glade.get_object("image_delete")
# self.image_drink = self.glade.get_object("image_drink")
self.button_add = self.glade.get_object("button_add")
self.button_delete = self.glade.get_object("button_delete")
self.button_previous = self.glade.get_object("button_previous")
self.button_next = self.glade.get_object("button_next")
# self.button_drink = self.glade.get_object("button_drink")
# conectamos las señales
self.glade.connect_signals(self)
# modificamos las variables para mostrar o no los botones
# self.window.set_icon_from_file("icono.png")
self.window.set_title("PyChupito")
self.button_previous.set_sensitive(False)
self.button_next.set_sensitive(False)
self.button_delete.set_sensitive(False)
# self.button_drink.set_sensitive(False)
# mostramos la cámara en la imagen de la izquierda
self.camera.check_name_cameras()
self.camera.open_camera(0)
# creamos una especie de while
self.refresh = gobject.timeout_add(50, self.update) # Bucle video
# creamos una lista de borrachos
self.borrachos = Borrachos()
# mostramos la ventana
self.window.show()
# callback
def button_add_clicked(self, widget):
borracho = self.borrachos.agregar_borracho()
nombre_imagen = borracho.agregar_imagen()
frame = self.camera.get_frame()
save = cvCloneImage(frame)
try:
cvSaveImage("imagenes/%s.png" % nombre_imagen, save)
except:
print "no se ha podido guardar la imagen"
if len(self.borrachos.lista_borrachos) == 1:
self.button_previous.set_sensitive(True)
self.button_next.set_sensitive(True)
self.button_delete.set_sensitive(True)
# self.button_drink.set_sensitive(True)
self.borracho_actual = self.borrachos.lista_borrachos[self.indice % self.borrachos.numero_borrachos]
nombre_imagen = self.borracho_actual.lista_imagenes[-1]
imagen_borracho = cvLoadImage("imagenes/%s.png" % nombre_imagen)
resized = change_size_image(imagen_borracho, (150, 100))
self.load_image_delete(resized)
def button_previous_clicked(self, widget):
self.indice -= 1
self.borracho_actual = self.borrachos.lista_borrachos[self.indice % self.borrachos.numero_borrachos]
nombre_imagen = self.borracho_actual.lista_imagenes[-1]
imagen_borracho = cvLoadImage("imagenes/%s.png" % nombre_imagen)
resized = change_size_image(imagen_borracho, (150, 100))
self.load_image_delete(resized)
def button_next_clicked(self, widget):
self.indice += 1
self.borracho_actual = self.borrachos.lista_borrachos[self.indice % self.borrachos.numero_borrachos]
nombre_imagen = self.borracho_actual.lista_imagenes[-1]
imagen_borracho = cvLoadImage("imagenes/%s.png" % nombre_imagen)
resized = change_size_image(imagen_borracho, (150, 100))
self.load_image_delete(resized)
def button_delete_clicked(self, widget):
self.borrachos.eliminar_borracho(self.borracho_actual)
self.indice -= 1
self.borracho_actual = self.borrachos.lista_borrachos[self.indice % self.borrachos.numero_borrachos]
nombre_imagen = self.borracho_actual.lista_imagenes[-1]
imagen_borracho = cvLoadImage("imagenes/%s.png" % nombre_imagen)
resized = change_size_image(imagen_borracho, (150, 100))
self.load_image_delete(resized)
if not self.borrachos.numero_borrachos:
self.button_previous.set_sensitive(False)
#.........这里部分代码省略.........
示例2: __init__
# 需要导入模块: from Camera import Camera [as 别名]
# 或者: from Camera.Camera import get_frame [as 别名]
#.........这里部分代码省略.........
def perform_homography(self):
# TODO: get a new frame
# TODO: these are hardcoded, use real homography procedures
self.pitch_tl_ = (20, 25)
self.pitch_bl_ = (20, 320)
self.pitch_tr_ = (600, 25)
self.pitch_br_ = (600, 320)
self.l_goal_t_ = (20, 100)
self.l_goal_b_ = (20, 250)
self.r_goal_t_ = (600, 100)
self.r_goal_b_ = (600, 250)
# calculate distortion matrix, for barrel effect correction
ilist = [ [600.95880126953125, 0, 330.65557861328125],
[0.0, 600.8642578125, 266.62376403808594],
[0.0, 0.0, 1.0]]
dlist = [ -0.3258521556854248, 0.19688290357589722,
-0.0078322244547307491, -0.0044014849700033665]
self.imat_ = cv.CreateMat(3, 3, 1111638021)
self.dmat_ = cv.CreateMat(4, 1, 1111638021)
for i in range(3):
for j in range(3):
self.imat_[i,j] = ilist[i][j]
for i in range(4):
self.dmat_[i,0] = dlist[i]
def detect_objects(self, prev_bal_center, prev_blu_center, prev_ylw_center,
prev_blu_dir, prev_ylw_dir):
# get camera or dummy frame and unidstort
img = self.cam_.get_frame()
# Size of frame is 640x480, so cut (50, 80) from the left to remove
# the distortion. Usage: cv.SubRect(x, y, width, height)
# TODO: Use homography info, current crop is hadrcoded
img = cv.GetSubRect(img, (10, 70, 620, 340)) # crop
size = cv.GetSize(img)
blu_dir = ylw_dir = None
bal_center = blu_center = ylw_center = None
trust_bal = trust_ylw = trust_blu = True
# create and HSV and RGB iamge for later use
hsv_img = cv.CreateImage(size, cv.IPL_DEPTH_8U, 3)
cv.CvtColor(img, hsv_img, cv.CV_BGR2HSV)
rgb_img = cv.CreateImage(size, cv.IPL_DEPTH_8U, 3)
cv.CvtColor(img, rgb_img, cv.CV_BGR2RGB)
# detect ball using hsv_img
red_bin_img, bal_center = self.detect_ball(hsv_img,
(3, 3), 3, (3, 3), 3)
if not bal_center:
bal_center = prev_bal_center
trust_bal = False
# detect blue robot using hsv_img
blu_trsh = self.blu_color_.in_range_s(hsv_img) # threshold
erd_mat = (1, 1); erd = 1; dil_mat = (2, 2); dil = 5 # erode/dilate
cv.Erode(blu_trsh, blu_trsh, cv.CreateStructuringElementEx(
erd_mat[0], erd_mat[1], 0, 0, 0), erd)
cv.Dilate(blu_trsh, blu_trsh, cv.CreateStructuringElementEx(
dil_mat[0], dil_mat[1], 0, 0, 0), dil)
cv.Erode(blu_trsh, blu_trsh, cv.CreateStructuringElementEx(
erd_mat[0] * 6, erd_mat[1] * 6, 0, 0, 0), erd)