Beispiel #1
0
	def parseRecipeImage(self):
		try:
			image_url = find_image(self.page_url, self.soup)
			if not image_url:
				return ""
			else:
				return image_url
		except:
			return ""
def docker_image(tmpdir, light_project, request, docker_client):
    project = light_project

    cmd = [os.path.join(basepath, "cartridge"), "pack", "docker", project.path]
    process = subprocess.run(cmd, cwd=tmpdir)
    assert process.returncode == 0, \
        "Error during creating of docker image"

    image_name = find_image(docker_client, project.name)
    assert image_name is not None, "Docker image isn't found"

    request.addfinalizer(lambda: delete_image(docker_client, image_name))

    image = Image(image_name, project)
    return image
def docker_image_with_cartridge(cartridge_cmd, tmpdir, project_with_cartridge, request, docker_client):
    project = project_with_cartridge

    cmd = [cartridge_cmd, "pack", "docker", project.path]
    process = subprocess.run(cmd, cwd=tmpdir)
    assert process.returncode == 0, \
        "Error during creating of docker image"

    image_name = find_image(docker_client, project.name)
    assert image_name is not None, "Docker image isn't found"

    request.addfinalizer(lambda: delete_image(docker_client, image_name))

    image = Image(image_name, project)
    return image
def docker_image(cartridge_cmd, session_tmpdir, session_light_project, request, docker_client):
    project = session_light_project
    add_runtime_requirements_file(project)

    cmd = [cartridge_cmd, "pack", "docker", project.path]
    process = subprocess.run(cmd, cwd=session_tmpdir)
    assert process.returncode == 0, \
        "Error during creating of docker image"

    image_name = find_image(docker_client, project.name)
    assert image_name is not None, "Docker image isn't found"

    request.addfinalizer(lambda: delete_image(docker_client, image_name))

    image = Image(image_name, project)
    return image
def docker_image_print_environment(cartridge_cmd, tmpdir, project_without_dependencies, request, docker_client):
    project = project_without_dependencies
    replace_project_file(project, 'init.lua', INIT_PRINT_ENV_FILEPATH)

    cmd = [
        cartridge_cmd,
        "pack", "docker",
        "--tag", project.name,
        project.path,
    ]

    process = subprocess.run(cmd, cwd=tmpdir)
    assert process.returncode == 0, \
        "Error during creating of docker image"

    image_name = find_image(docker_client, project.name)
    assert image_name is not None, "Docker image isn't found"

    request.addfinalizer(lambda: delete_image(docker_client, image_name))

    image = Image(image_name, project)
    return image
Beispiel #6
0
        print(kp2)


def resize(image, width):
    (h, w) = image.shape[:2]
    r = width / float(w)
    dim = (width, int(h * r))
    return cv2.resize(image, dim, interpolation=cv2.INTER_AREA)


if __name__ == '__main__':
    # ap = argparse.ArgumentParser()
    # ap.add_argument("-f", "--first", help="path to the first image")
    # ap.add_argument("-s", "--second", help="path to the second image")
    #
    # args = vars(ap.parse_args())
    args = {"first": find_image('mpv-shot0001.jpg'), 'second': find_image('mpv-shot0002.jpg')}

    print(args)
    imageA = cv2.imread(args["first"])
    imageB = cv2.imread(args["second"])
    imageA = resize(imageA, width=800)
    imageB = resize(imageB, width=800)
    imageB = imutils.rotate(imageB, -12)
    # show the images
    cv2.imshow("Image A", imageA)
    cv2.imshow("Image B", imageB)
    # cv2.imshow("Keypoint Matches", vis)
    # cv2.imshow("Result", result)
    cv2.waitKey(0)
import cv2
import numpy as np

from utils import find_image

image_path = find_image('girls_01.jpg')
img = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
rows, cols = img.shape

M = cv2.getRotationMatrix2D((cols / 2, rows / 2), 90, 1)

res = cv2.warpAffine(img, M, (cols, rows))
cv2.imshow('90 degree', res)

M = cv2.getRotationMatrix2D((cols / 2, rows / 2), 60, 0.5)
res = cv2.warpAffine(img, M, (cols, rows))
cv2.imshow('60 degree, with half scalar', res)

cv2.waitKey(0)
cv2.destroyAllWindows()
Beispiel #8
0
from scipy import ndimage

from utils import find_image

kernel_3x3 = np.array([
    [-1, -1, -1],
    [-1, 8, -1],
    [-1, -1, -1]
])

