Exemple #1
0
 def __create_camera(video_file_or_camera, fps, width, height):
     """Create the appropriate class using opencv or the raspberry Pi piCamera"""
     # For files nor non raspberry pi devices, use opencv, for real-time video on raspberry pi, use CameraRaspbian
     if os.path.isfile("/etc/rpi-issue") and video_file_or_camera == 0:
         return RaspberianGrabber(cv2, fps, width, height)
     else:
         return FrameGrabber(cv2, fps, width, height)
Exemple #2
0
def create_camera(video_file_or_camera, fps, width, height, logger):
    # For video files nor non raspberry pi devices, use open cv, for real-time video on raspberry pi, use CameraRaspbian
    if os.path.isfile("/etc/rpi-issue") and video_file_or_camera == 0:
        return RaspberianGrabber(cv2, fps, width, height, logger,
                                 video_file_or_camera)
    else:
        return FrameGrabber(cv2, fps, width, height, logger,
                            video_file_or_camera)
 def __init__(self, fps_limit=5.):
     self.builder = gtk.Builder()
     self.builder.add_from_file(os.path.join('glade', 'frame_grabber.glade'))
     self.window = self.builder.get_object('window')
     self.area = self.builder.get_object('drawing_area')
     # connect signals from glade to python
     self.builder.connect_signals(self)
     # show window and contents
     self.window.show_all()
     self.cam_cap = CameraCapture(auto_init=False)
     self.grabber = FrameGrabber(self.cam_cap, auto_init=True)
     self.grabber.frame_callback = self.update_frame_data
     self.pixbuf = None
     self.pixmap = None
     self.grabber.start()
     self.grabber.set_fps_limit(fps_limit)
     self.video_enabled = False
Exemple #4
0
def grab_images():
  grabbers = []
  for i in range(2):
    try:
      camera = cv2.VideoCapture(i)
      camera.set(cv2.CAP_PROP_FRAME_WIDTH,320)
      camera.set(cv2.CAP_PROP_FRAME_HEIGHT,240)
      camera.set(cv2.CAP_PROP_FPS,60)
      grabber = FrameGrabber(camera)
      grabbers.append(grabber)
      grabber.go()
    except:
      raise
      
  print 'found',str(len(grabbers)),'cameras'
  
  interval = Interval(10.)
  grab_number = 0
  while True:
    c = cv2.waitKey(1)
    if c <> -1:
      print 'pressed: '+str(c)
    c = c & 255
    if c == ord('q'):
      break
    images = []
    for grabber in grabbers:
      retval,img = grabber.read()
      if retval: images.append(img)
      if interval.occurred():
        print grabber.stats()
        
    if c == ord(' '):
      grab_number += 1
      print 'saving images'
      for i in range(len(images)):
        cv2.imwrite('img_'+str(grab_number)+'_'+str(i)+'.png',images[i])
    for i in range(len(images)):
      add_chessboard_corners(images[i])
      cv2.imshow(str(i),images[i])
   
  for grabber in grabbers:
    grabber.quit()
Exemple #5
0
from face_detector import FaceDetector
from frame_grabber import FrameGrabber
from imutils.video import FPS
import imutils
import datetime
import cv2

SHOW_GUI = True

left_offsetX = 900
right_offsetX = 1600
up_offsetY = 550
down_offsetY = 1350

# Start videostream, 0 for webcam, 1 for rtsp
frame_grabber = FrameGrabber(1)
frame_grabber.start()

# Initialize motion detector
motion_detector = MotionDetector()
num_frame_read = 0  # no. of frames read

# Initialize face detector
face_detector = FaceDetector()

# FPS calculation
fps = FPS().start()

print("[INFO] Start collecting face images.")

while True:
class FrameGrabberGUI:
    def __init__(self, fps_limit=5.):
        self.builder = gtk.Builder()
        self.builder.add_from_file(os.path.join('glade', 'frame_grabber.glade'))
        self.window = self.builder.get_object('window')
        self.area = self.builder.get_object('drawing_area')
        # connect signals from glade to python
        self.builder.connect_signals(self)
        # show window and contents
        self.window.show_all()
        self.cam_cap = CameraCapture(auto_init=False)
        self.grabber = FrameGrabber(self.cam_cap, auto_init=True)
        self.grabber.frame_callback = self.update_frame_data
        self.pixbuf = None
        self.pixmap = None
        self.grabber.start()
        self.grabber.set_fps_limit(fps_limit)
        self.video_enabled = False

    def on_fps_limit_spinner_value_changed(self, button):
        self.grabber.set_fps_limit(button.get_value())

    def on_button_start_clicked(self, *args, **kwargs):
        self.video_enabled = True

    def on_button_stop_clicked(self, *args, **kwargs):
        self.video_enabled = False

    def on_drawing_area_expose_event(self, widget, event):
        if self.pixmap:
            x , y, width, height = event.area
            self.area.window.draw_drawable(gui.area.get_style().white_gc,
                        self.pixmap, x, y, x, y, width, height)
        return False

    def draw_state(self, cairo):
        # Draw two red boxes
        cairo.set_source_rgba(1, 0, 0, 0.5)
        cairo.rectangle(200, 100, 100, 100)
        cairo.fill()
        cairo.rectangle(200, 300, 100, 100)
        cairo.fill()
        # Draw two white boxes
        cairo.set_source_rgba(1, 1, 1, 0.5)
        cairo.rectangle(300, 100, 100, 100)
        cairo.fill()
        cairo.rectangle(300, 300, 100, 100)
        cairo.fill()

    def update_frame_data(self, frame, frame_time):
        cairo = None
        if self.video_enabled:
            # Process NumPy array frame data
            height, width, channels = frame.shape
            depth = {np.dtype('uint8'): 8}[frame.dtype]
            logging.debug('[update_frame_data] type(frame)=%s '\
                'height, width, channels, depth=(%s)'\
                % (type(frame), (height, width, channels, depth)))
            gtk_frame = array2cv(frame)
            cv.CvtColor(gtk_frame, gtk_frame, cv.CV_BGR2RGB)
            x, y, a_width, a_height = self.area.get_allocation()
            if a_width != width or a_height != height:
                resized = cv.CreateMat(width, height, cv.CV_8UC3)
                cv.Resize(gtk_frame, resized)
            else:
                resized = gtk_frame
            self.pixbuf = gtk.gdk.pixbuf_new_from_data(
                resized.tostring(), gtk.gdk.COLORSPACE_RGB, False,
                depth, width, height, height * 3) #resized.step)
            self.pixmap, mask = self.pixbuf.render_pixmap_and_mask()
            cairo = self.pixmap.cairo_create()
        elif self.pixmap is not None:
            x, y, width, height = self.area.get_allocation()
            cairo = self.pixmap.cairo_create()
            cairo.set_source_rgb(1, 1, 1)
            cairo.rectangle(0, 0, width, height)
            cairo.fill()
        if cairo:
            self.draw_state(cairo)
        self.area.queue_draw()
        return True

    def on_window_destroy(self, widget):
        gtk.main_quit()
        results = self.grabber.stop()

        logging.info(str(results))
        del self.cam_cap