img = img_as_ubyte(rgb2grey(lena())) img_grey = cv2.equalizeHist(rgb2grey(img)) ImageViewer(img_grey).show() cascade = cv2.CascadeClassifier('/usr/share/opencv/haarcascades/haarcascade_frontalface_alt.xml') rects = cascade.detectMultiScale(img_grey, scaleFactor=1.1, minNeighbors=3, minSize=(20,20), flags = cv.CV_HAAR_SCALE_IMAGE) # x y w h -> x1 y1 x2 y2 rects[:,2:] += rects[:,:2] boxes(img,rects) capture = cv.CaptureFromCAM(0) frame = np.asarray(cv.QueryFrame(capture)[:,:]).copy() frame_grey = img_as_ubyte(rgb2grey(frame)) del(capture) ImageViewer(frame).show() rects = cascade.detectMultiScale(frame_grey, scaleFactor=1.1, minNeighbors=3, minSize=(20,20), flags = cv.CV_HAAR_SCALE_IMAGE) rects[:,2:] += rects[:,:2] boxes(frame_grey,rects)
bkg = GaussianBlur(background, kernel, blur) cur = GaussianBlur(current, kernel, blur) ImageViewer(cur).show() # get absolute difference between images absdiff = abs(img_as_float(cur) - img_as_float(bkg)) ImageViewer(absdiff).show() grey = rgb2grey(absdiff) # threshold automatically thresholded = grey > threshold_otsu(grey) ImageViewer(thresholded).show() dilated = binary_dilation(thresholded, disk(9)) ImageViewer(dilated).show() filtered = remove_small_objects(dilated, 7000) ImageViewer(filtered).show() # draw box around the car props = regionprops(label(filtered),properties=['BoundingBox']) boxes(current,[props[0]['BoundingBox']])