def drawImage(image,h,w,psize):
    """
    Draw the image as a continuous line on a surface h by w "pixels" where 
    each continuous line representation of a pixel in image is represented
    on the output suface using psize by psize "pixels".

    @param  image   an opencv image with at least 3 channels
    @param  h       integer representing the hight of the output surface
    @param  w       integer representing the width of the output surface
    @param  psize   ammount that each pixel in the input image is scaled up
    """
    h = (h/psize)-2
    w = (w/psize)-2
    size = opencv.cvSize(w,h)
    scaled = opencv.cvCreateImage(size,8,3)
    red = opencv.cvCreateImage(size,8,1)
    blue = opencv.cvCreateImage(size,8,1)
    green = opencv.cvCreateImage(size,8,1)
    opencv.cvSplit(scaled,blue,green,red,None)
    opencv.cvEqualizeHist(red,red)
    opencv.cvEqualizeHist(green,green)
    opencv.cvEqualizeHist(blue,blue)
    opencv.cvMerge(red,green,blue,None,scaled)
    opencv.cvResize(image,scaled,opencv.CV_INTER_LINEAR)
    opencv.cvNot(scaled,scaled)

    # Draw each pixel in the image
    xr = range(scaled.width)
    whitespace = 0
    for y in range(scaled.height):
        for x in xr:
            s = opencv.cvGet2D(scaled,y,x)
            s = [s[j] for j in range(3)]
            if (sum(s)/710.0 < 1.0/psize):
                whitespace = whitespace+psize
            else:
                if whitespace is not 0:
                    line(whitespace,6,(xr[0]>0))
                    whitespace = 0
                drawPixel([j/255.0 for j in s],psize,(xr[0]>0))
        if whitespace is not 0:
            line(whitespace,6,(xr[0]>0))
            whitespace = 0
        line(psize,2)
        xr.reverse()
        displayImage(output)
        events = pygame.event.get()
        for event in events:
            if event.type == QUIT:
		exit()
Example #2
0
def mask(img, img_mask):
    dim = img.width, img.height
    depth = img.depth
    channels = img.nChannels

    r_chan = cv.cvCreateImage(cv.cvSize(*dim), depth, 1)
    g_chan = cv.cvCreateImage(cv.cvSize(*dim), depth, 1)
    b_chan = cv.cvCreateImage(cv.cvSize(*dim), depth, 1)
    combined = cv.cvCreateImage(cv.cvSize(*dim), depth, 3)
    cv.cvSplit(img, r_chan, g_chan, b_chan, None)

    cv.cvAnd(r_chan, img_mask, r_chan)
    cv.cvAnd(g_chan, img_mask, g_chan)
    cv.cvAnd(b_chan, img_mask, b_chan)
    cv.cvMerge(r_chan, g_chan, b_chan, None, combined)
    return combined
Example #3
0
def mask(img, img_mask):
    dim      = img.width, img.height
    depth    = img.depth
    channels = img.nChannels

    r_chan = cv.cvCreateImage(cv.cvSize(*dim), depth, 1)
    g_chan = cv.cvCreateImage(cv.cvSize(*dim), depth, 1)
    b_chan = cv.cvCreateImage(cv.cvSize(*dim), depth, 1)
    combined = cv.cvCreateImage(cv.cvSize(*dim), depth, 3)
    cv.cvSplit(img, r_chan, g_chan, b_chan, None)

    cv.cvAnd(r_chan, img_mask, r_chan)
    cv.cvAnd(g_chan, img_mask, g_chan)
    cv.cvAnd(b_chan, img_mask, b_chan)
    cv.cvMerge(r_chan, g_chan, b_chan, None, combined)
    return combined