kernel_5x5 = np.array([
    [-1, -1, -1, -1, -1],
    [-1, 1, 2, 1, -1],
    [-1, 2, 4, 2, -1],
    [-1, 1, 2, 1, -1],
    [-1, -1, -1, -1, -1],
])
image_path = find_image('Katrina_Kaif.jpg')
image = cv2.imread(image_path, cv2.IMREAD_GRAYSCALE)
k3 = ndimage.convolve(image, kernel_3x3)
k5 = ndimage.convolve(image, kernel_5x5)

blurred = cv2.GaussianBlur(image, (11, 11), 0)
cv2.imshow('blurred', blurred)
g_hpf = image - blurred
cv2.imshow('convolve_3x3', k3)
cv2.imshow('convolve_5x5', k5)
cv2.imshow('g_hpf', g_hpf)
cv2.waitKey(0)
cv2.destroyAllWindows()
Beispiel #9
0
def fetch_recipe_feed_entries(feed_url):
    logging.info("fetchies entries for %s", feed_url)
    new_posts = 0
    existing_posts = 0
    errors = 0
    try:
        d = feedparser.parse(feed_url)
        blog_url = d.feed.link
        blog_feed_url = feed_url
        blog_name = d.feed.title
        posts = []
        for entry in d.entries:
            post_url = entry.link
            existing_post = memcache.get(post_url)
            if existing_post is not None:
                logging.info("skipping %s in memcache", post_url)
                existing_posts += 1
                continue
            existing_post = BlogPost.query(
                BlogPost.post_url == post_url).fetch(1)

            # fetch images and parse data only if we have to
            if not existing_post:
                new_posts += 1

                post_title = entry.title
                post_description = parse_entry_description(entry.description)
                post_date_published = datetime.fromtimestamp(
                    mktime(entry.published_parsed)) if (
                        "published_parsed" in entry.keys()) else None
                post_image_url = find_image(post_url)
                post = BlogPost(blog_url=blog_url,
                                blog_feed_url=blog_feed_url,
                                blog_name=blog_name,
                                post_url=post_url,
                                post_title=post_title,
                                post_description=post_description,
                                post_image_url=post_image_url,
                                post_date_published=post_date_published)
                logging.info("inserting %s", post_url)
                post.put()
                memcache.add(post_url, post, 7200)
            else:
                logging.info("skipping %s", post_url)
                existing_posts += 1
                memcache.add(post_url, existing_post, 7200)
        return json.dumps({
            "response": {
                "new": new_posts,
                "existing": existing_posts,
                "errors": 0,
                "error_feed": []
            }
        })
    except Exception, e:
        logging.warning("error parsing feed %s", e)
        return json.dumps({
            "response": {
                "new": new_posts,
                "existing": existing_posts,
                "errors": 1,
                "error_feed": [feed_url]
            }
        })
Beispiel #10
0
def fetch_recipe_feed_entries_new(feed_url):
    logging.info("fetchies entries for %s", feed_url)
    new_posts = 0
    existing_posts = 0
    errors = 0
    try:
        d = feedparser.parse(feed_url)
        blog_url = d.feed.link
        blog_feed_url = feed_url
        blog_name = d.feed.title
        posts = []
        for entry in d.entries:
            post_url = entry.link
            existing_post = memcache.get(post_url)
            if existing_post is not None:
                logging.info("skipping %s in memcache", post_url)
                existing_posts += 1
                continue
            existing_post = WebPage.query(
                WebPage.page_url == post_url).fetch(1)

            # fetch images and parse data only if we have to
            if not existing_post:
                new_posts += 1

                post_title = entry.title
                post_description = parse_entry_description(entry.description)
                post_date_published = datetime.fromtimestamp(
                    mktime(entry.published_parsed)) if (
                        "published_parsed" in entry.keys()) else None

                logging.info("getting soup")
                soup = get_soup_from_url(post_url)
                if soup is None:
                    logging.warning("issue parsing html for %s", post_url)
                    errors += 1
                    continue
                post_image_url = find_image(post_url, soup)
                post_recipe_ingredients = getRecipeIngredientsFromSoup(soup)
                post_recipe_instructions = getRecipeInstructionsFromSoup(soup)

                web_page = WebPage(
                    site_url=blog_url,
                    site_feed_url=blog_feed_url,
                    site_name=blog_name,
                    page_url=post_url,
                    page_title=post_title,
                    page_description=post_description,
                    page_image_url=post_image_url,
                    page_date_published=post_date_published,
                    page_recipe_ingredients=post_recipe_ingredients,
                    page_recipe_instructions=post_recipe_instructions)

                logging.info("inserting %s", post_url)
                web_page.put()
                memcache.add(post_url, web_page)
            else:
                logging.info("skipping %s", post_url)
                existing_posts += 1
                memcache.add(post_url, existing_post)
        return json.dumps({
            "response": {
                "new": new_posts,
                "existing": existing_posts,
                "errors": 0,
                "error_feed": []
            }
        })
    except Exception, e:
        logging.warning("error parsing feed %s", e)
        return json.dumps({
            "response": {
                "new": new_posts,
                "existing": existing_posts,
                "errors": 1,
                "error_feed": [feed_url]
            }
        })
