Exemple #1
0
def video_file(file):
    cap = hg.cvCreateFileCapture(file)
    f = hg.cvQueryFrame(cap)

    while f != None:
        yield f
        f = hg.cvQueryFrame(cap)
Exemple #2
0
def video_file(file):
     cap          = hg.cvCreateFileCapture(file);
     f            = hg.cvQueryFrame(cap)

     while f != None:
         yield f
         f          = hg.cvQueryFrame(cap)
Exemple #3
0
    def process(self, videofile, progress):
        progress(0, _("Extracting histogram"))
        video = hg.cvCreateFileCapture(str(videofile).encode(sys.getfilesystemencoding()))
        if not video:
            raise Exception("Could not open video file")
        histo = cv.cvCreateHist([256],cv.CV_HIST_ARRAY,[[0,256]], 1)
        frame = hg.cvQueryFrame(video)
        frame_gray  = cv.cvCreateImage(cv.cvGetSize(frame), frame.depth, 1);
        hists    = []
        nbframes = 0

        fps = hg.cvGetCaptureProperty(video, hg.CV_CAP_PROP_FPS)
        while frame :
            if not progress(hg.cvGetCaptureProperty(video, hg.CV_CAP_PROP_POS_AVI_RATIO)):
                break
            hg.cvConvertImage(frame,frame_gray)
            cv.cvCalcHist(frame_gray,histo,0,None)
            h = [cv.cvGetReal1D(histo.bins,i) for i in range(255) ]
            h = numpy.array(h,dtype='int32')
            hists.append(h)
            frame = hg.cvQueryFrame(video)
            nbframes += 1

        hists = numpy.array(hists)
        return hists.reshape(nbframes, -1), fps
Exemple #4
0
def _detect(image):
    """ Detects faces on `image`
    Parameters:
        @image: image file path

    Returns:
        [((x1, y1), (x2, y2)), ...] List of coordenates for top-left
                                    and bottom-right corner
    """
    # the OpenCV API says this function is obsolete, but we can't
    # cast the output of cvLoad to a HaarClassifierCascade, so use
    # this anyways the size parameter is ignored
    capture = cvCreateFileCapture(image) 

    if not capture:
        return []

    frame = cvQueryFrame(capture)
    if not frame:
        return []

    img = cvCreateImage(cvSize(frame.width, frame.height),
                        IPL_DEPTH_8U, frame.nChannels)
    cvCopy(frame, img)

    # allocate temporary images
    gray          = cvCreateImage((img.width, img.height),
                                  COPY_DEPTH, COPY_CHANNELS)
    width, height = (cvRound(img.width / IMAGE_SCALE),
                     cvRound(img.height / IMAGE_SCALE))
    small_img     = cvCreateImage((width, height), COPY_DEPTH, COPY_CHANNELS)

    # convert color input image to grayscale
    cvCvtColor(img, gray, CV_BGR2GRAY)

    # scale input image for faster processing
    cvResize(gray, small_img, CV_INTER_LINEAR)
    cvEqualizeHist(small_img, small_img)
    cvClearMemStorage(STORAGE)

    coords = []
    for haar_file in CASCADES:
        cascade = cvLoadHaarClassifierCascade(haar_file, cvSize(1, 1))
        if cascade:
            faces = cvHaarDetectObjects(small_img, cascade, STORAGE, HAAR_SCALE,
                                        MIN_NEIGHBORS, HAAR_FLAGS, MIN_SIZE) or []
            for face_rect in faces:
                # the input to cvHaarDetectObjects was resized, so scale the 
                # bounding box of each face and convert it to two CvPoints
                x, y = face_rect.x, face_rect.y
                pt1 = (int(x * IMAGE_SCALE), int(y * IMAGE_SCALE))
                pt2 = (int((x + face_rect.width) * IMAGE_SCALE),
                       int((y + face_rect.height) * IMAGE_SCALE))
                coords.append((pt1, pt2))
    return coords
