Пример #1
0
def Video2IplList(i_file, i_scale=1.0, i_reverse_list=False):
    from frame_grabber import FrameGrabberFile
    """Return a list of video frames in opencv format - first frame first in list if i_reverse_list=False, otherwise first frame is last"""
    frame_grabber = FrameGrabberFile(i_file, i_loop_back=False)
    o_data = []

    while True:
        current_frame = frame_grabber.nextFrame()
        if current_frame == None:
            break
        else:
            current_frame = frame_grabber.currentFrame()
            w = int(i_scale * float(current_frame.width) + 0.5)
            h = int(i_scale * float(current_frame.height) + 0.5)
            o_data.append(IplResizeAndConvert(current_frame, w, h))
    if i_reverse_list:
        o_data.reverse()
    return o_data
Пример #2
0
def Video2Numpy(i_file, i_scale=1.):
    from frame_grabber import FrameGrabberFile
    """Return a 3D numpy array from a video file"""
    frame_grabber = FrameGrabberFile(i_file, i_loop_back=False)
    o_data = None
    nframes = 0
    while True:
        current_frame = frame_grabber.nextFrame()
        if current_frame == None:
            break
        else:
            current_frame = frame_grabber.currentFrame()
            w = int(i_scale * float(current_frame.width) + 0.5)
            h = int(i_scale * float(current_frame.height) + 0.5)
            image = IplResizeAndConvert(current_frame, w, h)
            image = cv.Ipl2NumPy(image)
            if o_data == None:
                o_data = image
            else:
                o_data = numpy.dstack([o_data, image])
    return o_data
