def hue_histogram_as_image(self, hist):
        """ Returns a nice representation of a hue histogram """
        histimg_hsv = cv.CreateImage( (320,200), 8, 3)
        mybins = cv.CloneMatND(hist.bins)
        cv.Log(mybins, mybins)
        
        (_, hi, _, _) = cv.MinMaxLoc(mybins)
        cv.ConvertScale(mybins, mybins, 255. / hi)

        w,h = cv.GetSize(histimg_hsv)
        hdims = cv.GetDims(mybins)[0]
        for x in range(w):
            xh = (180 * x) / (w - 1)  # hue sweeps from 0-180 across the image
            val = int(mybins[int(hdims * x / w)] * h / 255)
            cv.Rectangle( histimg_hsv, (x, 0), (x, h-val), (xh,255,64), -1)
            cv.Rectangle( histimg_hsv, (x, h-val), (x, h), (xh,255,255), -1)

        histimg = cv.CreateImage( (320,200), 8, 3)
        cv.CvtColor(histimg_hsv, histimg, cv.CV_HSV2BGR)
        return histimg
def setup_camshift(roi_selection, img):

    hist = cv.CreateHist([180], cv.CV_HIST_ARRAY, [(0, 180)], 1)
    # backproject_mode = False

    histimg_hsv = cv.CreateImage((320, 200), 8, 3)
    mybins = cv.CloneMatND(hist.bins)
    cv.Log(mybins, mybins)

    (_, hi, _, _) = cv.MinMaxLoc(mybins)
    cv.ConvertScale(mybins, mybins, 255. / hi)

    w, h = cv.GetSize(histimg_hsv)
    hdims = cv.GetDims(mybins)[0]
    for x in range(w):
        xh = (180 * x) / (w - 1)  # hue sweeps from 0-180 across the image
        val = int(mybins[int(hdims * x / w)] * h / 255)
        cv.Rectangle(histimg_hsv, (x, 0), (x, h - val), (xh, 255, 64), -1)
        cv.Rectangle(histimg_hsv, (x, h - val), (x, h), (xh, 255, 255), -1)

    histimg = cv.CreateImage((320, 200), 8, 3)
    cv.CvtColor(histimg_hsv, histimg, cv.CV_HSV2BGR)

    # making_selection
    # print roi_selection[0]
    # print roi_selection[1]
    point1 = roi_selection[0]
    point2 = roi_selection[1]
    xmin = point1[0]
    ymin = point1[1]
    xmax = point2[0]
    ymax = point2[1]
    widthx = xmax - xmin
    heighty = ymax - ymin

    selection = (xmin, ymin, widthx, heighty)
    return selection, hist