コード例 #1
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
コード例 #2
0
    # capture the 1st frame to get some propertie on it
    frame = highgui.cvQueryFrame (capture)

    # get some properties of the frame
    frame_size = cv.cvGetSize (frame)

    # compute which selection of the frame we want to monitor
    selection = cv.cvRect (0, 0, frame.width, frame.height)

    # create some images usefull later
    hue = cv.cvCreateImage (frame_size, 8, 1)
    mask = cv.cvCreateImage (frame_size, 8, 1)
    hsv = cv.cvCreateImage (frame_size, 8, 3 )

    # create the histogram
    hist = cv.cvCreateHist ([hdims], cv.CV_HIST_ARRAY, hranges, 1)

    while 1:
        # do forever

        # 1. capture the current image
        frame = highgui.cvQueryFrame (capture)
        if frame is None:
            # no image captured... end the processing
            break

        # mirror the captured image
        cv.cvFlip (frame, None, 1)

        # compute the hsv version of the image 
        cv.cvCvtColor (frame, hsv, cv.CV_BGR2HSV)
コード例 #3
0
    frame = highgui.cvQueryFrame(capture)

    # get some properties of the frame
    frame_size = cv.cvGetSize(frame)

    # compute which selection of the frame we want to monitor
    selection = cv.cvRect(0, 0, frame.width, frame.height)

    # create some images usefull later
    hue = cv.cvCreateImage(frame_size, 8, 1)
    mask = cv.cvCreateImage(frame_size, 8, 1)
    hsv = cv.cvCreateImage(frame_size, 8, 3)
    backproject = cv.cvCreateImage(frame_size, 8, 1)

    # create the histogram
    hist = cv.cvCreateHist([hdims], cv.CV_HIST_ARRAY, hranges, 1)
    obj_hist = cv.cvCreateHist([hdims], cv.CV_HIST_ARRAY, hranges, 1)
    while 1:
        # do forever

        # 1. capture the current image
        frame = highgui.cvQueryFrame(capture)
        if frame is None:
            # no image captured... end the processing
            break

        # mirror the captured image
        #cv.cvFlip (frame, None, 1)

        # compute the hsv version of the image
        cv.cvCvtColor(frame, hsv, cv.CV_BGR2HSV)
コード例 #4
0
sample_pixels = 0.0
for x in xrange(size.width):
    for y in xrange(size.height):
        if cv.cvGetReal2D(mask_bw, y, x) > 0:
            sample_pixels = sample_pixels + 1
print "Sample region: %f%%" % (100 * sample_pixels / total_pixels)
del (tmp)


h_bins = 20
h_limit = 180
s_bins = 32
v_bins = 32
v_limit = 255
# create histogram with 30 bins
h_hue = cv.cvCreateHist([h_bins], cv.CV_HIST_ARRAY, [[0, h_limit]], 1)
h_sat = cv.cvCreateHist([s_bins], cv.CV_HIST_ARRAY, [[0, 255]], 1)
h_val = cv.cvCreateHist([v_bins], cv.CV_HIST_ARRAY, [[0, v_limit]], 1)

# histogram limits
hsv_min = cv.cvScalar(0, 30, 10, 0)
hsv_max = cv.cvScalar(180, 256, 256, 0)
scalewidth = 20
scaleheight = 400.0

# object classification boundries
# if the bin value a given pixel falls into is lower than one of these cutoffs,
# that pixel is classified as an obstacle
hue_cutoff = 0.01 * sample_pixels  # 1.0%
val_cutoff = 0.015 * sample_pixels  # 1.5%