Пример #3
0
    def __init__(self, i_head_tracker, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.__display = qt_image_display.ImageDisplayAndRecord()
        #Recording button
        self.__record_button = QtGui.QPushButton(self)
        self.__record_button.setCheckable(True)
        self.__record_button.setObjectName("recordButton")
        self.__record_button.setText("Record")
        self.connect(self.__record_button, QtCore.SIGNAL("clicked(bool)"),
                     self.recordSlot)

        #File playback button
        self.__file_button = QtGui.QPushButton(self)
        self.__file_button.setCheckable(True)
        self.__file_button.setObjectName("fileButton")
        self.__file_button.setText("Display .avi")
        self.connect(self.__file_button, QtCore.SIGNAL("clicked(bool)"),
                     self.fileSlot)

        #Run Viola Jones on each frame and get the largest face
        self.__face_button = QtGui.QPushButton(self)
        self.__face_button.setCheckable(True)
        self.__face_button.setObjectName("detectButton")
        self.__face_button.setText("Detect faces")
        #Tracking checkBox
        self.__tracking_box = QtGui.QCheckBox()
        self.__tracking_box.setChecked(True)
        self.__tracking_box.setObjectName("trackingBox")
        self.__tracking_box.setText("Enable tracking")
        #Enable xy coordinate out put
        self.__active_box = QtGui.QCheckBox()
        self.__active_box.setChecked(False)
        self.__active_box.setObjectName("activeBox")
        self.__active_box.setText("Activate Cursor Control (ESC to exit)")
        #The scroll bar
        self.__scrollbar_gain_x = QtGui.QScrollBar()
        self.__scrollbar_gain_x.setGeometry(QtCore.QRect(0, 190, 291, 20))
        self.__scrollbar_gain_x.setMinimum(1)
        self.__scrollbar_gain_y = QtGui.QScrollBar()
        self.__scrollbar_gain_y.setGeometry(QtCore.QRect(0, 190, 291, 20))
        self.__scrollbar_gain_y.setMinimum(1)
        slider_max = 100
        self.__scrollbar_gain_x.setMaximum(slider_max)
        self.__scrollbar_gain_x.setProperty("value",
                                            QtCore.QVariant(slider_max / 2))
        self.__scrollbar_gain_x.setSliderPosition(slider_max / 2)
        self.__scrollbar_gain_x.setOrientation(QtCore.Qt.Horizontal)
        self.__scrollbar_gain_x.setObjectName("scrollbar_gain")
        self.__scrollbar_gain_y.setMaximum(slider_max)
        self.__scrollbar_gain_y.setProperty("value",
                                            QtCore.QVariant(slider_max / 2))
        self.__scrollbar_gain_y.setSliderPosition(slider_max / 2)
        self.__scrollbar_gain_y.setOrientation(QtCore.Qt.Horizontal)
        self.__scrollbar_gain_y.setObjectName("scrollbar_gain")
        self.__label_gain_x = QtGui.QLabel()
        self.__label_gain_x.setText(QtCore.QString("X gain"))
        self.__label_gain_y = QtGui.QLabel()
        self.__label_gain_y.setText(QtCore.QString("Y gain"))

        #Camera capture settings
        self.__scale_select = QtGui.QDoubleSpinBox()
        self.__scale_select.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.__scale_select.setMaximum(1.0)
        self.__scale_select.setMinimum(0.1)
        self.__scale_select.setSingleStep(0.25)
        self.__scale_select.setProperty("value", QtCore.QVariant(1.0))
        self.__scale_label = QtGui.QLabel()
        self.__scale_label.setText(QtCore.QString("Image scale"))

        self.__device = QtGui.QComboBox(self)
        self.__device.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.__device.setObjectName("device")
        for n in range(0, 6):
            self.__device.addItem(QtCore.QString(str(n)), QtCore.QVariant(n))

        self.__device.setCurrentIndex(0)
        self.__device_label = QtGui.QLabel()
        self.__device_label.setText(QtCore.QString("Device number"))

        #Set the layout
        g_layout = QtGui.QGridLayout()
        g_layout.addWidget(self.__face_button, 0, 0)
        g_layout.addWidget(self.__record_button, 1, 0)
        g_layout.addWidget(self.__file_button, 2, 0)
        g_layout.addWidget(self.__tracking_box, 3, 0)
        g_layout.addWidget(self.__active_box, 4, 0)
        g_layout.addWidget(self.__label_gain_x, 5, 0)
        g_layout.addWidget(self.__scrollbar_gain_x), 6, 0
        g_layout.addWidget(self.__label_gain_y, 7, 0)
        g_layout.addWidget(self.__scrollbar_gain_y, 8, 0)
        g_layout.addWidget(self.__scale_label, 9, 0)
        g_layout.addWidget(self.__scale_select, 10, 0)
        g_layout.addWidget(self.__device_label, 11, 0)
        g_layout.addWidget(self.__device, 12, 0)
        v_layout = QtGui.QVBoxLayout()
        v_layout.addWidget(self.__display)
        spacer = QtGui.QSpacerItem(10, 100, QtGui.QSizePolicy.Expanding,
                                   QtGui.QSizePolicy.Minimum)
        v_layout.addItem(spacer)

        g_layout.addLayout(v_layout, 0, 1, 12, 1)

        self.setLayout(g_layout)
        #Screen size
        desktop = QtGui.QDesktopWidget()
        screen_size = QtCore.QRectF(
            desktop.screenGeometry(desktop.primaryScreen()))
        x = screen_size.x() + screen_size.width()
        y = screen_size.y() + screen_size.height()
        self.__current_pos = [x / 2., y / 2.]

        #Init the core algorithms
        self.__frame_grabber_file = FrameGrabberFile("out.avi")
        (cam, is_data) = self.__device.itemData(
            self.__device.currentIndex()).toInt()
        self.__frame_grabber_cam = FrameGrabberWebCam(
            i_scale=self.__scale_select.value(), i_camera=cam)
        self.__frame_grabber = self.__frame_grabber_cam
        self.__head_tracker = i_head_tracker

        #Connect signals
        QtCore.QObject.connect(self.__scale_select,
                               QtCore.SIGNAL("valueChanged(double)"),
                               self.updateImageScale)
        QtCore.QObject.connect(self.__device,
                               QtCore.SIGNAL("currentIndexChanged(int)"),
                               self.updateDevice)

        #Main functions
        self.__timer = QtCore.QTimer()
        QtCore.QObject.connect(self.__timer, QtCore.SIGNAL("timeout()"),
                               self.update)
        self.__timer.start(20)