Example #1
0
def filters():
    image = cv2.imread(config.ORIGIN_IMAGE)
    blur = [cv2.GaussianBlur(image, (5, 5), 0)]
    blur.append(cv2.medianBlur(image, 5))
    blur.append(cv2.boxFilter(image, 5, (5, 5)))
    for i, x in enumerate(blur):
        cv2.imwrite(
            config.RESULT_PATH + "%s_mode_%s.jpg" % (
                config.current_filename(__file__), i),
            x)
Example #2
0
        roi_gray = gray[y:y + h, x:x + w]
        roi_color = image[y:y + h, x:x + w]
        eyes = eye_cascade.detectMultiScale(roi_gray)
        for (ex, ey, ew, eh) in eyes:
            cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0),
                          2)
    return image


if __name__ == "__main__":
    cam = cv2.VideoCapture(0)
    w = int(cam.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH))
    h = int(cam.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT))
    # video doesn't play
    out = cv2.VideoWriter(
        config.RESULT_PATH + "%s.mp4" % config.current_filename(__file__), -1,
        25,
        (w, h))
    while 1:
        _, frame = cam.read()
        frame = detect(frame)
        if cam.isOpened():
            out.write(frame)
        cv2.imshow('Video', frame)
        if cv2.waitKey(1) == 0x1b:  # ESC
            print 'ESC pressed. Exiting ...'
            break
    cam.release()
    out.release()
    cv2.destroyAllWindows()
Example #3
0
import cv2

from config import config

img1 = cv2.imread(config.ORIGIN_IMAGE)
imgray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 127, 255, cv2.THRESH_BINARY)

for x in [cv2.RETR_EXTERNAL, cv2.RETR_LIST, cv2.RETR_CCOMP, cv2.RETR_TREE]:
    ret, thresh = cv2.threshold(imgray, 127, 255, cv2.THRESH_BINARY)
    contours, hierarchy = cv2.findContours(thresh, x, cv2.CHAIN_APPROX_SIMPLE)
    cv2.drawContours(thresh, contours, 0, (0, 255, 0), 3)
    cv2.imwrite(
        config.RESULT_PATH + "%s_mode_%s.jpg" % (
        config.current_filename(__file__), str(x)),
        thresh)
# cv2.waitKey(0)
cv2.destroyAllWindows()
Example #4
0
import cv2

from config import config

img1 = cv2.imread(config.ORIGIN_IMAGE)
imgray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 127, 200, cv2.THRESH_BINARY)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(thresh, contours, 30, (0, 255, 0), 3)
cv2.imwrite(config.RESULT_PATH + "%s.jpg" % config.current_filename(__file__), thresh)
# cv2.waitKey(0)
cv2.destroyAllWindows()
Example #5
0
import cv2

from config import config

img1 = cv2.imread(config.ORIGIN_IMAGE)
imgray = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(imgray, 127, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE,
                                       cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(img1, contours, -1, (0, 255, 0), 3)
cv2.imwrite(config.RESULT_PATH + '%s.jpg' % config.current_filename(__file__),
            img1)