Exemple #5
0
def _detect(image):
    """ Detects faces on `image`
    Parameters:
        @image: image file path

    Returns:
        [((x1, y1), (x2, y2)), ...] List of coordenates for top-left
                                    and bottom-right corner
    """
    # the OpenCV API says this function is obsolete, but we can't
    # cast the output of cvLoad to a HaarClassifierCascade, so use
    # this anyways the size parameter is ignored
    capture = cvCreateFileCapture(image)

    if not capture:
        return []

    frame = cvQueryFrame(capture)
    if not frame:
        return []

    img = cvCreateImage(cvSize(frame.width, frame.height), IPL_DEPTH_8U,
                        frame.nChannels)
    cvCopy(frame, img)

    # allocate temporary images
    gray = cvCreateImage((img.width, img.height), COPY_DEPTH, COPY_CHANNELS)
    width, height = (cvRound(img.width / IMAGE_SCALE),
                     cvRound(img.height / IMAGE_SCALE))
    small_img = cvCreateImage((width, height), COPY_DEPTH, COPY_CHANNELS)

    # convert color input image to grayscale
    cvCvtColor(img, gray, CV_BGR2GRAY)

    # scale input image for faster processing
    cvResize(gray, small_img, CV_INTER_LINEAR)
    cvEqualizeHist(small_img, small_img)
    cvClearMemStorage(STORAGE)

    coords = []
    for haar_file in CASCADES:
        cascade = cvLoadHaarClassifierCascade(haar_file, cvSize(1, 1))
        if cascade:
            faces = cvHaarDetectObjects(small_img, cascade, STORAGE,
                                        HAAR_SCALE, MIN_NEIGHBORS, HAAR_FLAGS,
                                        MIN_SIZE) or []
            for face_rect in faces:
                # the input to cvHaarDetectObjects was resized, so scale the
                # bounding box of each face and convert it to two CvPoints
                x, y = face_rect.x, face_rect.y
                pt1 = (int(x * IMAGE_SCALE), int(y * IMAGE_SCALE))
                pt2 = (int((x + face_rect.width) * IMAGE_SCALE),
                       int((y + face_rect.height) * IMAGE_SCALE))
                coords.append((pt1, pt2))
    return coords
Exemple #6
0
    def __init__(self, path, start=0, stop=None):
        self.path = path
        self.video = hg.cvCreateFileCapture(self.path)

        # these functions don't seem to work at present on my linux system

        # self.fps = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FPS)
        # self.n_of_frames = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_COUNT)
        # self.duration = self.n_of_frames/self.fps
        # self.width = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_WIDTH)
        # self.height = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_HEIGHT)
        hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_POS_FRAMES, start)
Exemple #7
0
    def __init__(self, path, start=0, stop=None):
        self.path = path
        self.video = hg.cvCreateFileCapture(self.path)

        # these functions don't seem to work at present on my linux system
        
        #self.fps = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FPS)
        #self.n_of_frames = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_COUNT)
        #self.duration = self.n_of_frames/self.fps
        #self.width = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_WIDTH)
        #self.height = hg.cvGetCaptureProperty(self.video, hg.CV_CAP_PROP_FRAME_HEIGHT)
        hg.cvSetCaptureProperty(self.video, hg.CV_CAP_PROP_POS_FRAMES, start)
Exemple #8
0
    def __init__(self, parent=None):
        QWidget.__init__(self)
        self.resize(550, 550)
        self.setWindowTitle('vedio control')
        self.status = 0  # 0 is init status;1 is play video; 2 is capture video
        self.image = QImage()

        # 录制的视频保存位置、格式等参数设定
        self.videowriter = highgui.cvCreateVideoWriter(
            "test.mpg", highgui.CV_FOURCC('m', 'p', 'g', '1'), 25,
            cv.cvSize(200, 200), 1)
        # 播放的视频位置
        self.playcapture = highgui.cvCreateFileCapture("test.avi")

        # 初始化按钮
        self.capturebtn = QPushButton('capture')
        self.playbtn = QPushButton('play')
        exitbtn = QPushButton('exit')

        # 界面布局
        vbox = QVBoxLayout()
        vbox.addWidget(self.capturebtn)
        vbox.addWidget(self.playbtn)
        vbox.addWidget(exitbtn)

        self.piclabel = QLabel('pic')
        hbox = QHBoxLayout()
        hbox.addLayout(vbox)
        hbox.addStretch(1)
        hbox.addWidget(self.piclabel)

        self.setLayout(hbox)

        # 加载初始页面
        if self.image.load("1.jpg"):
            self.piclabel.setPixmap(QPixmap.fromImage(self.image))

            # 设定定时器
        self.timer = Timer()  # 录制视频
        self.playtimer = Timer("updatePlay()")  # 播放视频

        # 信号--槽
        self.connect(self.timer, SIGNAL("updateTime()"), self.CaptureVGA)
        self.connect(self.capturebtn, SIGNAL("clicked()"), self.PauseBegin)
        self.connect(self.playtimer, SIGNAL("updatePlay()"), self.PlayVideo)
        self.connect(self.playbtn, SIGNAL("clicked()"), self.VideoPlayPause)
        self.connect(exitbtn, SIGNAL("clicked()"), app, SLOT("quit()"))
