Exemple #1
0
def histogram(src):
    '''
    '''
    size = (30, 32)
    hist = cvCreateHist(size, CV_HIST_ARRAY)

    h_plane = cvCreateImage(cvGetSize(src), src.depth, 1)
    s_plane = cvCreateImage(cvGetSize(src), src.depth, 1)
    # v_plane = cvCreateImage(cvGetSize(src), src.depth, 1)
    for chan, plane in [(1, h_plane), (2, s_plane)]:
        cvSetImageCOI(src, chan)
        cvCopy(src, plane)

    cvSetImageCOI(src, 0)
    planes = (h_plane, s_plane)

    cvCalcHist(planes, hist, 0, 0)
    dst = new_dst(src, nchannels=1)
    cvCalcBackProject(planes, dst, hist)
    return dst
Exemple #2
0
def remove_noise(img, x, y, w, h):
    sz = cvSize(w, h)
    # sz = cvSize(img.width & -2, img.height & -2)
    subimage = cvCloneImage(img)  # make a copy of input image
    crop(subimage, x, y, w, h)
    # gray = cvCreateImage(sz, 8, 1)
    pyr = cvCreateImage(cvSize(int(sz.width / 2), int(sz.height / 2)), 8, 3)
#    subimage = cvGetSubRect(timg, None, cvRect(0, 0, sz.width, sz.height))

    # down-scale and upscale the image to filter out the noise
    cvPyrDown(subimage, pyr, 7)
    cvPyrUp(pyr, subimage, 7)
    return subimage
Exemple #3
0
def new_dst(src, zero=False, width=None,
            height=None, nchannels=None, size=None):
    '''
    '''

#    print nchannels
    if width is not None and height is not None:
        size = CvSize(width, height)
    elif size is None:
        size = cvGetSize(src)

    if nchannels is None:
        nchannels = src.nChannels

    img = cvCreateImage(size, 8, nchannels)
    if zero:
        cvZero(img)
    return img
#  logfile = open("/opt/ibehave/log/scripts.log",'w')  # TODO: better logging!
#  print >> logfile, "-----------------> Model Background"
#  print >> logfile, invideofile
#  print >> logfile, background 

#######################################

# open the video
cap = ocv.cvCreateFileCapture(invideofile)
# extract the number of frames
max_frames = ocv.cvGetCaptureProperty(cap,ocv.CV_CAP_PROP_FRAME_COUNT)
# interrogate the first frame to get the size
frame = ocv.cvQueryFrame(cap)
frame_size = ocv.cvGetSize(frame)

working =       ocv.cvCreateImage(frame_size,ocv.IPL_DEPTH_32F,3)
accumulator =   ocv.cvCreateImage(frame_size,ocv.IPL_DEPTH_32F,3)
background =    ocv.cvCreateImage(frame_size,ocv.IPL_DEPTH_32F,3)
ones =		ocv.cvCreateImage(frame_size,ocv.IPL_DEPTH_32F,3)
target =	ocv.cvCloneImage(frame) 

# Set divisor image all to one
ocv.cvSet(ones,ocv.cvScalar(1.0,1.0,1.0,0))

if show:
  ocv.cvNamedWindow ('Track', ocv.CV_WINDOW_AUTOSIZE)
  ocv.cvMoveWindow ('Track', 100, 100)

t = 1
n = 1
Exemple #5
0
anglefrom = pi*0.33 # angles of turning
angleto = pi*0.66

#######################################

# open the video
cap = ocv.cvCreateFileCapture(filename)
# extract the number of frames
max_frames = ocv.cvGetCaptureProperty(cap,ocv.CV_CAP_PROP_FRAME_COUNT)
# interrogate the first frame to get the size
t = 1
frame = ocv.cvQueryFrame(cap)
frame_size = ocv.cvGetSize(frame)

# create some temporary frames
gray =		ocv.cvCreateImage(frame_size,8,1) 
#backgray =		ocv.cvCreateImage(frame_size,8,1) 
grayfloat =		ocv.cvCreateImage(frame_size,ocv.IPL_DEPTH_32F,1)
background =		ocv.cvCreateImage(frame_size,ocv.IPL_DEPTH_32F,1)
ones =		ocv.cvCreateImage(frame_size,ocv.IPL_DEPTH_32F,1)
thresh = 	ocv.cvCreateImage(frame_size,8,1) 
output =	ocv.cvCloneImage(frame) 
masked = 	ocv.cvCreateImage(frame_size,8,1) 
  
#mask = ocv.cvLoadImage(maskname,0)
backgray = ocv.cvLoadImage(backname,0) 
#print back
#print frame_size.width, frame_size.height 
#ocv.cvConvertImage(back,backgray)
ocv.cvConvert(backgray,background)