def threshold(src, threshold, invert=False): ''' ''' dst = cvCloneImage(src) kind = CV_THRESH_BINARY if invert: kind = CV_THRESH_BINARY_INV cvThreshold(src, dst, threshold, 255, kind) return dst
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
def colorspace1D(src, channel='r'): ''' ''' dst = cvCloneImage(src) c = 255 if channel == 'r': s = CvScalar(c, c, 0) elif channel == 'g': s = CvScalar(c, 0, c) else: s = CvScalar(0, c, c) cvSubS(src, s, dst) return dst
def draw_squares(img, squares): ''' ''' dst = cvCloneImage(img) # read 4 sequence elements at a time (all vertices of a square) i = 0 sqr_arr = squares.asarray(CvPoint) pts = [] while i < squares.total: pt = [] # read 4 vertices pt.append(sqr_arr[i]) pt.append(sqr_arr[i + 1]) pt.append(sqr_arr[i + 2]) pt.append(sqr_arr[i + 3]) # draw the square as a closed polyline cvPolyLine(dst, [pt], 1, CV_RGB(0, 255, 0), 3, CV_AA, 0) i += 4 pts.append(pt) return dst, pts
####################################### # 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 while True: # check to see if we should stop if max_frames: if t > max_frames:
def clone(src): ''' ''' return cvCloneImage(src)
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) if show: ocv.cvNamedWindow ('Track', ocv.CV_WINDOW_AUTOSIZE) ocv.cvMoveWindow ('Track', 100, 100) font = ocv.cvInitFont(None,ocv.CV_FONT_HERSHEY_PLAIN, 1.0, 1.0, 0, 1, 8) #######################################