import numpy as np

# termination criteria
from utils import find_image

criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp = np.zeros((6 * 7, 3), np.float32)
objp[:, :2] = np.mgrid[0:7, 0:6].T.reshape(-1, 2)

# Arrays to store object points and image points from all the images.
objpoints = []  # 3d point in real world space
imgpoints = []  # 2d points in image plane.

image = find_image('left02.jpg')
img = cv2.imread(image)
print(img.shape)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Find the chess board corners
ret, corners = cv2.findChessboardCorners(gray, (7, 6), None)
print('corners shape {}'.format(corners.shape))

# If found, add object points, image points (after refining them)
if ret:
    objpoints.append(objp)
    # cv2.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
    imgpoints.append(corners)
    # Draw and display the corners
    cv2.drawChessboardCorners(img, (7, 6), corners, ret)
    cv2.imshow('img', img)
Beispiel #12
0
import cv2
import numpy as np

from utils import find_image

image_path = find_image('ml-logo.png')
image = cv2.imread(image_path)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
edge = cv2.Canny(gray, 50, 200)

min_line_length = 20
max_line_gap = 50

lines = cv2.HoughLinesP(edge, 1, np.pi / 180, 50, None, min_line_length, max_line_gap)

for x1, y1, x2, y2 in lines[0]:
    cv2.line(image, (x1, y1), (x2, y2), (0, 0, 255), 1)

cv2.imshow('edge', edge)
cv2.imshow('image', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
Beispiel #13
0
import cv2
import numpy as np

# Read Image
from utils import find_image

im = cv2.imread(find_image('girls.jpg'))
size = im.shape

# 2D image points. If you change the image, you need to change vector
image_points = np.array(
    [
        (359, 391),  # Nose tip
        (399, 561),  # Chin
        (337, 297),  # Left eye left corner
        (513, 301),  # Right eye right corne
        (345, 465),  # Left Mouth corner
        (453, 469)  # Right mouth corner
    ],
    dtype="double")

# 3D model points.
model_points = np.array([
    (0.0, 0.0, 0.0),  # Nose tip
    (0.0, -330.0, -65.0),  # Chin
    (-225.0, 170.0, -135.0),  # Left eye left corner
    (225.0, 170.0, -135.0),  # Right eye right corne
    (-150.0, -150.0, -125.0),  # Left Mouth corner
    (150.0, -150.0, -125.0)  # Right mouth corner
])
Beispiel #14
0
import cv2 as cv
from matplotlib import pyplot as plt

from utils import find_image

image_path = find_image('bear.jpeg')
img = cv.imread(image_path, 0)
# global thresholding
ret1, th1 = cv.threshold(img, 90, 255, cv.THRESH_BINARY)
# Otsu's thresholding
ret2, th2 = cv.threshold(img, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
# Otsu's thresholding after Gaussian filtering
blur = cv.GaussianBlur(img, (5, 5), 0)
ret3, th3 = cv.threshold(blur, 0, 255, cv.THRESH_BINARY + cv.THRESH_OTSU)
# plot all the images and their histograms
images = [img, 0, th1, img, 0, th2, blur, 0, th3]
titles = [
    'Original Noisy Image', 'Histogram', 'Global Thresholding (v=127)',
    'Original Noisy Image', 'Histogram', "Otsu's Thresholding",
    'Gaussian filtered Image', 'Histogram', "Otsu's Thresholding"
]
for i in range(3):
    plt.subplot(3, 3, i * 3 + 1), plt.imshow(images[i * 3], 'gray')
    plt.title(titles[i * 3]), plt.xticks([]), plt.yticks([])
    plt.subplot(3, 3, i * 3 + 2), plt.hist(images[i * 3].ravel(), 256)
    plt.title(titles[i * 3 + 1]), plt.xticks([]), plt.yticks([])
    plt.subplot(3, 3, i * 3 + 3), plt.imshow(images[i * 3 + 2], 'gray')
    plt.title(titles[i * 3 + 2]), plt.xticks([]), plt.yticks([])
plt.show()