Exemple #9
0
 def createCapture(self, file_name):
     capture = cvCreateFileCapture(file_name)
     return capture
Exemple #10
0
 def createCapture(self, file_name):
     capture = cvCreateFileCapture(file_name)
     return capture
        # no device number on the command line, assume we want the 1st device
        device = 0

    if len (sys.argv) == 1:
        # no argument on the command line, try to use the camera
        capture = highgui.cvCreateCameraCapture (device)

        # set the wanted image size from the camera
        highgui.cvSetCaptureProperty (capture,
                                      highgui.CV_CAP_PROP_FRAME_WIDTH, 320)
        highgui.cvSetCaptureProperty (capture,
                                      highgui.CV_CAP_PROP_FRAME_HEIGHT,240)
    else:
        # we have an argument on the command line,
        # we can assume this is a file name, so open it
        capture = highgui.cvCreateFileCapture (sys.argv [1])            

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit (1)
        
    # create an image to put in the histogram
    histimg = cv.cvCreateImage (cv.cvSize (320,240), 8, 3)

    # init the image of the histogram to black
    cv.cvSetZero (histimg)

    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame (capture)
Exemple #12
0
#! /usr/bin/env python

import opencv
from opencv import highgui

cap = highgui.cvCreateFileCapture("../c/tree.avi")
img = highgui.cvQueryFrame(cap)
print "Got frame of dimensions (", img.width, " x ", img.height, " )"

highgui.cvNamedWindow("win", highgui.CV_WINDOW_AUTOSIZE)
highgui.cvShowImage("win", img)
highgui.cvMoveWindow("win", 200, 200)
highgui.cvWaitKey(0)

Exemple #13
0
        # no device number on the command line, assume we want the 1st device
        device = 0

    if len(sys.argv) == 1:
        # no argument on the command line, try to use the camera
        capture = highgui.cvCreateCameraCapture(device)

        # set the wanted image size from the camera
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_WIDTH,
                                     1600)
        highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FRAME_HEIGHT,
                                     1200)
    else:
        # we have an argument on the command line,
        # we can assume this is a file name, so open it
        capture = highgui.cvCreateFileCapture(sys.argv[1])

    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit(1)

    # create an image to put in the histogram
    histimg = cv.cvCreateImage(cv.cvSize(320, 240), 8, 3)

    # init the image of the histogram to black
    cv.cvSetZero(histimg)

    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame(capture)
Exemple #14
0
 def __init__(self, left_file, right_file):
     self.left  = hg.cvCreateFileCapture(left_file);
     self.right = hg.cvCreateFileCapture(right_file);
Exemple #15
0
 def __init__(self, left_file, right_file):
     self.left = hg.cvCreateFileCapture(left_file)
     self.right = hg.cvCreateFileCapture(right_file)
Exemple #16
0
                print """usage : multitouch [option]
    option:
        -h  | --help                            show help
        -f  | --file    <path>                  open file (no cam)
        -s  | --size    <width><height>         param of cam
        --noGUI                                dont show windows
        
        attention a l ordre des arguments
                
                """
                sys.exit(1)
            elif sys.argv[i] == "-s" or sys.argv[i] == "--size":
                capture = init_cam(sys.argv[i + 1], sys.argv[i + 2])
                i = i + 2
            elif sys.argv[i] == "-f" or sys.argv[i] == "--file":
                capture = highgui.cvCreateFileCapture(str(sys.argv[i + 1]))
                i = i + 1
            elif sys.argv[i] == "--noGUI":
                GUI = 0
                capture = init_cam()
                i = i + 1
            elif sys.argv[i] == "--fps":
                capture = init_cam()
                highgui.cvSetCaptureProperty(capture, highgui.CV_CAP_PROP_FPS,
                                             int(sys.argv[i + 1]))
                i = i + 1
    # check that capture device is OK
    if not capture:
        print "Error opening capture device"
        sys.exit(1)