예제 #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
            scale = 0.

        # scale the histograms
        cv.cvConvertScale (hist.bins, hist.bins, scale, 0)

        # clear the histogram image
        cv.cvSetZero (histimg)

        # compute the width for each bin do display
        bin_w = histimg.width / hdims
        
        for  i in range (hdims):
            # for all the bins

            # get the value, and scale to the size of the hist image
            val = cv.cvRound (cv.cvGetReal1D (hist.bins, i)
                              * histimg.height / 255)

            # compute the color
            color = hsv2rgb (i * 180. / hdims)

            # draw the rectangle in the wanted color
            cv.cvRectangle (histimg,
                            cv.cvPoint (i * bin_w, histimg.height),
                            cv.cvPoint ((i + 1) * bin_w, histimg.height - val),
                            color, -1, 8, 0)

        # we can now display the images
        highgui.cvShowImage ('Camera', frame)
        highgui.cvShowImage ('Histogram', histimg)
예제 #3
0
        # scale the histograms
        cv.cvConvertScale(hist.bins, hist.bins, scale, 0)

        # clear the histogram image
        cv.cvSetZero(histimg)

        # compute the width for each bin do display
        bin_w = histimg.width / hdims

        for i in range(hdims):
            # for all the bins

            # get the value, and scale to the size of the hist image
            val = cv.cvRound(
                cv.cvGetReal1D(hist.bins, i) * histimg.height / 255)

            # compute the color
            color = hsv2rgb(i * 180. / hdims)

            # draw the rectangle in the wanted color
            cv.cvRectangle(histimg, cv.cvPoint(i * bin_w, histimg.height),
                           cv.cvPoint((i + 1) * bin_w, histimg.height - val),
                           color, -1, 8, 0)
        # Make the sweet negative selection box
        if mouse_select_object and mouse_selection.width > 0 and mouse_selection.height > 0:
            a = cv.cvGetSubRect(frame, mouse_selection)
            cv.cvXorS(a, cv.cvScalarAll(255),
                      a)  # Take the negative of the image..
            del a
예제 #4
0
            scale = 0.

        # scale the histograms
        cv.cvConvertScale (hist.bins, hist.bins, scale, 0)

        # clear the histogram image
        cv.cvSetZero (histimg)

        # compute the width for each bin do display
        bin_w = histimg.width / hdims
        
        for  i in range (hdims):
            # for all the bins

            # get the value, and scale to the size of the hist image
            val = cv.cvRound (cv.cvGetReal1D (hist.bins, i)
                              * histimg.height / 255)

            # compute the color
            color = hsv2rgb (i * 180. / hdims)

            # draw the rectangle in the wanted color
            cv.cvRectangle (histimg,
                            cv.cvPoint (i * bin_w, histimg.height),
                            cv.cvPoint ((i + 1) * bin_w, histimg.height - val),
                            color, -1, 8, 0)

        # we can now display the images
        highgui.cvShowImage ('Camera', frame)
        highgui.cvShowImage ('Histogram', histimg)
예제 #5
0
            scale = 0.0

        # scale the histograms
        cv.cvConvertScale(hist.bins, hist.bins, scale, 0)

        # clear the histogram image
        cv.cvSetZero(histimg)

        # compute the width for each bin do display
        bin_w = histimg.width / hdims

        for i in range(hdims):
            # for all the bins

            # get the value, and scale to the size of the hist image
            val = cv.cvRound(cv.cvGetReal1D(hist.bins, i) * histimg.height / 255)

            # compute the color
            color = hsv2rgb(i * 180.0 / hdims)

            # draw the rectangle in the wanted color
            cv.cvRectangle(
                histimg,
                cv.cvPoint(i * bin_w, histimg.height),
                cv.cvPoint((i + 1) * bin_w, histimg.height - val),
                color,
                -1,
                8,
                0,
            )
예제 #6
0
    # calculate histogram
    cv.cvCalcHist(img_h, h_hue, 0, thresh_mask)
    cv.cvCalcHist(img_s, h_sat, 0, thresh_mask)
    cv.cvCalcHist(img_v, h_val, 0, thresh_mask)

    # Don't normalize, use total mask pixels to calculate relative importance
    # cv.cvNormalizeHist(h_hue, 180)
    # cv.cvNormalizeHist(h_sat, 255)
    # cv.cvNormalizeHist(h_val, 255)
    # minv,maxv,minp,maxp = cv.cvMinMaxLoc(img_h)
    # print minv,maxv

    cv.cvZero(hist_hue_img)
    # hue_min,hue_max,min_loc,max_loc = cv.cvGetMinMaxHistValue(h_hue)
    for h in xrange(h_bins):
        hue = cv.cvGetReal1D(h_hue.bins, h)
        color = hsv2rgb(h * h_limit / h_bins)
        cv.cvRectangle(
            hist_hue_img,
            (h * scalewidth, 0),
            ((h + 1) * scalewidth, (hue / sample_pixels) * scaleheight),
            color,
            cv.CV_FILLED,
        )
    cv.cvLine(
        hist_hue_img,
        (0, scaleheight * hue_cutoff / sample_pixels),
        (h_bins * scalewidth, scaleheight * hue_cutoff / sample_pixels),
        (255, 0, 0),
        1,
    )